Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Warn if there are library changes, but not tests
const modifiedAppFiles = modified.filter(p => p.includes('src/'))
const hasAppChanges = modifiedAppFiles.length > 0
const testChanges = modifiedAppFiles.filter(filepath => /test/i.test(filepath))
const hasTestChanges = testChanges.length > 0
if (hasAppChanges && !hasTestChanges) {
warn(
'There are library changes, but not tests. That\'s OK as long as you\'re refactoring existing code',
)
}
// Warn if someone wants to change peril settings
if (modified.filter(p => p.includes('peril')).length) {
fail('Peril settings are being changed')
}
// TODO: fs won't work in peril
// // Be careful of leaving testing shortcuts in the codebase
// const onlyTestFiles = testChanges.filter(x => {
// const content = fs.readFileSync(x).toString();
// return (
// content.includes('it.only') ||
// content.includes('describe.only') ||
// content.includes('fdescribe') ||
// content.includes('fit(')
// );
// });
// raiseIssueAboutPaths(fail, onlyTestFiles, 'an `only` was left in the test');
return configFilePattern.test(filePath);
});
const modifiedGenerateConfigScriptFiles = danger.git.modified_files.filter((filePath) => {
const srcFilePattern = /\/scripts\/generate-app-config/i;
return srcFilePattern.test(filePath);
});
const hasCHANGELOGChanges = modifiedChangelog.length > 0 || newChangelog.length > 0;
const hasModifiedSrcFiles = modifiedSrcFiles.length > 0;
const hasModifiedConfigFiles = modifiedConfigFiles.length > 0;
const hasModifiedGenerateConfigScriptFiles = modifiedGenerateConfigScriptFiles.length > 0;
// Fail if there are src code changes without a CHANGELOG update
if ((hasModifiedSrcFiles || hasModifiedConfigFiles || hasModifiedGenerateConfigScriptFiles) && !hasCHANGELOGChanges) {
fail('Please include a CHANGELOG entry with this PR.');
}
)
}
if (logos.created) {
message(
[
':art: Thanks for submitting a logo. <br>',
'Please ensure your contribution follows our ',
'[guidance](https://github.com/badges/shields/blob/master/doc/logos.md#contributing-logos) ',
'for logo submissions.',
].join('')
)
}
if (capitals.created || underscores.created) {
fail(
[
'JavaScript source files should be named with `kebab-case` ',
'(dash-separated lowercase).',
].join('')
)
}
const allFiles = danger.git.created_files.concat(danger.git.modified_files)
if (allFiles.length > 100) {
warn("Lots 'o changes. Skipping diff-based checks.")
} else {
allFiles.forEach(file => {
// eslint-disable-next-line promise/prefer-await-to-then
danger.git.diffForFile(file).then(({ diff }) => {
if (/serverSecrets/.test(diff) && !secretsDocs.modified) {
const newPHPFiles = newFiles.filter(
fileName => fileName.includes( '.php' ) && ! fileName.includes( 'tests/php' )
);
const notWhitelistedFiles = [];
newPHPFiles.forEach( file => {
const whitelistedPath = phpWhitelist.find( path => file.includes( path ) );
if ( ! whitelistedPath ) {
notWhitelistedFiles.push( file );
}
} );
if ( notWhitelistedFiles.length > 0 ) {
const stringifiedFilesList = '\n' + notWhitelistedFiles.join( '\n' );
fail(
'Please add these new PHP files to PHPCS whitelist for automatic linting:' +
stringifiedFilesList
);
}
}
// skip if there are no warnings.
if ( results.warnings.length > 0 || results.fails.length > 0 ) {
markdown(
"This is an automated check which relies on [`PULL_REQUEST_TEMPLATE`](https://github.com/Automattic/jetpack/blob/master/.github/PULL_REQUEST_TEMPLATE.md). We encourage you to follow that template as it helps Jetpack maintainers do their job. If you think 'Testing instructions' or 'Proposed changelog entry' are not needed for your PR - please explain why you think so. Thanks for cooperation :robot:"
);
} else {
markdown(
`**Thank you for the great PR description!**
When this PR is ready for review, please apply the \`[Status] Needs Review\` label. If you are an a11n, please have someone from your team review the code if possible. The Jetpack team will also review this PR and merge it to be included in the next Jetpack release.`
import { danger, fail, warn } from 'danger'
if (!danger.github.pr.body.length) {
fail('Please add a description to your PR.')
}
// Warns if there are changes to package.json without changes to yarn.lock.
const packageChanged = danger.git.modified_files.includes('package.json')
const lockfileChanged = danger.git.modified_files.includes('yarn.lock')
if (packageChanged && !lockfileChanged) {
const message = 'Changes were made to package.json, but not to yarn.lock'
const idea = 'Perhaps you need to run `yarn install`?'
warn(`${message} - <i>${idea}</i>`)
}
const someoneAssigned = danger.github.pr.assignee
if (someoneAssigned === null) {
fail('Please assign someone to merge this PR, and optionally include people who should review.');
}
import { danger, fail, warn } from "danger";
// Check if the CHANGELOG.md file has been edited
// Fail the build and post a comment reminding submitters to do so if it wasn't changed
if (!danger.git.modified_files.includes("CHANGELOG.md")) {
warn("Please include an updated `CHANGELOG.md` file.<br>This way we can keep track of all the contributions.");
}
// Check if the PR request is send to the master branch.
// This should only be done by MichMich.
if (danger.github.pr.base.ref === "master" && danger.github.pr.user.login !== "MichMich") {
// Check if the PR body or title includes the text: #accepted.
// If not, the PR will fail.
if ((danger.github.pr.body + danger.github.pr.title).includes("#accepted")) {
fail("Please send all your pull requests to the `develop` branch.<br>Pull requests on the `master` branch will not be accepted.");
}
}
}
if (hasOperation(diffs, 'remove') || hasOperation(diffs, 'replace')) {
const allRemovedUsernames = diffs
.filter(x => x.op === 'remove' || x.op === 'replace')
.map(x => getIndexFromPath(x.path))
.map(idx => jsonPatch.before.data[idx])
.map(pixel => pixel.username)
.filter(username => username !== '');
if (allRemovedUsernames.length > 0) {
const uniqueRemovedUsernames = [...new Set(allRemovedUsernames)];
fail(
'It seems like you are accidentally deleting some contributions of others. Please make sure you have pulled the latest changes from the master branch and resolved any merge conflicts. https://help.github.com/en/articles/syncing-a-fork'
);
fail(
`Make sure that the following usernames are indeed included: ${uniqueRemovedUsernames.join(
','
)}`
);
return false;
}
}
let currentPixelIndex = undefined;
for (let diff of diffs) {
const idx = getIndexFromPath(diff.path);
if (typeof currentPixelIndex === 'undefined') {
currentPixelIndex = idx;
}
if (currentPixelIndex !== idx) {
function handleMultipleFileChanges(gitChanges) {
fail(
'This PR requires a manual review because you are changing more files than just `_data/pixels.json`.'
);
markdown(stripIndent`
## FAQ
*Why has my Pull Request failed the tests?*
Your Pull Request didn't fail the tests but you modified more files with
this PR than just the \`_data/pixels.json\` file.
The files you modified are:
${gitChanges.modified_files.map(name => `- ${name}`).join('\n')}
${gitChanges.created_files.map(name => `- ${name}`).join('\n')}
${gitChanges.deleted_files.map(name => `- ${name}`).join('\n')}
If you did this on purpose, please consider breaking your PR into multiple ones.
`I'm sorry but you can't remove a pixel that someone else contributed`
);
return false;
} else if (linePatch.op === 'replace' || linePatch.op === 'test') {
return isValidPixelUpdate(jsonPatch, linePatch, gitHubUsername);
} else {
fail(
`I'm sorry but you can only contribute one pixel per GitHub username.`
);
}
} else {
if (!allPatchesAreForTheSamePixel(jsonPatch)) {
return false;
} else {
if (jsonPatch.diff.length === 0) {
fail('This PR appears to be empty and needs a manual review');
return false;
}
return isValidPixelUpdate(jsonPatch, jsonPatch.diff[0], gitHubUsername);
}
}
return false;
}
typeof pixel.x !== 'number' ||
pixel.x < 0 ||
!Number.isInteger(pixel.x)
) {
fail(
'Please make sure your pixel submission has a valid positive `x` coordinate as an integer.'
);
result = false;
}
if (
typeof pixel.y !== 'number' ||
pixel.y < 0 ||
!Number.isInteger(pixel.y)
) {
fail(
'Please make sure your pixel submission has a valid positive `y` coordinate as an integer.'
);
result = false;
}
return result;
}