-
Notifications
You must be signed in to change notification settings - Fork 144
[ISSUE #1182]🔨Add remove-label-on-approve.yml #1183
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
name: Remove Label on Approval | ||
|
||
on: | ||
pull_request_review: | ||
types: | ||
- submitted | ||
|
||
jobs: | ||
remove-label-on-approve: | ||
if: github.event.review.state == 'approved' # Trigger only when the review is approved | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Remove label using github-script | ||
uses: actions/github-script@v7 | ||
with: | ||
github-token: ${{ secrets.BOT_TOKEN }} | ||
script: | | ||
const labelToRemove = 'waiting-review'; // The name of the label to remove | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Make label name configurable Consider making the label name configurable through workflow inputs rather than hardcoding it. - const labelToRemove = 'waiting-review'; // The name of the label to remove
+ const labelToRemove = core.getInput('label-name') || 'waiting-review'; Add this to the workflow inputs: on:
pull_request_review:
types:
- submitted
inputs:
label-name:
description: 'Name of the label to remove'
required: false
default: 'waiting-review' |
||
const { context, github } = require('@actions/github'); | ||
|
||
// Get repository and PR context information | ||
const { owner, repo } = context.repo; | ||
const issue_number = context.payload.pull_request.number; | ||
|
||
// Get all labels on the current PR | ||
const { data: labels } = await github.rest.issues.listLabelsOnIssue({ | ||
owner, | ||
repo, | ||
issue_number, | ||
}); | ||
Comment on lines
+29
to
+33
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add error handling for API calls The API calls lack proper error handling, which could lead to silent failures. - const { data: labels } = await github.rest.issues.listLabelsOnIssue({
- owner,
- repo,
- issue_number,
- });
+ try {
+ const { data: labels } = await github.rest.issues.listLabelsOnIssue({
+ owner,
+ repo,
+ issue_number,
+ });
+
+ // Check if the target label exists
+ const labelExists = labels.some(label => label.name === labelToRemove);
+ if (labelExists) {
+ // Remove the label
+ await github.rest.issues.removeLabel({
+ owner,
+ repo,
+ issue_number,
+ name: labelToRemove,
+ });
+ console.log(`Label '${labelToRemove}' has been removed.`);
+ } else {
+ console.log(`Label '${labelToRemove}' does not exist on this PR.`);
+ }
+ } catch (error) {
+ core.setFailed(`Failed to manage labels: ${error.message}`);
+ } Also applies to: 40-46 |
||
|
||
// Check if the target label exists | ||
const labelExists = labels.some(label => label.name === labelToRemove); | ||
if (labelExists) { | ||
// Remove the label | ||
await github.rest.issues.removeLabel({ | ||
owner, | ||
repo, | ||
issue_number, | ||
name: labelToRemove, | ||
}); | ||
console.log(`Label '${labelToRemove}' has been removed.`); | ||
} else { | ||
console.log(`Label '${labelToRemove}' does not exist on this PR.`); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Document required token permissions
The workflow uses
BOT_TOKEN
but doesn't specify the required permissions. This should be documented to ensure proper setup.Add a comment explaining the required permissions:
+ # Requires a token with 'issues:write' permissions to manage labels github-token: ${{ secrets.BOT_TOKEN }}
📝 Committable suggestion