Skip to content

Commit

Permalink
Ignore PRs whose branches indicate workflows updates
Browse files Browse the repository at this point in the history
Such PRs can't be automatically managed by bots.

Fixes #10.
  • Loading branch information
pbrisbin committed Dec 20, 2023
1 parent 2708abf commit 8265c98
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,4 @@ runs:
GH_PR_ACTION: ${{ github.event.action }}
GH_PR_NUMBER: ${{ github.event.number }}
GH_PR_TITLE: ${{ github.event.pull_request.title }}
GH_PR_HEAD_REF: ${{ github.event.pull_request.head.ref }}
15 changes: 13 additions & 2 deletions bin/automerge-prs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ fi
: "${GH_PR_ACTION:=""}"
: "${GH_PR_NUMBER:=""}"
: "${GH_PR_TITLE:=""}"
: "${GH_PR_HEAD_REF:=""}"

is_dependabot() {
[[ "$GH_ACTOR" == 'dependabot[bot]' ]] && [[ "$GH_EVENT" == 'pull_request' ]]
Expand All @@ -23,14 +24,18 @@ exclude_by_title() {
[[ -n "$EXCLUDE_TITLE_REGEX" ]] && [[ "$1" =~ $EXCLUDE_TITLE_REGEX ]]
}

is_workflows_update() {
[[ "$1" =~ ^dependabot/github_actions/.* ]]
}

gh_pr() {
gh pr --repo "$GH_REPO" "$@"
}

tmp=$(mktemp -d)
trap 'rm -rf "$tmp"' EXIT

if is_dependabot && ! exclude_by_title "$GH_PR_TITLE"; then
if is_dependabot && ! exclude_by_title "$GH_PR_TITLE" && ! is_workflows_update "$GH_PR_HEAD_REF"; then
if ((QUARANTINE_DAYS <= 0)); then
when_message="the next time it runs"
else
Expand Down Expand Up @@ -79,7 +84,7 @@ since_s=$((now_s - (QUARANTINE_DAYS * 24 * 60 * 60)))
since=$(date -d "@$since_s" +"%Y-%m-%d")

search="author:app/dependabot updated:<$since"
fields='number,title,author,updatedAt,reviewDecision'
fields='number,title,headRefName,author,updatedAt,reviewDecision'

gh_pr list --search "$search" --limit 1000 --json "$fields" --jq '.[]' |
while IFS=$'\n' read -r ln; do
Expand All @@ -92,6 +97,7 @@ found=0
for json in "$tmp"/*.json; do
number=$(jq --raw-output '.number' "$json")
title=$(jq --raw-output '.title' "$json")
branch=$(jq --raw-output '.headRefName' "$json")
updatedAt=$(jq --raw-output '.updatedAt' "$json")
reviewDecision=$(jq --raw-output '.reviewDecision' "$json")
found=1
Expand All @@ -105,6 +111,11 @@ for json in "$tmp"/*.json; do
continue
fi

if is_workflows_update "$branch"; then
printf ' \e[1;37m=>\e[0m \e[33mSkip\e[0m (PR updates worflows)\n'
continue
fi

case "$reviewDecision" in
CHANGES_REQUESTED)
printf ' \e[1;37m=>\e[0m \e[33mSkip\e[0m (changes requested)\n'
Expand Down

0 comments on commit 8265c98

Please sign in to comment.