|
| 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 | +permissions: read-all |
| 14 | + |
| 15 | +jobs: |
| 16 | + notify-ready-prs: |
| 17 | + permissions: |
| 18 | + pull-requests: write |
| 19 | + runs-on: ubuntu-latest |
| 20 | + steps: |
| 21 | + - name: Check |
| 22 | + env: |
| 23 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 24 | + run: | |
| 25 | + # Number of days before repeating the gatekeepers ping |
| 26 | + days=3 |
| 27 | + days_in_seconds=$((days*24*60*60)) |
| 28 | +
|
| 29 | + # Function to ping gatekeepers and print debug info |
| 30 | + ping_gatekeepers() { |
| 31 | + pr_number=$1 |
| 32 | + gh pr comment "$pr_number" --repo intel/llvm --body "@intel/llvm-gatekeepers please consider merging" |
| 33 | + echo "Pinged @intel/llvm-gatekeepers for https://github.com/intel/llvm/pull/$pr_number" |
| 34 | + } |
| 35 | +
|
| 36 | + # Get the list of suitable PRs |
| 37 | + prs=$(gh pr list --search "is:open review:approved draft:no status:success" --repo intel/llvm --json number --jq '.[].number') |
| 38 | + now=$(date -u +%s) |
| 39 | + for pr in $prs; do |
| 40 | + # Get the timestamp of the latest comment mentioning @intel/llvm-gatekeepers |
| 41 | + latest_ts=$(gh pr view $pr --repo intel/llvm --json comments \ |
| 42 | + --jq '[.comments[] | select(.body | test("@intel/llvm-gatekeepers")) | .createdAt] | last') |
| 43 | + # If there is no previous mention, ping the gatekeepers |
| 44 | + if [[ -z "$latest_ts" ]]; then |
| 45 | + ping_gatekeepers "$pr" |
| 46 | + # If the latest mention is older than $days, ping the gatekeepers again |
| 47 | + else |
| 48 | + comment_time=$(date -u -d "$latest_ts" +%s) |
| 49 | + age=$((now - comment_time)) |
| 50 | + if (( age >= days_in_seconds )); then |
| 51 | + ping_gatekeepers "$pr" |
| 52 | + fi |
| 53 | + fi |
| 54 | + done |
0 commit comments