Skip to content

Commit

Permalink
#30488: Rewriting 'Next Release' issue labeling for 'QA : Approved' a…
Browse files Browse the repository at this point in the history
…nd 'QA : Not Needed' (#30886)

The internal workflow that takes care of the actual labeling is more
flexible and generic so all that was hardcoded is parametrized now.
  • Loading branch information
victoralfaro-dotcms authored Dec 9, 2024
1 parent b40d2e6 commit ba131d5
Show file tree
Hide file tree
Showing 3 changed files with 149 additions and 116 deletions.
142 changes: 142 additions & 0 deletions .github/workflows/issue_comp_label-conditional-labeling.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
# action.yml
name: 'Label-based Conditional Labeling'
on:
workflow_call:
inputs:
issue_number:
description: 'Issue number'
type: number
required: true
evaluating_labels:
description: 'Comma delimited list of labels to evaluate against'
type: string
required: true
evaluated_labels:
description: 'Comma delimited list of labels to be evaluated'
type: string
required: true
ignore_issue_labels:
description: 'Comma delimited list of issue labels to ignore'
type: string
required: false
default: ''
new_labels:
description: 'Comma delimited list of new labels to be added to issue'
type: string
required: true
secrets:
CI_MACHINE_TOKEN:
description: 'CI machine token'
required: true
workflow_dispatch:
inputs:
issue_number:
description: 'Issue number'
type: number
required: true
default: 1
evaluating_labels:
description: 'Comma delimited list of labels to evaluate against'
type: string
required: true
evaluated_labels:
description: 'Comma delimited list of labels to be evaluated'
type: string
required: true
ignore_issue_labels:
description: 'Comma delimited list of issue labels to ignore'
type: string
required: false
default: ''
new_labels:
description: 'Comma delimited list of new labels to be added to issue'
type: string
required: true

jobs:
conditional-labeling:
runs-on: ubuntu-20.04
env:
REPO: core
steps:
- run: echo 'GitHub context'
env:
GITHUB_CONTEXT: ${{ toJSON(github) }}
- name: Resolve Labels
id: resolve-labels
uses: actions/github-script@v7
with:
result-encoding: string
script: |
const evaluatingLabels = '${{ inputs.evaluating_labels }}'.split(',').map(lbl => lbl.trim());
let issueNumber;
const issue = context.payload.issue;
if (!issue && '${{ inputs.issue_number }}'.trim() === '') {
core.warning('Issue number is not provided');
process.exit(0);
}
if ('${{ inputs.evaluated_labels }}'.trim() === '') {
core.warning('New labels are missing, exiting');
process.exit(0);
}
const evaluatedLabels = '${{ inputs.evaluated_labels }}'.split(',').map(lbl => lbl.trim());
console.log(`Received these labels to be evaluated: [${evaluatedLabels.join(', ')}]`);
const filteredLabels = evaluatedLabels.filter(lbl => evaluatingLabels.includes(lbl));
if (filteredLabels.length === 0) {
core.warning(`Evaluated labels are not in [${evaluatingLabels.join(', ')}] label group, exiting`);
process.exit(0);
}
core.setOutput('labels', JSON.stringify(filteredLabels));
- name: Add Labels
uses: actions/github-script@v7
if: success() && steps.resolve-labels.outputs.labels != ''
with:
result-encoding: string
retries: 3
retry-exempt-status-codes: 400,401
script: |
const ignoreIssueLabels = '${{ inputs.ignore_issue_labels }}'.split(',').map(lbl => lbl.trim());
async function getIssue(issueNumber) {
const response = await github.rest.issues.get({
issue_number: issueNumber,
owner: '${{ github.repository_owner }}',
repo: '${{ env.REPO }}'
});
return response.data;
}
if ('${{ inputs.issue_number }}'.trim() === '') {
core.warning('Issue number is missing, exiting');
process.exit(0);
}
const issue = await getIssue(${{ inputs.issue_number }});
if (!issue) {
core.warning('Issue [${{ inputs.issue_number }}] not found');
process.exit(0);
}
console.log(`Issue: ${JSON.stringify(issue, null, 2)}`);
const issueNumber = issue.number;
const foundLabel = ignoreIssueLabels.find(lbl => issue.labels.includes(lbl));
if (foundLabel) {
core.warning(`Issue does have label in [${ignoreIssueLabels.join(', ')}] ignore labels group, aborting...`);
process.exit(0);
}
const newLabels = '${{ inputs.new_labels }}'.split(',').map(lbl => lbl.trim());
await github.rest.issues.addLabels({
issue_number: issueNumber,
owner: '${{ github.repository_owner }}',
repo: '${{ env.REPO }}',
labels: newLabels
});
const updated = await getIssue(issueNumber);
console.log(`Issue [${issueNumber}] now got labels: ${JSON.stringify(updated.labels, null, 2)}`);
115 changes: 0 additions & 115 deletions .github/workflows/issue_comp_next-release-label.yml

This file was deleted.

8 changes: 7 additions & 1 deletion .github/workflows/issue_on-change_post-issue-edited.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ jobs:
next-release-label-update:
name: Next Release label update
if: github.event.action == 'labeled'
uses: ./.github/workflows/issue_comp_next-release-label.yml
uses: ./.github/workflows/issue_comp_label-conditional-labeling.yml
with:
issue_number: ${{ github.event.issue.number }}
evaluating_labels: 'QA : Approved,QA : Not Needed'
evaluated_labels: '${{ github.event.label.name }}'
ignore_issue_labels: 'Next Release'
new_labels: 'Next Release'
secrets:
CI_MACHINE_TOKEN: ${{ secrets.CI_MACHINE_TOKEN }}

0 comments on commit ba131d5

Please sign in to comment.