-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Project Management: Assign issues 'fixed' by a PR to the author of th…
…at PR (#16700) Adds a GitHub Action which, when a pull request is opened, searches the pull request description for 'Fixes #XXXX' and, for each found issue: - Adds the author of the pull request as an assignee. - Adds the `[Status] In Progress` label.
- Loading branch information
1 parent
830624e
commit a8f60ad
Showing
3 changed files
with
85 additions
and
0 deletions.
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,18 @@ | ||
FROM debian:stable-slim | ||
|
||
LABEL "name"="Assign Fixed Issues" | ||
LABEL "maintainer"="The WordPress Contributors" | ||
LABEL "version"="1.0.0" | ||
|
||
LABEL "com.github.actions.name"="Assign Fixed Issues" | ||
LABEL "com.github.actions.description"="Assigns the issues fixed by a pull request to the author of that pull request" | ||
LABEL "com.github.actions.icon"="flag" | ||
LABEL "com.github.actions.color"="green" | ||
|
||
RUN apt-get update && \ | ||
apt-get install --no-install-recommends -y jq curl ca-certificates && \ | ||
apt-get clean -y | ||
|
||
COPY entrypoint.sh /entrypoint.sh | ||
|
||
ENTRYPOINT [ "/entrypoint.sh" ] |
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,51 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
# 1. Find the issues that this PR 'fixes'. | ||
|
||
issues=$( | ||
jq -r '.pull_request.body' $GITHUB_EVENT_PATH | perl -nle 'print $1 while / | ||
(?:close|closes|closed|fix|fixes|fixed|resolve|resolves|resolved) | ||
:? | ||
\ + | ||
(?:\#?|https?:\/\/github\.com\/WordPress\/gutenberg\/issues\/) | ||
(\d+) | ||
/igx' | ||
) | ||
|
||
if [ -z "$issues" ]; then | ||
echo "Pull request does not 'fix' any issues. Aborting." | ||
exit 78 | ||
fi | ||
|
||
# 2. Grab the author of the PR. | ||
|
||
author=$(jq -r '.pull_request.user.login' $GITHUB_EVENT_PATH) | ||
|
||
# 3. Loop through each 'fixed' issue. | ||
|
||
for issue in $issues; do | ||
|
||
# 3a. Add the author as an asignee to the issue. This fails if the author is | ||
# already assigned, which is expected and ignored. | ||
|
||
curl \ | ||
--silent \ | ||
-X POST \ | ||
-H "Authorization: token $GITHUB_TOKEN" \ | ||
-H "Content-Type: application/json" \ | ||
-d "{\"assignees\":[\"$author\"]}" \ | ||
"https://api.github.com/repos/$GITHUB_REPOSITORY/issues/$issue/assignees" > /dev/null | ||
|
||
# 3b. Label the issue as 'In Progress'. This fails if the label is already | ||
# applied, which is expected and ignored. | ||
|
||
curl \ | ||
--silent \ | ||
-X POST \ | ||
-H "Authorization: token $GITHUB_TOKEN" \ | ||
-H "Content-Type: application/json" \ | ||
-d '{"labels":["[Status] In Progress"]}' \ | ||
"https://api.github.com/repos/$GITHUB_REPOSITORY/issues/$issue/labels" > /dev/null | ||
|
||
done |
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