Skip to content

Commit cd29c73

Browse files
committed
Merge branch 'develop'
2 parents 118957e + b9734f6 commit cd29c73

File tree

3 files changed

+77
-40
lines changed

3 files changed

+77
-40
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## [3.5.0] - 2024-07-07
4+
5+
- Support pull request comment as workflow trigger
6+
37
## [3.4.0] - 2024-07-02
48

59
- Add ability to display custom information by @fungairino
@@ -61,6 +65,8 @@
6165

6266
- Initial release
6367

68+
[3.5.0]: https://github.com/daun/playwright-report-summary/releases/tag/v3.5.0
69+
[3.4.0]: https://github.com/daun/playwright-report-summary/releases/tag/v3.4.0
6470
[3.3.0]: https://github.com/daun/playwright-report-summary/releases/tag/v3.3.0
6571
[3.2.0]: https://github.com/daun/playwright-report-summary/releases/tag/v3.2.0
6672
[3.1.0]: https://github.com/daun/playwright-report-summary/releases/tag/v3.1.0

dist/index.js

Lines changed: 34 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.ts

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export async function report(): Promise<void> {
3535
const cwd = process.cwd()
3636

3737
const { workflow, eventName, repo, payload } = context
38-
const { owner, number: pull_number } = context.issue || {}
38+
const { owner, number: issueNumber } = context.issue || {}
3939

4040
const token = getInput('github-token')
4141
const reportFile = getInput('report-file', { required: true })
@@ -54,21 +54,41 @@ export async function report(): Promise<void> {
5454

5555
let ref: string = context.ref
5656
let sha: string = context.sha
57+
let pr: number | null = null
5758

5859
const octokit = getOctokit(token)
5960

60-
if (eventName === 'push') {
61-
ref = payload.ref
62-
sha = payload.after
63-
console.log(`Commit pushed onto ${ref} (${sha})`)
64-
} else if (eventName === 'pull_request' || eventName === 'pull_request_target') {
65-
ref = payload.pull_request?.base?.ref
66-
sha = payload.pull_request?.head?.sha
67-
console.log(`PR #${pull_number} targeting ${ref} (${sha})`)
68-
} else if (eventName === 'workflow_dispatch') {
69-
console.log(`Workflow dispatched on ${ref} (${sha})`)
70-
} else {
71-
console.warn(`Unsupported event type: ${eventName}`)
61+
switch (eventName) {
62+
case 'push':
63+
ref = payload.ref
64+
sha = payload.after
65+
console.log(`Commit pushed onto ${ref} (${sha})`)
66+
break
67+
68+
case 'pull_request':
69+
case 'pull_request_target':
70+
ref = payload.pull_request?.base?.ref
71+
sha = payload.pull_request?.head?.sha
72+
pr = issueNumber
73+
console.log(`PR #${pr} targeting ${ref} (${sha})`)
74+
break
75+
76+
case 'issue_comment':
77+
if (payload.issue?.pull_request) {
78+
pr = issueNumber
79+
console.log(`Comment on PR #${pr} targeting ${ref} (${sha})`)
80+
} else {
81+
console.log(`Comment on issue #${issueNumber}`)
82+
}
83+
break
84+
85+
case 'workflow_dispatch':
86+
console.log(`Workflow dispatched on ${ref} (${sha})`)
87+
break
88+
89+
default:
90+
console.warn(`Unsupported event type: ${eventName}`)
91+
break
7292
}
7393

7494
const reportPath = path.resolve(cwd, reportFile)
@@ -94,14 +114,12 @@ export async function report(): Promise<void> {
94114
const body = `${prefix}\n\n${summary}`
95115
let commentId = null
96116

97-
const hasPR = eventName === 'pull_request' || eventName === 'pull_request_target'
98-
99-
if (!hasPR) {
117+
if (!pr) {
100118
console.log('No PR associated with this action run. Not posting a check or comment.')
101119
} else {
102120
startGroup(`Commenting test report on PR`)
103121
try {
104-
const comments = await getIssueComments(octokit, { ...repo, issue_number: pull_number })
122+
const comments = await getIssueComments(octokit, { ...repo, issue_number: pr })
105123
const existingComment = comments.findLast((c) => c.body?.includes(prefix))
106124
commentId = existingComment?.id || null
107125
} catch (error: unknown) {
@@ -122,7 +140,7 @@ export async function report(): Promise<void> {
122140
if (!commentId) {
123141
console.log('Creating new comment')
124142
try {
125-
const newComment = await createIssueComment(octokit, { ...repo, issue_number: pull_number, body })
143+
const newComment = await createIssueComment(octokit, { ...repo, issue_number: pr, body })
126144
commentId = newComment.id
127145
console.log(`Created new comment #${commentId}`)
128146
} catch (error: unknown) {
@@ -145,7 +163,7 @@ export async function report(): Promise<void> {
145163
endGroup()
146164
}
147165

148-
if (!commentId && hasPR) {
166+
if (!commentId && pr) {
149167
const intro = `Unable to comment on your PR — this can happen for PR's originating from a fork without write permissions. You can copy the test results directly into a comment using the markdown summary below:`
150168
warning(`${intro}\n\n${body}`, { title: 'Unable to comment on PR' })
151169
}

0 commit comments

Comments
 (0)