Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Improve PR lint script
- Do not add draft PRs to the review board
- Do not enforce that the base branch must be "trunk"
- Refuse PRs made with our "trunk" as the head
- Improve staff check to avoid hardcoding
- Improve pattern matching when suggesting to link to an issue
- Use the stock GITHUB_TOKEN
  • Loading branch information
mislav committed Mar 29, 2021
commit c1c936b74b250654bdec2ddb41a2f75b28c86a91
36 changes: 15 additions & 21 deletions .github/workflows/prauto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,59 +8,53 @@ jobs:
steps:
- name: lint pr
env:
REPO: "cli/cli"
GH_REPO: ${{ github.repository }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NEEDSREVIEWCOL: "MDEzOlByb2plY3RDb2x1bW43MTEwMTI4"
PRID: ${{ github.event.pull_request.node_id }}
PRBODY: ${{ github.event.pull_request.body }}
STAFF: "vilmibm,mislav,samcoe,billygriffin,ampinsk"
PRNUM: ${{ github.event.pull_request.number }}
PRBASE: ${{ github.event.pull_request.base.ref }}
GH_TOKEN: ${{ secrets.AUTOMATION_TOKEN }}
PRHEAD: ${{ github.event.pull_request.head.label }}
PRAUTHOR: ${{ github.event.pull_request.user.login }}
# Testing data:
#REPO: "vilmibm/testing"
#NEEDSREVIEWCOL: "MDEzOlByb2plY3RDb2x1bW4xMTAzNTA3Ng==" # vilmibm/testing "good" column
if: "!github.event.pull_request.draft"
run: |
commentPR () {
gh -R$REPO pr comment $PRNUM -b "${1}"
gh pr comment $PRNUM -b "${1}"
}

closePR () {
gh -R$REPO pr close $PRNUM
gh pr close $PRNUM
}

addToBoard () {
# this exec is an attempt to fix some quote highlighting issues i was having in my editor.
bash -c 'gh api graphql -f query="mutation { addProjectCard(input: { projectColumnId: \"$NEEDSREVIEWCOL\", contentId: \"$PRID\" }) { clientMutationId } }"'
gh api graphql --silent -f query='
mutation($colID:ID!, $pr:ID!) { addProjectCard(input: { projectColumnId: $colID, contentId: $prID }) { clientMutationId } }
' -f colID="$NEEDSREVIEWCOL" -f prID="$PRID"
}

if echo $STAFF | grep $PRAUTHOR
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 echo "${PRBODY}" | wc -w | grep -E '^[0-9]$'
if [ "$PRHEAD" = "cli:trunk" ]
then
commentPR "Thanks for the PR! 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 PR since the body appears to be lacking much content; please add a more descriptive PR body as well as any issues it closes and reopen. Thanks again!"
closePR
exit 0
fi

if echo "${PRBASE}" | grep -Ev '^trunk$'
if [ $(wc -c <<<"$PRBODY") -lt 10 ]
then
commentPR "This pull request should probably be targeting trunk; since it isn't, our automation has closed it. Please reopen with an appropriate base branch if this was in error."
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 echo "${PRBODY}" | grep -Ev '#[0-9]+'
if ! grep -Eq '(#|issues/)[0-9]+' <<<"$PRBODY"
then
commentPR "Hi! Thanks for the PR. Please ensure that this PR is related to an issue by mentioning its issue number in the PR body. If this PR would close the issue, please put the word 'Fixes' before the issue number somewhere in the PR body. If this is a tiny change like fixing a typo, feel free to ignore this message."
# TODO should this be close-worthy? I feel like sometimes it's ok
# to not have an issue (like a tiny typo fix) so we should have
# this be a warning.
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
Expand Down