Skip to content

Add labeler workflow for categorizing Pull Requests based on template #5754

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
13 changes: 13 additions & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
@@ -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`)'
11 changes: 8 additions & 3 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,18 @@ Closes #

<!-- List of things removed in this PR -->

### Risk

- **Low risk:** TBD low risk definition. <!-- (`risk:low`) -->
- **High risk:** TBD high risk definition. <!-- (`risk:high`) -->

### Rollout strategy

<!-- How do you recommend this change to be rolled out? Refer to [contributor docs on Versioning](https://github.com/primer/react/blob/main/contributor-docs/versioning.md) for details. -->

- [ ] Patch release
- [ ] Minor release
- [ ] Major release; if selected, include a written rollout or migration plan
- [ ] Patch release <!-- (`release:patch`) -->
- [ ] Minor release <!-- (`release:minor`) -->
- [ ] Major release; if selected, include a written rollout or migration plan <!-- (`release:major`) -->
- [ ] None; if selected, include a brief description as to why

### Testing & Reviewing
Expand Down
62 changes: 62 additions & 0 deletions .github/workflows/label-pull-request.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
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 = '<!-- action:label-pull-request job:label -->';
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) {
//
}
}
Loading