How to use the danger.danger.git function in danger

To help you get started, we’ve selected a few danger examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github artsy / detect-responsive-traits / dangerfile.ts View on Github external
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.")
}
github Marwan01 / food-converter / node_modules / react-native / bots / dangerfile.js View on Github external
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 &amp;&amp;
  danger.github.pr.body.toLowerCase().includes('## test plan');
if (!includesTestPlan) {
  const title = ':clipboard: Missing Test Plan';
  const idea =
    'Can you add a Test Plan? ' +
github jest-community / eslint-plugin-jest / dangerfile.ts View on Github external
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');
}
github Automattic / jetpack / dangerfile.js View on Github external
/**
 * 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 &lt; 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 =&gt;
	commit.message.includes( '[not verified]' )
);
if ( notVerifiedCommits.length &gt; 0 ) {
	warn( '`pre-commit` hook was skipped for one or more commits' );
}

// Use labels please!
const ghLabels = github.issue.labels;
github danger / peril / api / dangerfile.lite.ts View on Github external
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`.")
}
github artsy / metaphysics / dangerfile.ts View on Github external
export default async () =&gt; {
  // Rule: encourage all new files to be TypeScript
  const jsAppFiles = danger.git.created_files.filter(
    f =&gt; f.startsWith("src/") &amp;&amp; f.endsWith(".js")
  )
  const testFiles = danger.git.created_files
    .concat(danger.git.modified_files)
    .filter(f =&gt; 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")
github getsentry / sentry-javascript / dangerfile.ts View on Github external
}
            },
          });
        });
      }),
    )).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]})*`);
  });
};
github apache / incubator-weex / dangerfile-jsfm.js View on Github external
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{
github jwu910 / check-it-out / dangerfile.js View on Github external
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 =&gt; file.endsWith('/');

const touchedFiles = modified
  .concat(danger.git.created_files)
  .filter(p =&gt; filesOnly(p));

//No empty assignee
if (!pr.assignee &amp;&amp; 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 &lt; 10) {
  fail('This pull request needs a description.');
}
github apache / incubator-weex / dangerfile-ios.js View on Github external
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;
  });