Skip to content

Commit

Permalink
Action now removes all vulnerability labels on a PR if all vulnerabil…
Browse files Browse the repository at this point in the history
…ities have been fixed
  • Loading branch information
Sebastian Dumbs committed Apr 13, 2021
1 parent a24abd1 commit 7e26f3e
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 9 deletions.
29 changes: 23 additions & 6 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1757,14 +1757,14 @@ function run() {
audit.run(auditLevel, productionFlag, 'true');
core.info(audit.stdout);
core.setOutput('npm_audit', audit.stdout);
// get GitHub information
const ctx = JSON.parse(core.getInput('github_context'));
const token = core.getInput('github_token', { required: true });
const octokit = new rest_1.Octokit({
auth: token
});
if (audit.foundVulnerability()) {
// vulnerabilities are found
// get GitHub information
const ctx = JSON.parse(core.getInput('github_context'));
const token = core.getInput('github_token', { required: true });
const octokit = new rest_1.Octokit({
auth: token
});
if (ctx.event_name === 'pull_request') {
yield pr.createComment(token, github.context.repo.owner, github.context.repo.repo, ctx.event.number, audit.strippedStdout());
if (addPrLabels === 'true') {
Expand Down Expand Up @@ -1810,6 +1810,23 @@ function run() {
}
}
}
else {
// remove all vulnerability labels once the PR is fixed
const labels = yield octokit.issues.listLabelsOnIssue({
owner: github.context.repo.owner,
repo: github.context.repo.repo,
issue_number: ctx.event.number
});
const filteredLabelNames = labels.data
.filter(label => !Object.values(audit_1.VULNERABILITIY_TYPE).includes(label.name))
.map(label => label.name);
octokit.issues.setLabels({
owner: github.context.repo.owner,
repo: github.context.repo.repo,
issue_number: ctx.event.number,
labels: [...filteredLabelNames]
});
}
}
catch (error) {
core.setFailed(error.message);
Expand Down
26 changes: 23 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,18 @@ export async function run(): Promise<void> {
core.info(audit.stdout)
core.setOutput('npm_audit', audit.stdout)

if (audit.foundVulnerability()) {
// vulnerabilities are found

// get GitHub information
const ctx = JSON.parse(core.getInput('github_context'))
const token: string = core.getInput('github_token', {required: true})
const octokit = new Octokit({
auth: token
})

if (audit.foundVulnerability()) {
// vulnerabilities are found



if (ctx.event_name === 'pull_request') {
await pr.createComment(
token,
Expand Down Expand Up @@ -130,6 +132,24 @@ export async function run(): Promise<void> {
core.setFailed('This repo has some vulnerabilities')
}
}
} else {
// remove all vulnerability labels once the PR is fixed
const labels = await octokit.issues.listLabelsOnIssue({
owner: github.context.repo.owner,
repo: github.context.repo.repo,
issue_number: ctx.event.number
})

const filteredLabelNames = labels.data
.filter(label => !Object.values(VULNERABILITIY_TYPE).includes(label.name as VULNERABILITIY_TYPE))
.map(label => label.name)

octokit.issues.setLabels({
owner: github.context.repo.owner,
repo: github.context.repo.repo,
issue_number: ctx.event.number,
labels: [...filteredLabelNames]
})
}
} catch (error) {
core.setFailed(error.message)
Expand Down

0 comments on commit 7e26f3e

Please sign in to comment.