mirror of
https://github.com/supabase/supabase.git
synced 2026-12-03 23:18:57 +00:00
feat(docs): nudge approved docs PRs with no activity for 3 days
This commit is contained in:
1 parent
ccabb68033
commit
ffb574ea67
1 file changed
+93
@@ -0,0 +1,93 @@
|
||||
name: Docs PR Tracker
|
||||
|
||||
# Daily jobs that keep docs PRs moving. Runs on weekday mornings.
|
||||
on:
|
||||
schedule:
|
||||
- cron: '0 11 * * 1-5'
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
dry_run:
|
||||
description: Log the PRs that would get a comment, without commenting
|
||||
type: boolean
|
||||
default: true
|
||||
|
||||
permissions: {}
|
||||
|
||||
jobs:
|
||||
approval-nudge:
|
||||
name: Nudge approved docs PRs
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
issues: write
|
||||
pull-requests: read
|
||||
steps:
|
||||
- name: Comment on approved docs PRs with no activity for 3 days
|
||||
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
|
||||
env:
|
||||
DRY_RUN: ${{ inputs.dry_run }}
|
||||
with:
|
||||
script: |
|
||||
const { owner, repo } = context.repo
|
||||
const dryRun = process.env.DRY_RUN === 'true'
|
||||
const marker = '<!-- docs-approval-nudge -->'
|
||||
const cutoff = Date.now() - 3 * 24 * 60 * 60 * 1000
|
||||
|
||||
const query = `query ($q: String!, $cursor: String) {
|
||||
search(query: $q, type: ISSUE, first: 50, after: $cursor) {
|
||||
pageInfo { hasNextPage endCursor }
|
||||
nodes {
|
||||
... on PullRequest {
|
||||
number
|
||||
author { login }
|
||||
headRepository { nameWithOwner }
|
||||
commits(last: 1) { nodes { commit { committedDate statusCheckRollup { state } } } }
|
||||
comments(last: 20) { nodes { createdAt author { __typename } } }
|
||||
reviews(last: 20) { nodes { state submittedAt authorAssociation author { login } } }
|
||||
}
|
||||
}
|
||||
}
|
||||
}`
|
||||
const q = `repo:${owner}/${repo} is:pr is:open draft:false review:approved label:documentation base:master`
|
||||
const prs = []
|
||||
let cursor = null
|
||||
do {
|
||||
const { search } = await github.graphql(query, { q, cursor })
|
||||
prs.push(...search.nodes)
|
||||
cursor = search.pageInfo.hasNextPage ? search.pageInfo.endCursor : null
|
||||
} while (cursor)
|
||||
|
||||
for (const pr of prs) {
|
||||
const commit = pr.commits.nodes[0]?.commit
|
||||
if (commit?.statusCheckRollup?.state !== 'SUCCESS') continue
|
||||
|
||||
// Bot comments, such as preview deploy updates, don't count as activity.
|
||||
const activity = [
|
||||
commit.committedDate,
|
||||
...pr.comments.nodes.filter((c) => c.author?.__typename !== 'Bot').map((c) => c.createdAt),
|
||||
...pr.reviews.nodes.map((r) => r.submittedAt),
|
||||
].filter(Boolean)
|
||||
if (Math.max(...activity.map((date) => Date.parse(date))) > cutoff) continue
|
||||
|
||||
const comments = await github.paginate(github.rest.issues.listComments, { owner, repo, issue_number: pr.number, per_page: 100 })
|
||||
if (comments.some((comment) => comment.body?.includes(marker))) continue
|
||||
|
||||
const isFork = pr.headRepository?.nameWithOwner !== `${owner}/${repo}`
|
||||
let body
|
||||
if (isFork) {
|
||||
const approver = pr.reviews.nodes
|
||||
.filter((r) => r.state === 'APPROVED' && ['MEMBER', 'OWNER'].includes(r.authorAssociation))
|
||||
.at(-1)?.author?.login
|
||||
if (!approver) continue
|
||||
body = `@${approver} This PR is approved and its checks pass. Its author can't merge from a fork, so it's ready for you to merge.`
|
||||
} else {
|
||||
body = `@${pr.author.login} This PR is approved and its checks pass, so it's ready for you to merge.`
|
||||
}
|
||||
body = [marker, body, '', 'For who merges what, see [Merge an approved PR](https://github.com/supabase/supabase/blob/master/apps/docs/CONTRIBUTING.md#merge-an-approved-pr).'].join('\n')
|
||||
|
||||
if (dryRun) {
|
||||
core.info(`Would comment on #${pr.number}:\n${body}`)
|
||||
} else {
|
||||
await github.rest.issues.createComment({ owner, repo, issue_number: pr.number, body })
|
||||
core.info(`Commented on #${pr.number}`)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user