Skip to content

Commit

Permalink
Add GH Action to ensure new issues have a QA label (rancher#10572)
Browse files Browse the repository at this point in the history
* Add GH Action to ensure new issues have a QA label

* Remove incorrect comment

* Add QA None support

* Add more intelligent choice of label

* Change order of label choice so tech-debt is first
  • Loading branch information
nwmac authored Mar 8, 2024
1 parent 7ef50a1 commit 20462e2
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 0 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/add-qa-label.yaml
Original file line number Diff line number Diff line change
@@ -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
61 changes: 61 additions & 0 deletions .github/workflows/scripts/add-qa-label.js
Original file line number Diff line number Diff line change
@@ -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}`);
}

0 comments on commit 20462e2

Please sign in to comment.