-
Notifications
You must be signed in to change notification settings - Fork 3.4k
380 lines (294 loc) · 17.1 KB
/
pull-request-comments.yml
File metadata and controls
380 lines (294 loc) · 17.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
# Responsible for making comments on pull requests, such as commenting for first time contributors.
name: Pull Request Comments
on:
pull_request_target:
types: [ 'opened', 'synchronize', 'reopened', 'edited' ]
workflow_run:
workflows: [ 'Check Built Files (PRs)', 'Test Build Processes' ]
types:
- completed
# Cancels all previous workflow runs for pull requests that have not completed.
concurrency:
# The concurrency group contains the workflow name and the branch name for pull requests
# or the commit hash for any other events.
group: ${{ github.workflow }}-${{ github.event_name == 'pull_request_target' && github.head_ref || github.event_name == 'workflow_dispatch' && github.event.number || github.sha }}
# Disable permissions for all available scopes by default.
# Any needed permissions should be configured at the job level.
permissions: {}
jobs:
# Comments on a pull request when the author is a first time contributor.
post-welcome-message:
name: Contributor welcome message
runs-on: ubuntu-24.04
permissions:
issues: write
pull-requests: write
timeout-minutes: 5
if: ${{ github.repository == 'WordPress/wordpress-develop' && github.event_name == 'pull_request_target' }}
steps:
- name: Post a welcome comment
uses: wow-actions/welcome@68019c2c271561f63162fea75bb7707ef8a02c85 # v1.3.1
with:
FIRST_PR_REACTIONS: 'hooray'
FIRST_PR_COMMENT: >
Hi @{{ author }}! 👋
Thank you for your contribution to WordPress! 💖
It looks like this is your first pull request to `wordpress-develop`. Here are a few things to be aware of that may help you out!
**No one monitors this repository for new pull requests.** Pull requests **must** be attached to a Trac ticket to be considered for inclusion in WordPress Core. To attach a pull request to a Trac ticket, please include the ticket's full URL in your pull request description.
**Pull requests are never merged on GitHub.** The WordPress codebase continues to be managed through the SVN repository that this GitHub repository mirrors. Please feel free to open pull requests to work on any contribution you are making.
More information about how GitHub pull requests can be used to contribute to WordPress can be found in [the Core Handbook](https://make.wordpress.org/core/handbook/contribute/git/github-pull-requests-for-code-review/).
**Please include automated tests.** Including tests in your pull request is one way to help your patch be considered faster. To learn about WordPress' test suites, visit the [Automated Testing](https://make.wordpress.org/core/handbook/testing/automated-testing/) page in the handbook.
If you have not had a chance, please review the [Contribute with Code page](https://make.wordpress.org/core/handbook/contribute/) in the [WordPress Core Handbook](https://make.wordpress.org/core/handbook/).
The [Developer Hub](https://developer.wordpress.org/) also documents the various [coding standards](https://make.wordpress.org/core/handbook/best-practices/coding-standards/) that are followed:
- [PHP Coding Standards](https://developer.wordpress.org/coding-standards/wordpress-coding-standards/php/)
- [CSS Coding Standards](https://developer.wordpress.org/coding-standards/wordpress-coding-standards/css/)
- [HTML Coding Standards](https://developer.wordpress.org/coding-standards/wordpress-coding-standards/html/)
- [JavaScript Coding Standards](https://developer.wordpress.org/coding-standards/wordpress-coding-standards/javascript/)
- [Accessibility Coding Standards](https://developer.wordpress.org/coding-standards/wordpress-coding-standards/accessibility/)
- [Inline Documentation Standards](https://developer.wordpress.org/coding-standards/inline-documentation-standards/)
Thank you,
The WordPress Project
# Leaves a comment on a pull request with a link to test the changes in a WordPress Playground instance.
playground-details:
name: Leave Playground testing details
runs-on: ubuntu-24.04
permissions:
issues: write
pull-requests: write
if: >
github.repository == 'WordPress/wordpress-develop' &&
github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.name == 'Test Build Processes' &&
github.event.workflow_run.conclusion == 'success'
steps:
- name: Download artifact
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
env:
RUN_ID: ${{ github.event.workflow_run.id }}
with:
script: |
const artifacts = await github.rest.actions.listWorkflowRunArtifacts( {
owner: context.repo.owner,
repo: context.repo.repo,
run_id: process.env.RUN_ID,
} );
const matchArtifact = artifacts.data.artifacts.filter( ( artifact ) => {
return artifact.name === 'pr-number'
} )[0];
if ( ! matchArtifact ) {
core.setFailed( 'No artifact found!' );
return;
}
const download = await github.rest.actions.downloadArtifact( {
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact.id,
archive_format: 'zip',
} );
const fs = require( 'fs' );
fs.writeFileSync( '${{github.workspace}}/pr-number.zip', Buffer.from( download.data ) )
- name: Unzip the artifact containing the PR number
run: unzip pr-number.zip
- name: Leave a comment about testing with Playground
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
with:
script: |
const fs = require( 'fs' );
const issue_number = Number( fs.readFileSync( './NR' ) );
core.info( `Checking pull request #${issue_number}.` );
// Confirm that the pull request is still open before leaving a comment.
const pr = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: issue_number,
});
if ( pr.data.state !== 'open' ) {
core.info( 'The pull request has been closed. No comment will be left.' );
return;
}
// Comments are only added after the first successful build. Check for the presence of a comment and bail early.
const commentInfo = {
owner: context.repo.owner,
repo: context.repo.repo,
issue_number,
};
const comments = ( await github.rest.issues.listComments( commentInfo ) ).data;
for ( const currentComment of comments ) {
if ( currentComment.user.type === 'Bot' && currentComment.body.includes( 'Test using WordPress Playground' ) ) {
core.info( 'A comment with instructions to test within a Playground instance already exists.' );
return;
}
};
// No comment was found. Create one.
commentInfo.body = `## Test using WordPress Playground
The changes in this pull request can previewed and tested using a [WordPress Playground](https://developer.wordpress.org/playground/) instance.
[WordPress Playground](https://developer.wordpress.org/playground/) is an experimental project that creates a full WordPress instance entirely within the browser.
### Some things to be aware of
- All changes will be lost when closing a tab with a Playground instance.
- All changes will be lost when refreshing the page.
- A fresh instance is created each time the link below is clicked.
- Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
it's possible that the most recent build failed, or has not completed. Check the [list of workflow runs to be sure](https://github.com/WordPress/wordpress-develop/actions/workflows/test-build-processes.yml).
For more details about these limitations and more, check out the [Limitations page](https://wordpress.github.io/wordpress-playground/limitations/) in the WordPress Playground documentation.
[Test this pull request with WordPress Playground](https://playground.wordpress.net/wordpress.html?pr=${ issue_number }).
`;
github.rest.issues.createComment( commentInfo );
# Leaves a comment on a pull request noting differences between the PR and the build server.
build-server-comparison:
name: Note differences with the build server
runs-on: ubuntu-24.04
permissions:
issues: write
pull-requests: write
if: >
github.repository == 'WordPress/wordpress-develop' &&
github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.name == 'Check Built Files (PRs)' &&
github.event.workflow_run.conclusion == 'success'
steps:
- name: Download artifact
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
env:
RUN_ID: ${{ github.event.workflow_run.id }}
with:
script: |
const artifacts = await github.rest.actions.listWorkflowRunArtifacts( {
owner: context.repo.owner,
repo: context.repo.repo,
run_id: process.env.RUN_ID,
} );
const matchArtifact = artifacts.data.artifacts.filter( ( artifact ) => {
return artifact.name === 'build-server-comparison'
} )[0];
if ( ! matchArtifact ) {
core.setFailed( 'No artifact found!' );
return;
}
const download = await github.rest.actions.downloadArtifact( {
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact.id,
archive_format: 'zip',
} );
const fs = require( 'fs' );
fs.writeFileSync( '${{github.workspace}}/build-server-comparison.zip', Buffer.from( download.data ) )
- name: Unzip the artifact containing the comparison info
run: unzip build-server-comparison.zip
- name: Leave a comment with any differences noticed
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
with:
script: |
const fs = require( 'fs' );
const issue_number = Number( fs.readFileSync( './NR' ) );
const fileChanges = fs.readFileSync( './file-changes.txt', 'utf8' );
const diffContents = fs.readFileSync( './changes.diff', 'utf8' );
const MAX_DIFF_LENGTH = 50000; // GitHub has a 65,536 character limit for comments.
core.info( `Checking pull request #${issue_number}.` );
// Confirm that the pull request is still open before leaving a comment.
const pr = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: issue_number,
});
if ( pr.data.state !== 'open' ) {
core.info( 'The pull request has been closed. No comment will be left.' );
return;
}
// Comments are only added after the first successful build. Check for the presence of a comment and bail early.
const commentInfo = {
owner: context.repo.owner,
repo: context.repo.repo,
issue_number,
};
const comments = ( await github.rest.issues.listComments( commentInfo ) ).data;
for ( const currentComment of comments ) {
if ( currentComment.user.type === 'Bot' && currentComment.body.includes( 'Build Server Comparison' ) ) {
commentInfo.comment_id = currentComment.id;
break;
}
};
// Post or update the comment.
if ( fileChanges.trim() === '' ) {
if ( ! commentInfo.comment_id ) {
core.info( 'No differences found and no existing comment. Skipping.' );
return;
}
commentInfo.body = "## Build Server Comparison\n\nThe changes in this pull request will not result in any differences with the WordPress/WordPress repository.";
github.rest.issues.updateComment( commentInfo );
return;
}
commentInfo.body = "## Build Server Comparison\n\n";
commentInfo.body += `The contents of the \`build\` directory after running \`npm run build\` has been compared with the contents of the WordPress/WordPress repository.
**Review these differences carefully for any unexpected results.**
### List of Modified Files
\`\`\`
${ fileChanges }
\`\`\`
### Full Diff File
`;
if ( diffContents.length > MAX_DIFF_LENGTH ) {
const cutoff = diffContents.lastIndexOf( '\n', MAX_DIFF_LENGTH );
const truncated = diffContents.substring( 0, cutoff );
commentInfo.body += `<details>
<summary>Click to expand (truncated)</summary>
\`\`\`diff
${ truncated }
\`\`\`
⚠️ The diff was too large to display in full.
</details>`;
} else {
commentInfo.body += `<details>
<summary>Click to expand</summary>
\`\`\`diff
${ diffContents }
\`\`\`
</details>`;
}
const sha = context.payload.workflow_run.head_sha;
commentInfo.body += `\n\n_Comment updated using [${ sha.slice( 0, 7 ) }](https://github.com/${ context.repo.owner }/${ context.repo.repo }/commit/${ sha })._ ([commenting workflow run](https://github.com/${ context.repo.owner }/${ context.repo.repo }/actions/runs/${ context.runId })).`;
commentInfo.body += `\n\n[Download the complete .diff file from the workflow run](https://github.com/${ context.repo.owner }/${ context.repo.repo }/actions/runs/${ context.payload.workflow_run.id }).`;
if ( commentInfo.comment_id ) {
github.rest.issues.updateComment( commentInfo );
} else {
github.rest.issues.createComment( commentInfo );
}
# Manages comments reminding contributors to include a Trac ticket link when opening a pull request.
trac-ticket-check:
name: Manage Trac ticket reminders for pull requests
runs-on: ubuntu-24.04
permissions:
issues: write
pull-requests: write
if: ${{ github.repository == 'WordPress/wordpress-develop' && github.event_name == 'pull_request_target' && ! github.event.pull_request.draft && github.event.pull_request.state == 'open' }}
steps:
- name: Check for Trac ticket and manage comment
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
with:
script: |
const { owner, repo } = context.repo;
const { number } = context.issue;
// Check for the presence of a comment and bail early.
const comments = ( await github.rest.issues.listComments( { owner, repo, issue_number: number } ) ).data;
const hasMissingTicketComment = comments.find( comment => comment.user.type === 'Bot' && comment.body.includes( 'Trac Ticket Missing' ) );
if ( hasMissingTicketComment ) {
// Trac ticket link found, delete existing "Trac Ticket Missing" comment.
await github.rest.issues.deleteComment( { owner, repo, comment_id: hasMissingTicketComment.id } );
return;
}
// No comment was found. Create one.
const pr = ( await github.rest.pulls.get( { owner, repo, pull_number: number } ) ).data;
const prBody = pr.body ?? '';
const prTitle = pr.title ?? '';
const tracTicketRegex = new RegExp( '(https?://core.trac.wordpress.org/ticket/|Core-|ticket:)([0-9]+)', 'g' );
const tracTicketMatches = prBody.match( tracTicketRegex ) || prTitle.match( tracTicketRegex );
if ( ! tracTicketMatches ) {
github.rest.issues.createComment( {
owner,
repo,
issue_number: number,
body: `## Trac Ticket Missing
This pull request is missing a link to a [Trac ticket](https://core.trac.wordpress.org/). For a contribution to be considered, there must be a corresponding ticket in Trac.
To attach a pull request to a Trac ticket, please include the ticket's full URL in your pull request description. More information about contributing to WordPress on GitHub can be found in [the Core Handbook](https://make.wordpress.org/core/handbook/contribute/git/github-pull-requests-for-code-review/).
`,
} );
}