Repository navigation
feat(web,mobile): continue a thread on another machine from its menu #248294
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: PR Vouch | ||
|
Check warning on line 1 in .github/workflows/pr-vouch.yml
|
||
| on: | ||
| pull_request_target: | ||
| types: [opened, reopened, synchronize, ready_for_review, converted_to_draft] | ||
| issue_comment: | ||
| types: [created] | ||
| push: | ||
| branches: | ||
| - main | ||
| paths: | ||
| - .github/VOUCHED.td | ||
| - .github/workflows/pr-vouch.yml | ||
| permissions: | ||
| contents: read | ||
| # Per-PR events supersede each other at the run level, in arrival order (a job-level group | ||
| # is joined when the job starts, so an older run's slower job could cancel the newer one). | ||
| # Other comments and pushes get a unique group so they never cancel a PR's run. | ||
| concurrency: | ||
| group: >- | ||
| ${{ (github.event_name == 'pull_request_target' || | ||
| (github.event_name == 'issue_comment' && contains(github.event.comment.body, '/recheck-vouch'))) | ||
| && format('pr-vouch-run-{0}', github.event.pull_request.number || github.event.issue.number) | ||
| || format('pr-vouch-run-{0}', github.run_id) }} | ||
| cancel-in-progress: true | ||
| jobs: | ||
| collect-targets: | ||
| name: Collect PR targets | ||
| # Most comments are not recheck commands; skip them before a runner starts. | ||
| if: >- | ||
| github.event_name != 'issue_comment' || | ||
| (github.event.issue.pull_request && contains(github.event.comment.body, '/recheck-vouch')) | ||
| runs-on: ubuntu-24.04 | ||
| permissions: | ||
| pull-requests: read | ||
| outputs: | ||
| targets: ${{ steps.collect.outputs.targets }} | ||
| steps: | ||
| - id: collect | ||
| uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0 | ||
| with: | ||
| script: | | ||
| if (context.eventName === "pull_request_target") { | ||
| const pr = context.payload.pull_request; | ||
| core.setOutput("targets", JSON.stringify([{ number: pr.number, user: pr.user.login }])); | ||
| return; | ||
| } | ||
| if (context.eventName === "issue_comment") { | ||
| const issue = context.payload.issue; | ||
| const body = context.payload.comment?.body ?? ""; | ||
| if (!issue?.pull_request || !body.includes("/recheck-vouch")) { | ||
| core.setOutput("targets", "[]"); | ||
| return; | ||
| } | ||
| core.setOutput( | ||
| "targets", | ||
| JSON.stringify([{ number: issue.number, user: issue.user.login }]), | ||
| ); | ||
| return; | ||
| } | ||
| const pulls = await github.paginate(github.rest.pulls.list, { | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| state: "open", | ||
| per_page: 100, | ||
| }); | ||
| const targets = pulls.map((pull) => ({ | ||
| number: pull.number, | ||
| user: pull.user.login, | ||
| })); | ||
| core.setOutput("targets", JSON.stringify(targets)); | ||
| label: | ||
| name: Label PR ${{ matrix.target.number }} | ||
| needs: collect-targets | ||
| if: ${{ needs.collect-targets.outputs.targets != '[]' }} | ||
| runs-on: ubuntu-24.04 | ||
| permissions: | ||
| contents: read | ||
| pull-requests: write | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| target: ${{ fromJson(needs.collect-targets.outputs.targets) }} | ||
| steps: | ||
| - id: vouch | ||
| name: Check PR author trust | ||
| uses: mitchellh/vouch/action/check-user@d66fa29a64600490892131ad87597c30c91fcac4 # v1.5.0 | ||
| with: | ||
| user: ${{ matrix.target.user }} | ||
| allow-fail: true | ||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| - name: Sync PR labels | ||
| uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0 | ||
| env: | ||
| PR_NUMBER: ${{ matrix.target.number }} | ||
| VOUCH_STATUS: ${{ steps.vouch.outputs.status }} | ||
| with: | ||
| script: | | ||
| const issueNumber = Number(process.env.PR_NUMBER); | ||
| const status = process.env.VOUCH_STATUS; | ||
| const managedLabels = [ | ||
| { | ||
| name: "vouch:trusted", | ||
| color: "1f883d", | ||
| description: "Author is trusted by repo permissions or the VOUCHED list.", | ||
| }, | ||
| { | ||
| name: "vouch:unvouched", | ||
| color: "fbca04", | ||
| description: "Author is not yet trusted in the VOUCHED list.", | ||
| }, | ||
| { | ||
| name: "vouch:denounced", | ||
| color: "d1242f", | ||
| description: "Author is explicitly blocked by the VOUCHED list.", | ||
| }, | ||
| ]; | ||
| const managedLabelNames = new Set(managedLabels.map((label) => label.name)); | ||
| for (const label of managedLabels) { | ||
| try { | ||
| const { data: existing } = await github.rest.issues.getLabel({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| name: label.name, | ||
| }); | ||
| if ( | ||
| existing.color !== label.color || | ||
| (existing.description ?? "") !== label.description | ||
| ) { | ||
| await github.rest.issues.updateLabel({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| name: label.name, | ||
| color: label.color, | ||
| description: label.description, | ||
| }); | ||
| } | ||
| } catch (error) { | ||
| if (error.status !== 404) { | ||
| throw error; | ||
| } | ||
| try { | ||
| await github.rest.issues.createLabel({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| name: label.name, | ||
| color: label.color, | ||
| description: label.description, | ||
| }); | ||
| } catch (createError) { | ||
| if (createError.status !== 422) { | ||
| throw createError; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| const nextLabelName = | ||
| status === "denounced" | ||
| ? "vouch:denounced" | ||
| : ["bot", "collaborator", "vouched"].includes(status) | ||
| ? "vouch:trusted" | ||
| : "vouch:unvouched"; | ||
| const { data: currentLabels } = await github.rest.issues.listLabelsOnIssue({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: issueNumber, | ||
| per_page: 100, | ||
| }); | ||
| for (const label of currentLabels) { | ||
| if (!managedLabelNames.has(label.name) || label.name === nextLabelName) { | ||
| continue; | ||
| } | ||
| try { | ||
| await github.rest.issues.removeLabel({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: issueNumber, | ||
| name: label.name, | ||
| }); | ||
| } catch (removeError) { | ||
| if (removeError.status !== 404) { | ||
| throw removeError; | ||
| } | ||
| } | ||
| } | ||
| if (!currentLabels.some((label) => label.name === nextLabelName)) { | ||
| await github.rest.issues.addLabels({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: issueNumber, | ||
| labels: [nextLabelName], | ||
| }); | ||
| } | ||
| core.info(`PR #${issueNumber}: ${status} -> ${nextLabelName}`); | ||