Skip to content
Open
Changes from all commits
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
67 changes: 62 additions & 5 deletions .github/workflows/review-post.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,59 @@
# no comment at all. It can delete the bot's own comments (a whole review, or
# single findings it has withdrawn), and reply in the threads of its own
# findings. It only ever deletes or replies to comments by github-actions[bot].
#
# Each review also carries a verdict label (Good, Nits, Discuss, Change). A
# push to the PR removes it until the new head is reviewed, so the label never
# describes an older head.
name: react/metro/review-post

on:
repository_dispatch:
types: [metro-review]
# Only removes labels: it never checks out or runs PR code.
pull_request_target:
types: [synchronize]

permissions:
contents: read

concurrency:
group: metro-review-post-${{ github.event.client_payload.pr }}
cancel-in-progress: false

jobs:
# In its own concurrency group, so that a queued post run can't cancel it.
# A post run re-checks the head after adding a verdict, which covers a push
# that lands while it runs.
clear-verdict:
if: github.repository == 'react/metro' && github.event_name == 'pull_request_target'
concurrency:
group: metro-review-clear-${{ github.event.pull_request.number }}
cancel-in-progress: false
runs-on: ubuntu-latest
timeout-minutes: 2
permissions:
issues: write
pull-requests: write
steps:
- uses: actions/github-script@v8
with:
script: |
const VERDICT_LABELS = ['Auto review: Good', 'Auto review: Nits', 'Auto review: Discuss', 'Auto review: Change'];
const {owner, repo} = context.repo;
const issue_number = context.payload.pull_request.number;
// Not filtered by the event's labels: a review of the old head can
// add one after the push, before this job runs.
for (const name of VERDICT_LABELS) {
try {
await github.rest.issues.removeLabel({owner, repo, issue_number, name});
core.notice(`#${issue_number}: removed ${name} after a push`);
} catch (e) {
if (e.status !== 404) throw e;
}
}

post:
if: github.repository == 'react/metro'
if: github.repository == 'react/metro' && github.event_name == 'repository_dispatch'
concurrency:
group: metro-review-post-${{ github.event.client_payload.pr }}
cancel-in-progress: false
runs-on: ubuntu-latest
timeout-minutes: 5
permissions:
Expand All @@ -47,6 +84,10 @@ jobs:
color: 'ededed',
description: 'The Metro review bot skipped this PR (a dependency bot PR or a mechanical tooling update)',
},
'Auto review: Good': {color: '0e8a16', description: 'The Metro review bot found nothing to change at this head'},
'Auto review: Nits': {color: 'c2e0c6', description: 'The Metro review bot found only nits at this head'},
'Auto review: Discuss': {color: 'fbca04', description: 'The Metro review bot raised questions for a maintainer at this head'},
'Auto review: Change': {color: 'd93f0b', description: 'The Metro review bot suggested changes at this head'},
};

// #region Validate the payload
Expand Down Expand Up @@ -146,6 +187,22 @@ jobs:
if (e.status !== 404) throw e;
}
}
// A push since the head check above can't rely on clear-verdict,
// which may have run before this added the label, so undo it here.
const addedVerdicts = addLabels.filter(l => l !== 'Auto review: Skipped');
if (addedVerdicts.length) {
const {data: now} = await github.rest.pulls.get({owner, repo, pull_number: p.pr});
if (now.head.sha !== p.head_sha) {
for (const name of addedVerdicts) {
try {
await github.rest.issues.removeLabel({owner, repo, issue_number: p.pr, name});
} catch (e) {
if (e.status !== 404) throw e;
}
}
core.notice(`#${p.pr} moved to ${now.head.sha.slice(0, 7)} while labeling; removed ${addedVerdicts.join(', ')}`);
}
}
const labelNote = [addLabels.length ? `labels added: ${addLabels.join(', ')}` : null, removeLabels.length ? `labels removed: ${removeLabels.join(', ')}` : null].filter(Boolean).join('; ');

// #endregion
Expand Down
Loading