From 9e42280d27ae67b9dbd2e8a64781856db2c3e9fa Mon Sep 17 00:00:00 2001 From: Josh Black Date: Thu, 20 Feb 2025 20:07:57 -0600 Subject: [PATCH] chore: check-in work --- .github/labeler.yml | 13 +++++ .github/pull_request_template.md | 11 +++-- .github/workflows/label-pull-request.yml | 62 ++++++++++++++++++++++++ 3 files changed, 83 insertions(+), 3 deletions(-) create mode 100644 .github/labeler.yml create mode 100644 .github/workflows/label-pull-request.yml diff --git a/.github/labeler.yml b/.github/labeler.yml new file mode 100644 index 00000000000..ed5c9d09557 --- /dev/null +++ b/.github/labeler.yml @@ -0,0 +1,13 @@ +# Add label for the selected risk. +risk:low: + - '(-.*\(`risk:low`)' +risk:high: + - '(-.*\(`risk:high`)' + +# Add label for the selected rollout. +release:patch: + - '(-.*\(`release:patch`)' +release:minor: + - '(-.*\(`release:minor`)' +release:major: + - '(-.*\(`release:major`)' diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index c688667135f..8145fc08e87 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -20,13 +20,18 @@ Closes # +### Risk + +- **Low risk:** TBD low risk definition. +- **High risk:** TBD high risk definition. + ### Rollout strategy -- [ ] Patch release -- [ ] Minor release -- [ ] Major release; if selected, include a written rollout or migration plan +- [ ] Patch release +- [ ] Minor release +- [ ] Major release; if selected, include a written rollout or migration plan - [ ] None; if selected, include a brief description as to why ### Testing & Reviewing diff --git a/.github/workflows/label-pull-request.yml b/.github/workflows/label-pull-request.yml new file mode 100644 index 00000000000..43b68afa28f --- /dev/null +++ b/.github/workflows/label-pull-request.yml @@ -0,0 +1,62 @@ +name: 'Label Pull Request' +on: + pull_request: + branches: + - main + types: [opened, edited, ready_for_review, reopened] + +permissions: + contents: read + issues: write + pull-requests: write + +jobs: + label: + runs-on: ubuntu-latest + if: github.event.pull_request == false + steps: + - id: labeler + uses: github/issue-labeler@v3.4 + with: + configuration-path: .github/labeler.yml + repo-token: ${{ github.token }} + sync-labels: 1 + - name: Manage incomplete labels + if: ${{ (steps.labeler.outputs.labels-added != '') || (steps.labeler.outputs.labels-removed != '') }} + uses: actions/github-script@v7 + env: + AUTHOR: ${{ github.event.pull_request.user.login }} + LABELS_ADDED: ${{ steps.labeler.outputs.labels-added }} + LABELS_REMOVED: ${{ steps.labeler.outputs.labels-removed }} + with: + script: | + const { AUTHOR, LABELS_ADDED, LABELS_REMOVED } = process.env; + + // Label prefixes that should only have one label applied at a time + const exactlyOnePrefix = ['risk', 'release']; + + const existingLabels = context.payload.pull_request.labels.map(l => l.name); + const addedLabels = LABELS_ADDED ? JSON.parse(LABELS_ADDED) : [] + const removedLabels = LABELS_REMOVED ? JSON.parse(LABELS_REMOVED) : [] + const currentLabels = [...new Set([...existingLabels, ...addedLabels])].filter(label => !removedLabels.includes(label)); + + const { data: comments } = await github.rest.issues.listComments({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.payload.pull_request.number + }); + const commentIdentifier = ''; + const previousComment = comments.find(comment => { + return comment.body.includes(commentIdentifier); + }); + + let comment = `${commentIdentifier}\n\n`; + + for (const prefix of exactlyOnePrefix) { + const matches = currentLabels.filter(label => label.startsWith(`${prefix}:`)); + if (matches.length === 1) { + // + } else if (matches.length > 1) { + // + } + }