Merge pull request #3193 from cli/prautomation
Add workflow for automated PR linting
This commit is contained in:
commit
8d3e910dec
1 changed files with 71 additions and 0 deletions
71
.github/workflows/prauto.yml
vendored
Normal file
71
.github/workflows/prauto.yml
vendored
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
name: PR Automation
|
||||
on:
|
||||
pull_request:
|
||||
types: [ready_for_review, opened, reopened]
|
||||
jobs:
|
||||
pr-auto:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: lint pr
|
||||
env:
|
||||
GH_REPO: ${{ github.repository }}
|
||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
PRID: ${{ github.event.pull_request.node_id }}
|
||||
PRBODY: ${{ github.event.pull_request.body }}
|
||||
PRNUM: ${{ github.event.pull_request.number }}
|
||||
PRHEAD: ${{ github.event.pull_request.head.label }}
|
||||
PRAUTHOR: ${{ github.event.pull_request.user.login }}
|
||||
if: "!github.event.pull_request.draft"
|
||||
run: |
|
||||
commentPR () {
|
||||
gh pr comment $PRNUM -b "${1}"
|
||||
}
|
||||
|
||||
closePR () {
|
||||
gh pr close $PRNUM
|
||||
}
|
||||
|
||||
colID () {
|
||||
gh api graphql -f query='query($owner:String!, $repo:String!) {
|
||||
repository(owner:$owner, name:$repo) {
|
||||
project(number:1) {
|
||||
columns(first:10) { nodes {id,name} }
|
||||
}
|
||||
}
|
||||
}' -F owner=:owner -F repo=:repo \
|
||||
-q ".data.repository.project.columns.nodes[] | select(.name | startswith(\"$1\")) | .id"
|
||||
}
|
||||
|
||||
addToBoard () {
|
||||
gh api graphql --silent -f query='
|
||||
mutation($colID:ID!, $pr:ID!) { addProjectCard(input: { projectColumnId: $colID, contentId: $prID }) { clientMutationId } }
|
||||
' -f colID="$(colID "Needs review")" -f prID="$PRID"
|
||||
}
|
||||
|
||||
if gh api orgs/cli/public_members/$PRAUTHOR --silent 2>/dev/null
|
||||
then
|
||||
# TODO this errors if it's already on the board...
|
||||
addToBoard
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ "$PRHEAD" = "cli:trunk" ]
|
||||
then
|
||||
closePR
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ $(wc -c <<<"$PRBODY") -lt 10 ]
|
||||
then
|
||||
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."
|
||||
closePR
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if ! grep -Eq '(#|issues/)[0-9]+' <<<"$PRBODY"
|
||||
then
|
||||
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."
|
||||
fi
|
||||
|
||||
addToBoard
|
||||
exit 0
|
||||
Loading…
Add table
Add a link
Reference in a new issue