mirrored from git://develop.git.wordpress.org/
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce workflow that automatically closes pull requests #8139
Closed
+126
−0
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
3e588f3
Add a workflow that closes pull requests based off `Fixed: `.
desrosj 82533aa
Convert to using the reusable pattern.
desrosj 027dd0a
No need to re-check repo.
desrosj b8191fa
Open is already a condition in the previous query.
desrosj 2c36608
Update the GitHub commit link.
desrosj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
name: Cleanup Pull Requests | ||
|
||
on: | ||
push: | ||
branches: | ||
- trunk | ||
- '4.[1-9]' | ||
- '[5-9].[0-9]' | ||
|
||
# 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.sha }} | ||
cancel-in-progress: true | ||
|
||
# Disable permissions for all available scopes by default. | ||
# Any needed permissions should be configured at the job level. | ||
permissions: {} | ||
|
||
jobs: | ||
# Runs pull request cleanup. | ||
close-prs: | ||
name: Clean up pull requests | ||
permissions: | ||
pull-requests: write | ||
if: ${{ github.repository == 'WordPress/wordpress-develop' }} | ||
uses: ./.github/workflows/reusable-cleanup-pull-requests.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
## | ||
# A reusable workflow that finds and closes any pull requests that are linked to Trac | ||
# tickets that are referenced as fixed in commit messages. | ||
# | ||
# More info about using GitHub pull requests for contributing to WordPress can be found in the handbook: https://make.wordpress.org/core/handbook/contribute/git/github-pull-requests-for-code-review/. | ||
## | ||
name: Run pull request cleanup | ||
|
||
on: | ||
workflow_call: | ||
|
||
jobs: | ||
# Finds and closes pull requests referencing fixed Trac tickets in commit messages using the | ||
# documented expected format | ||
# | ||
# Commit message format is documented in the Core handbook: https://make.wordpress.org/core/handbook/best-practices/commit-messages/. | ||
# | ||
# Performs the following steps: | ||
# - Parse fixed ticket numbers from the commit message. | ||
# - Parse the SVN revision from the commit message. | ||
# - Searches for pull requests referencing any fixed tickets. | ||
# - Leaves a comment on each PR before closing. | ||
close-prs: | ||
name: Find and close PRs | ||
runs-on: ubuntu-latest | ||
permissions: | ||
pull-requests: write | ||
|
||
steps: | ||
- name: Find fixed ticket numbers | ||
id: trac-tickets | ||
run: | | ||
COMMIT_MESSAGE=$(cat <<'EOF' | sed -n '/^Fixes #/,/\./p' | ||
${{ github.event.head_commit.message }} | ||
EOF | ||
) | ||
echo "fixed_list=$(echo \"$COMMIT_MESSAGE\" | sed -n 's/.*Fixes #\([0-9]\+\).*/\1/p' | tr '\n' ' ')" >> $GITHUB_OUTPUT | ||
|
||
- name: Get the SVN revision | ||
id: git-svn-id | ||
run: | | ||
COMMIT_MESSAGE=$(cat <<'EOF' | sed -n '$p' | ||
${{ github.event.head_commit.message }} | ||
EOF | ||
) | ||
echo "svn_revision_number=$(echo \"$COMMIT_MESSAGE\" | sed -n 's/.*git-svn-id: https:\/\/develop.svn.wordpress.org\/[^@]*@\([0-9]*\) .*/\1/p')" >> $GITHUB_OUTPUT | ||
|
||
- name: Find pull requests | ||
id: linked-prs | ||
if: ${{ steps.trac-tickets.outputs.fixed_list != '' && steps.git-svn-id.outputs.svn_revision_number != '' }} | ||
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 | ||
with: | ||
script: | | ||
const fixedList = "${{ steps.trac-tickets.outputs.fixed_list }}".split(' ').filter(Boolean); | ||
|
||
let prNumbers = []; | ||
|
||
for (const ticket of fixedList) { | ||
const query = 'is:pr is:open repo:' + context.repo.owner + '/' + context.repo.repo + ' in:body https://core.trac.wordpress.org/ticket/' + ticket; | ||
const result = await github.rest.search.issuesAndPullRequests({ q: query }); | ||
|
||
prNumbers = prNumbers.concat(result.data.items.map(pr => pr.number)); | ||
} | ||
|
||
return prNumbers; | ||
|
||
- name: Comment and close pull requests | ||
if: ${{ steps.trac-tickets.outputs.fixed_list != '' && steps.git-svn-id.outputs.svn_revision_number != '' }} | ||
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 | ||
with: | ||
script: | | ||
const prNumbers = ${{ steps.linked-prs.outputs.result }}; | ||
|
||
const commentBody = `A commit was made that fixes the Trac ticket referenced in the description of this pull request. | ||
|
||
SVN changeset: [${{ steps.git-svn-id.outputs.svn_revision_number }}](https://core.trac.wordpress.org/changeset/${{ steps.git-svn-id.outputs.svn_revision_number }}) | ||
GitHub commit: https://github.com/WordPress/wordpress-develop/commit/${{ github.sha }} | ||
|
||
This PR will be closed, but please confirm the accuracy of this and reopen if there is more work to be done.`; | ||
|
||
// Update all matched pull requests. | ||
for (const prNumber of prNumbers) { | ||
// Comment on the pull request with details. | ||
await github.rest.issues.createComment({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
issue_number: prNumber, | ||
body: commentBody | ||
}); | ||
|
||
// Close the pull request. | ||
await github.rest.pulls.update({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
pull_number: prNumber, | ||
state: 'closed' | ||
}); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clever!