Skip to content

Pull Requests Status Labels #36

Pull Requests Status Labels

Pull Requests Status Labels #36

Workflow file for this run

name: Pull Requests Status Labels
on:
workflow_run:
workflows: ['Lints']
types:
- completed
jobs:
label:
name: Add jobs labels
runs-on: ubuntu-latest
if: >
${{ github.event.workflow_run.event == 'pull_request' }}
steps:
- name: 'Download artifact'
uses: actions/[email protected]
with:
script: |
var artifacts = await github.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: ${{ github.event.workflow_run.id }},
});
var matchArtifact = artifacts.data.artifacts.filter((artifact) => {
return artifact.name == "pr"
})[0];
var download = await github.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact.id,
archive_format: 'zip',
});
var fs = require('fs');
fs.writeFileSync('${{github.workspace}}/pr.zip', Buffer.from(download.data));
- run: unzip pr.zip
- name: 'Set labels'
uses: actions/[email protected]
with:
script: |
var fs = require('fs');
var issue_number = Number(fs.readFileSync('./NR'));
var jobs = await github.actions.listJobsForWorkflowRun({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: ${{ github.event.workflow_run.id }},
})
var labels = {
failure: [],
success: []
}
for (const job of jobs.data.jobs) {
var match = job.name.match(/\(([^)]+)\)/)
var label = match && match[1]
if (label) { labels[job.conclusion].push(label) }
}
if (labels.failure.length > 0) {
await github.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue_number,
labels: labels.failure
}).catch((e) => {
console.error(`Cannot add labels ${labels}: ${e.message}`)
})
}
for (const label of labels.success) {
await github.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue_number,
name: label
}).catch((e) => {
console.error(`Cannot remove label ${label}: ${e.message}`)
})
}