Skip to content

Commit

Permalink
fix: Danger contributors check (#2167)
Browse files Browse the repository at this point in the history
  • Loading branch information
rogeruiz authored Jun 17, 2022
1 parent b120490 commit c05fe06
Showing 1 changed file with 19 additions and 32 deletions.
51 changes: 19 additions & 32 deletions dangerfile.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import * as child from 'child_process'

import { danger, fail, warn } from 'danger'
import { danger, fail, schedule, warn } from 'danger'

const shouldRun = !danger.github || (danger.github && danger.github.pr.user.type !== 'Bot');

// Load all modified and new files
const allFiles = danger.git.modified_files.concat(danger.git.created_files)
Expand Down Expand Up @@ -43,7 +45,7 @@ const checkYarnAudit: () => void = () => {
})
fail(
`${issuesFound}${summary.data.vulnerabilities.high} high vulnerabilities and ` +
`${summary.data.vulnerabilities.critical} critical vulnerabilities found`
`${summary.data.vulnerabilities.critical} critical vulnerabilities found`
)
}
} else {
Expand Down Expand Up @@ -126,43 +128,28 @@ const checkDependencyChanges: () => void = () => {
}
}

// const checkYarnAudit: () => void = () => {
const checkContributorsJSON: () => void = () => {
const packageChanged = allFiles.includes('package.json')
if (packageChanged) {
danger.git
.structuredDiffForFile('package.json')
.then((sdiff) => {
return sdiff.chunks.every((chunk) => {
return chunk.changes
.filter((change) => {
return change.type === 'add' // Filter on additive changes
})
.every((change) => {
return change.content.match(/"contributors":/)
})
})
})
.then((contributorsChanges) => {
if (contributorsChanges) {
const message =
'Do not make changes to package.json around contributors.'
const idea =
'This project only uses .all-contributorsrc for tracking contributors.'
fail(`${message} - <i>${idea}</i>`)
}
})
// Check for any changes to the contributors section of package.json
schedule(async () => {
if (!shouldRun) {
return;
}
}
const pd = await danger.git.JSONDiffForFile('package.json')

if (pd.contributors) {
const message =
'Do not make changes to package.json around contributors.'
const idea =
'This project only uses .all-contributorsrc for tracking contributors.'
fail(`${message} - <i>${idea}</i>`)
}
})

// skip these checks if PR is by any bot (e.g. dependabot), if we
// don't have a github object let it run also since we are local
if (!danger.github || (danger.github && danger.github.pr.user.type !== 'Bot')) {
if (shouldRun) {
checkYarnAudit()
checkPrDescription()

checkCodeChanges()
checkDependencyChanges()

checkContributorsJSON()
}

0 comments on commit c05fe06

Please sign in to comment.