Skip to content

Commit

Permalink
Project Management: Assign issues 'fixed' by a PR to the author of th…
Browse files Browse the repository at this point in the history
…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
noisysocks authored and draganescu committed Jul 29, 2019
1 parent 4036046 commit f598210
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 0 deletions.
18 changes: 18 additions & 0 deletions .github/actions/assign-fixed-issues/Dockerfile
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" ]
51 changes: 51 additions & 0 deletions .github/actions/assign-fixed-issues/entrypoint.sh
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://github.com/gitapi/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://github.com/gitapi/repos/$GITHUB_REPOSITORY/issues/$issue/labels" > /dev/null

done
16 changes: 16 additions & 0 deletions .github/main.workflow
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,19 @@ action "Milestone It" {
uses = "./.github/actions/milestone-it"
secrets = ["GITHUB_TOKEN"]
}

workflow "Assign fixed issues when pull request opened" {
on = "pull_request"
resolves = ["Assign Fixed Issues"]
}

action "Filter opened" {
uses = "actions/bin/filter@0dbb077f64d0ec1068a644d25c71b1db66148a24"
args = "action opened"
}

action "Assign Fixed Issues" {
uses = "./.github/actions/assign-fixed-issues"
needs = ["Filter opened"]
secrets = ["GITHUB_TOKEN"]
}

0 comments on commit f598210

Please sign in to comment.