Skip to content

Commit 8d3e910

Browse files
authored
Merge pull request cli#3193 from cli/prautomation
Add workflow for automated PR linting
2 parents 6bbebcd + a238d29 commit 8d3e910

1 file changed

Lines changed: 71 additions & 0 deletions

File tree

.github/workflows/prauto.yml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: PR Automation
2+
on:
3+
pull_request:
4+
types: [ready_for_review, opened, reopened]
5+
jobs:
6+
pr-auto:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- name: lint pr
10+
env:
11+
GH_REPO: ${{ github.repository }}
12+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
13+
PRID: ${{ github.event.pull_request.node_id }}
14+
PRBODY: ${{ github.event.pull_request.body }}
15+
PRNUM: ${{ github.event.pull_request.number }}
16+
PRHEAD: ${{ github.event.pull_request.head.label }}
17+
PRAUTHOR: ${{ github.event.pull_request.user.login }}
18+
if: "!github.event.pull_request.draft"
19+
run: |
20+
commentPR () {
21+
gh pr comment $PRNUM -b "${1}"
22+
}
23+
24+
closePR () {
25+
gh pr close $PRNUM
26+
}
27+
28+
colID () {
29+
gh api graphql -f query='query($owner:String!, $repo:String!) {
30+
repository(owner:$owner, name:$repo) {
31+
project(number:1) {
32+
columns(first:10) { nodes {id,name} }
33+
}
34+
}
35+
}' -F owner=:owner -F repo=:repo \
36+
-q ".data.repository.project.columns.nodes[] | select(.name | startswith(\"$1\")) | .id"
37+
}
38+
39+
addToBoard () {
40+
gh api graphql --silent -f query='
41+
mutation($colID:ID!, $pr:ID!) { addProjectCard(input: { projectColumnId: $colID, contentId: $prID }) { clientMutationId } }
42+
' -f colID="$(colID "Needs review")" -f prID="$PRID"
43+
}
44+
45+
if gh api orgs/cli/public_members/$PRAUTHOR --silent 2>/dev/null
46+
then
47+
# TODO this errors if it's already on the board...
48+
addToBoard
49+
exit 0
50+
fi
51+
52+
if [ "$PRHEAD" = "cli:trunk" ]
53+
then
54+
closePR
55+
exit 0
56+
fi
57+
58+
if [ $(wc -c <<<"$PRBODY") -lt 10 ]
59+
then
60+
commentPR "Thanks for the pull request! We're a small team and it's helpful to have context around community submissions in order to review them appropriately. Our automation has closed this pull request since it does not have an adequate description. Please edit the body of this pull request to describe what this does, then reopen it."
61+
closePR
62+
exit 0
63+
fi
64+
65+
if ! grep -Eq '(#|issues/)[0-9]+' <<<"$PRBODY"
66+
then
67+
commentPR "Hi! Thanks for the pull request. Please ensure that this change is linked to an issue by mentioning an issue number in the description of the pull request. If this pull request would close the issue, please put the word 'Fixes' before the issue number somewhere in the pull request body. If this is a tiny change like fixing a typo, feel free to ignore this message."
68+
fi
69+
70+
addToBoard
71+
exit 0

0 commit comments

Comments
 (0)