diff --git a/.github/workflows/add-qa-label.yaml b/.github/workflows/add-qa-label.yaml new file mode 100644 index 00000000000..ad83771dccc --- /dev/null +++ b/.github/workflows/add-qa-label.yaml @@ -0,0 +1,20 @@ +name: Add QA Label +on: + issues: + types: + - opened +jobs: + add_qa_label_to_issues: + runs-on: ubuntu-latest + permissions: + issues: write + steps: + - uses: actions/checkout@v2 + - name: Use Node.js + uses: actions/setup-node@v1 + with: + node-version: '16.x' + - name: script + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: node .github/workflows/scripts/add-qa-label.js diff --git a/.github/workflows/scripts/add-qa-label.js b/.github/workflows/scripts/add-qa-label.js new file mode 100644 index 00000000000..0758d18f6bc --- /dev/null +++ b/.github/workflows/scripts/add-qa-label.js @@ -0,0 +1,61 @@ +#!/usr/bin/env node + +const request = require('./request'); + +const QA_DEV_AUTOMATION_LABEL = 'QA/dev-automation'; +const QA_MANUAL_TEST_LABEL = 'QA/manual-test'; +const QA_NONE_LABEL = 'QA/None'; + +const EMBER_LABEL = 'ember'; +const TECH_DEBT_LABEL = 'kind/tech-debt'; + +// The event object +const event = require(process.env.GITHUB_EVENT_PATH); + +async function processOpenAction() { + const issue = event.issue; + + console.log('======'); + console.log('Processing Opened Issue #' + issue.number + ' : ' + issue.title); + console.log('======'); + + // Get an array of labels + const labels = issue.labels.map((label) => label.name); + + // Check we have a QA label + if (!labels.includes(QA_DEV_AUTOMATION_LABEL) && !labels.includes(QA_MANUAL_TEST_LABEL) && !labels.includes(QA_NONE_LABEL)) { + + // Add the appropriate QA label + if (labels.includes(TECH_DEBT_LABEL)) { + console.log(' Issue does not have a QA label, adding QA/None label (as issue is marked as tech-debt)'); + + labels.push(QA_NONE_LABEL); + } else if (labels.includes(EMBER_LABEL)) { + console.log(' Issue does not have a QA label, adding manual test label (as issue is marked as ember)'); + + labels.push(QA_MANUAL_TEST_LABEL); + } else { + console.log(' Issue does not have a QA label, adding dev-automation label'); + + labels.push(QA_DEV_AUTOMATION_LABEL); + } + + // Update the labels + const labelsAPI = `${issue.url}/labels`; + await request.put(labelsAPI, { labels }); + + console.log(' Issue has been updated with QA label'); + } else { + console.log(' Issue already has a QA label, nothing to do'); + } +} + +// Debugging +// console.log(JSON.stringify(event, null, 2)); + +// Look at the action +if (event.action === 'opened') { + processOpenAction(); +} else { + console.log(`Unsupported action: ${event.action}`); +}