Skip to content

Commit 302a603

Browse files
committed
[CI] Add a workflow to check ready PRs
This workflow checks for ready-to-merge PRs - if a PR is open, not a draft, passed all checks, and has been approved, it will ping @intel/llvm-gatekeepers if this group has not already been mentioned or if the last mention was more than $days days ago.
1 parent 388ccf5 commit 302a603

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# This workflow checks for ready-to-merge PRs - if a PR is open, not a draft,
2+
# passed all checks, and has been approved, it will ping @intel/llvm-gatekeepers
3+
# if this group has not already been mentioned or if the last mention was more
4+
# than $days days ago.
5+
6+
name: Check ready-to-merge PRs
7+
8+
on:
9+
schedule:
10+
- cron: '0 * * * *' # every hour
11+
workflow_dispatch:
12+
13+
jobs:
14+
notify-ready-prs:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Check
18+
env:
19+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
20+
run: |
21+
# Number of days before repeating the gatekeepers ping
22+
days=3
23+
days_in_seconds=$((days*24*60*60))
24+
25+
# Function to ping gatekeepers and print debug info
26+
ping_gatekeepers() {
27+
pr_number=$1
28+
gh pr comment "$pr_number" --repo intel/llvm --body "@intel/llvm-gatekeepers please consider merging"
29+
echo "Pinged @intel/llvm-gatekeepers for https://github.com/intel/llvm/pull/$pr_number"
30+
}
31+
32+
# Get the list of suitable PRs
33+
prs=$(gh pr list --search "is:open review:approved draft:no status:success" --repo intel/llvm --json number --jq '.[].number')
34+
now=$(date -u +%s)
35+
for pr in $prs; do
36+
# Get the timestamp of the latest comment mentioning @intel/llvm-gatekeepers
37+
latest_ts=$(gh pr view $pr --repo intel/llvm --json comments \
38+
--jq '[.comments[] | select(.body | test("@intel/llvm-gatekeepers")) | .createdAt] | last')
39+
# If there is no previous mention, ping the gatekeepers
40+
if [[ -z "$latest_ts" ]]; then
41+
ping_gatekeepers "$pr"
42+
# If the latest mention is older than $days, ping the gatekeepers again
43+
else
44+
comment_time=$(date -u -d "$latest_ts" +%s)
45+
age=$((now - comment_time))
46+
if (( age >= days_in_seconds )); then
47+
ping_gatekeepers "$pr"
48+
fi
49+
fi
50+
done

0 commit comments

Comments
 (0)