Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import { danger, fail, warn } from "danger"
import * as fs from "fs"
// Setup
const pr = danger.github.pr
const modified = danger.git.modified_files
const bodyAndTitle = (pr.body + pr.title).toLowerCase()
// Custom modifiers for people submitting PRs to be able to say "skip this"
const trivialPR = bodyAndTitle.includes("trivial")
const filesOnly = (file: string) => fs.existsSync(file) && fs.lstatSync(file).isFile()
// Custom subsets of known files
const modifiedAppFiles = modified.filter(p => p.includes("src/")).filter(p => filesOnly(p))
// When there are app-changes and it's not a PR marked as trivial, expect
// there to be CHANGELOG changes.
const changelogChanges = modified.includes("CHANGELOG.md")
if (modifiedAppFiles.length > 0 && !trivialPR && !changelogChanges) {
fail("No CHANGELOG added.")
}
const includesSummary =
danger.github.pr.body &&
danger.github.pr.body.toLowerCase().includes('## summary');
if (!danger.github.pr.body || danger.github.pr.body.length < 50) {
fail(':grey_question: This pull request needs a description.');
} else if (!includesSummary) {
const title = ':clipboard: Missing Summary';
const idea =
'Can you add a Summary? ' +
'To do so, add a "## Summary" section to your PR description. ' +
'This is a good place to explain the motivation for making this change.';
message(`${title} - <i>${idea}</i>`);
}
// Warns if there are changes to package.json, and tags the team.
const packageChanged = includes(danger.git.modified_files, 'package.json');
if (packageChanged) {
const title = ':lock: package.json';
const idea =
'Changes were made to package.json. ' +
'This will require a manual import by a Facebook employee.';
warn(`${title} - <i>${idea}</i>`);
}
// Provides advice if a test plan is missing.
const includesTestPlan =
danger.github.pr.body &&
danger.github.pr.body.toLowerCase().includes('## test plan');
if (!includesTestPlan) {
const title = ':clipboard: Missing Test Plan';
const idea =
'Can you add a Test Plan? ' +
import { danger } from 'danger';
// Ensure that people include a description on their PRs
if (danger.github.pr.body.length === 0) {
fail('Please include a body for your PR');
}
if (
danger.git.created_files.find(filename => filename.startsWith('rules/')) &&
!danger.git.modified_files.includes('README.md')
) {
fail('Please update the README when new rules are added');
}
/**
* External dependencies
*/
import { danger, warn, markdown, results, schedule, fail } from 'danger';
const moment = require( 'moment' );
const phpWhitelist = require( './bin/phpcs-whitelist' );
const github = danger.github;
const pr = github.pr;
const newFiles = danger.git.created_files;
// No PR is too small to include a description of why you made a change
if ( pr.body.length < 10 ) {
warn( 'Please include a description of your PR changes.' );
}
// Keep track of commits which skipped pre-commit hook
const notVerifiedCommits = danger.git.commits.filter( commit =>
commit.message.includes( '[not verified]' )
);
if ( notVerifiedCommits.length > 0 ) {
warn( '`pre-commit` hook was skipped for one or more commits' );
}
// Use labels please!
const ghLabels = github.issue.labels;
import { readFileSync } from "fs"
const hasChangelog = danger.git.modified_files.includes("CHANGELOG.md")
if (!hasChangelog) {
warn("Please add a changelog entry for your changes. You can find it in `CHANGELOG.md`")
}
// Ensure the NodeJS versions match everywhere
const nodeVersion = JSON.parse(readFileSync("package.json", "utf8")).engines.node
if (!readFileSync("../.circleci/config.yml", "utf8").includes("circleci/node:" + nodeVersion)) {
warn("The `.circleci/config.yml` does not have the same version of node in it (" + nodeVersion + ")")
}
if (
danger.git.modified_files.includes("source/db/GitHubRepoSettings.ts") &&
danger.git.modified_files.includes("source/db/index.ts")
) {
warn("You may need to run `yarn generate:types:schema`.")
}
export default async () => {
// Rule: encourage all new files to be TypeScript
const jsAppFiles = danger.git.created_files.filter(
f => f.startsWith("src/") && f.endsWith(".js")
)
const testFiles = danger.git.created_files
.concat(danger.git.modified_files)
.filter(f => f.includes(".test.ts") || f.includes(".test.js"))
if (jsAppFiles.length) {
const listed = danger.github.utils.fileLinks(jsAppFiles)
fail(`Please use <code>*.ts</code> for new files. Found: ${listed}.`)
}
// Compare a printed copy of the schema
// with the file in the repo.
const schemaText = printSchema(schema as any, { commentDescriptions: true })
const prettySchema = prettier.format(schemaText, { parser: "graphql" })
const localGQL = readFileSync("_schema.graphql", "utf8")
}
},
});
});
}),
)).filter(str => str.length);
if (tsLintResult.length) {
tsLintResult.forEach(tsLintFail => {
fail(`${tsLintFail}`);
});
} else {
message('✅ TSLint passed');
}
});
const hasChangelog = danger.git.modified_files.indexOf('CHANGELOG.md') !== -1;
const isTrivial = (danger.github.pr.body + danger.github.pr.title).includes('#trivial');
if (!hasChangelog && !isTrivial) {
warn('Please add a changelog entry for your changes.');
}
schedule(async () => {
const result = (await promisify(exec)('cd packages/browser; yarn size:check')).stdout;
message(`@sentry/browser bundle gzip'ed minified size: *(${result.split('\n')[3]}) (${result.split('\n')[4]})*`);
});
};
hasJsfmFile =f;
}
return f;
});
}
if (!hasJsfmFile && danger.git.modified_files) {
danger.git.modified_files.some(file => {
var f = checkJsfmFile(file);
if(f){
hasJsfmFile =f;
}
return f;
});
}
if (!hasJsfmFile && danger.git.deleted_files) {
danger.git.deleted_files.some(file => {
var f = checkJsfmFile(file);
if(f){
hasJsfmFile =f;
}
return f;
});
}
console.log('-----------------------------hasJsfmFile-----------------------------:'+hasJsfmFile);
if(hasJsfmFile){
var runTestCmd='source ~/.bash_profile; '
+ 'npm run build && npm run test'
var runSuccess = shell.exec(runTestCmd,{ async: false, timeout: 8 * 60 * 1000, maxBuffer: 200 * 1024 * 1024 }).code == 0;
if(!runSuccess){
fail("jsfm run test failed!");
}
}else{
import { danger, fail, warn } from 'danger';
const pr = danger.github.pr;
const modified = danger.git.modified_files;
const bodyAndTitle = (pr.body + pr.title).toLowerCase();
const trivialPR = bodyAndTitle.includes('#trivial');
const filesOnly = file => file.endsWith('/');
const touchedFiles = modified
.concat(danger.git.created_files)
.filter(p => filesOnly(p));
//No empty assignee
if (!pr.assignee && pr.user.login !== 'jwu910') {
const method = pr.title.includes('WIP') ? warn : fail;
method(
'This pull request needs an assignee, and optionally include any reviewers.',
);
}
//No empty descriptions
if (pr.body.length < 10) {
fail('This pull request needs a description.');
}
return type_jsfm_test;
} else if(file.match(/test\/scripts\/.+\.js/) || file.match(/test\/pages\/.+\.vue/)){
return type_ui_test
}else{
return type_unknown
}
}
function checkIosFile(file){
var type = getFileType(file);
return type == type_ios_sdk || type == type_ios_test || type == type_jsfm;
}
var hasIosFile = false;
if (!hasIosFile && danger.git.created_files) {
danger.git.created_files.some(file => {
var f = checkIosFile(file);
if(f){
hasIosFile =f;
}
return f;
});
}
if (!hasIosFile && danger.git.modified_files) {
danger.git.modified_files.some(file => {
var f = checkIosFile(file);
if(f){
hasIosFile =f;
}
return f;
});