Skip to content
name: Add Invalid Label if Low Quality Label is Added
on:
issues:
types: [labeled]
pull_request:
types: [labeled]
jobs:
add_invalid_label:
runs-on: ubuntu-latest
steps:
- name: Check if "low quality" label was added
if: ${{ github.event.label.name == 'low quality' }}
uses: actions/github-script@v6
with:
script: |
const { context, github } = require('@actions/github');
// Define the label to be added
const labelToAdd = 'invalid';
// Get the issue or pull request number
const issue_number = context.payload.issue ? context.payload.issue.number : context.payload.pull_request.number;
// Check if the 'invalid' label already exists
const existingLabels = context.payload.issue ? context.payload.issue.labels : context.payload.pull_request.labels;
const labelExists = existingLabels.some(label => label.name === labelToAdd);
if (!labelExists) {
// Add 'invalid' label if it doesn't exist
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue_number,
labels: [labelToAdd]
});
console.log(`Label "${labelToAdd}" added to issue/pr #${issue_number}.`);
} else {
console.log(`Label "${labelToAdd}" already exists on issue/pr #${issue_number}. No action taken.`);
}