Skip to content

Commit

Permalink
Update add-invalid-label.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
mezotv authored Aug 29, 2024
1 parent 9ca3048 commit d1224c8
Showing 1 changed file with 13 additions and 25 deletions.
38 changes: 13 additions & 25 deletions .github/workflows/add-invalid-label.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,44 +16,32 @@ jobs:
uses: actions/github-script@v6
with:
script: |
const github = require('@actions/github');
// Define the labels and the issue/PR number
const labelToAdd = 'invalid';
const issue_number = github.context.payload.issue ? github.context.payload.issue.number : github.context.payload.pull_request.number;
const issue_number = context.payload.issue ? context.payload.issue.number : context.payload.pull_request.number;
// Get the existing labels
const existingLabels = github.context.payload.issue ? github.context.payload.issue.labels : github.context.payload.pull_request.labels;
const existingLabels = context.payload.issue ? context.payload.issue.labels : context.payload.pull_request.labels;
const labelExists = existingLabels.some(label => label.name === labelToAdd);
// Function to add a label
async function addLabel() {
// Add the 'invalid' label if not already present
if (!labelExists) {
await github.rest.issues.addLabels({
owner: github.context.repo.owner,
repo: github.context.repo.repo,
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue_number,
labels: [labelToAdd]
});
console.log(`Label "${labelToAdd}" added to issue/pr #${issue_number}.`);
}
// Function to close the issue or PR
async function closeIssueOrPR() {
await github.rest.issues.update({
owner: github.context.repo.owner,
repo: github.context.repo.repo,
issue_number: issue_number,
state: 'closed'
});
console.log(`Issue/PR #${issue_number} closed.`);
}
// Add the 'invalid' label if not already present
if (!labelExists) {
await addLabel();
} else {
console.log(`Label "${labelToAdd}" already exists on issue/pr #${issue_number}. No action taken.`);
}
// Close the issue or PR
await closeIssueOrPR();
await github.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue_number,
state: 'closed'
});
console.log(`Issue/PR #${issue_number} closed.`);

0 comments on commit d1224c8

Please sign in to comment.