How to use the danger.danger.github 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.

github mui-org / material-ui / dangerfile.js View on Github external
async function run() {
  // Use git locally to grab the commit which represents the place
  // where the branches differ
  const upstreamRepo = danger.github.pr.base.repo.full_name;
  const upstreamRef = danger.github.pr.base.ref;
  try {
    await git(`remote add ${UPSTREAM_REMOTE} https://github.com/${upstreamRepo}.git`);
  } catch (err) {
    // ignore if it already exist for local testing
  }
  await git(`fetch ${UPSTREAM_REMOTE}`);
  const mergeBaseCommit = await git(`merge-base HEAD ${UPSTREAM_REMOTE}/${upstreamRef}`);

  const commitRange = `${mergeBaseCommit}...${danger.github.pr.head.sha}`;

  const comparison = await loadComparison(mergeBaseCommit, upstreamRef);
  const results = Object.entries(comparison.bundles);
  const anyResultsChanges = results.filter(createComparisonFilter(1, 1));

  if (anyResultsChanges.length > 0) {
github cerner / terra-clinical / dangerfile.js View on Github external
const modifiedSrcFiles = danger.git.modified_files.filter((filePath) => {
  const srcFilePattern = /^packages\/([a-z-])*\/src/i;
  return srcFilePattern.test(filePath);
});

const hasCHANGELOGChanges = modifiedChangelog.length > 0 || newChangelog.length > 0;
const hasModifiedSrcFiles = modifiedSrcFiles.length > 0;

// Fail if there are src code changes without a CHANGELOG update
if (hasModifiedSrcFiles && !hasCHANGELOGChanges) {
  fail('Please include a CHANGELOG entry with this PR.');
}

// Warn when there is a big PR
const bigPRThreshold = 1000;
if (danger.github.pr.additions + danger.github.pr.deletions > bigPRThreshold) {
  warn(':exclamation: Big PR. Consider breaking this into smaller PRs if applicaple');
}
github danreeves / react-tether / dangerfile.js View on Github external
import { warn, message, schedule, danger } from 'danger';
import { istanbulCoverage } from 'danger-plugin-istanbul-coverage';

const modified = danger.git.modified_files;
const modifiedSrc = modified.filter(p => p.includes('src/'));
const changelogChanges = modified.find(f => f === 'CHANGELOG.md');
const testChanges = modified.filter(p => p.includes('tests/'));

message(
  `Hey @${
    danger.github.pr.user.login
  }, thanks for submitting a pull request! :smile_cat:`
);

// Updates to the source require changelog updates
if (modifiedSrc.length > 1 && !changelogChanges) {
  warn(`You changed a source file but didn't add to the changelog`);
}

// Pull requests should have descriptions
if (danger.github.pr.body.length === 0) {
  warn('Please add a description to your PR');
}

// You added tests :tada:
if (testChanges.length > 0) {
  message(':tada: Thanks for working on tests!');
github twilio-labs / open-pixel-art / dangerfile.js View on Github external
async function evaluatePixelChanges(jsonPatch) {
  const gitHubUsername = danger.github.pr.user.login;
  if (jsonPatch.diff.length === 1) {
    // Only one pixel has been modified

    const linePatch = jsonPatch.diff[0];
    if (linePatch.op === 'add') {
      // a new pixel has been added

      if (isValidNewPixelSubmission(linePatch.value, gitHubUsername)) {
        return true;
      }
    } else if (linePatch.op === 'remove') {
      // a pixel has been removed

      fail(
        `I'm sorry but you can't remove a pixel that someone else contributed`
      );
github contiamo / operational-ui / dangerfile.ts View on Github external
import * as child_process from "child_process"
import { danger, GitHubPRDSL, markdown, message, warn } from "danger"
import jest from "danger-plugin-jest"
import * as fs from "fs"
import { includes } from "lodash"

// Setup
const pr = danger.github.pr
const modified = danger.git.modified_files
const added = danger.git.created_files

const packageChanged = includes(modified, "package.json")
const wrongLockfileChanged = includes([...modified, ...added], "package-lock.json")

const titlePrefixes = ["**Fix:**", "**Feature:**", "**Breaking:**"]
const isPrPrefixed = (title: GitHubPRDSL["title"]) => titlePrefixes.some(prefix => title.startsWith(prefix))

// Warn when there is a big PR
const bigPRThreshold = 500

message(`Here's [the demo](https://deploy-preview-${pr.number}--operational-ui.netlify.com/) for testing!`)

if (pr.title.includes("WIP")) {
  fail("This PR is a work in progress and should not be reviewed or merged _yet_.")
github MCS-Lite / mcs-lite / dangerfile.js View on Github external
// @flow
import { danger, fail, warn } from 'danger';

const allChanges = [].concat(
  danger.git.created_files,
  danger.git.modified_files,
  danger.git.deleted_files,
);

// Warn if there is no description.
if (!danger.github.pr.body.length) {
  warn('Please add a description to your PR.');
}

// Warn if there is no labels.
if (!danger.github.issue.labels.length) {
  warn('Please add a label to your PR.');
}

// Warn if there is no one assign.
const someoneAssigned = danger.github.pr.assignee;
if (someoneAssigned === null) {
  warn(
    'Please assign someone to merge this PR, and optionally include people who should review.',
  );
}
github gatsbyjs / gatsby / peril / rules / merge-on-green.ts View on Github external
export const mergeOnGreen = async () => {
  try {
    if (danger.github.action === `completed` && danger.github.check_suite) {
      // this is for check_suite.completed

      // search returns first 100 results, we are not handling pagination right now
      // because it's unlikely to get more 100 results for given sha
      const results = await danger.github.api.search.issues({
        q: `${danger.github.check_suite.head_sha} is:open repo:${danger.github.repository.owner.login}/${danger.github.repository.name}`,
      })

      let i = 0
      while (i < results.data.items.length) {
        const pr = results.data.items[i]
        i++
        await checkPRConditionsAndMerge({
          number: pr.number,
          owner: danger.github.repository.owner.login,
          repo: danger.github.repository.name,
github mmiszy / react-with-observable / dangerfile.ts View on Github external
import { danger, warn } from 'danger';
var fs = require('fs');
var path = require('path');

// No PR is too small to include a description of why you made a change
if (danger.github.pr.body.length < 10) {
  warn('Please include a description of your PR changes.');
}

// Request changes to src also include changes to tests.
const allFiles = danger.git.modified_files.concat(danger.git.created_files);
const hasAppChanges = allFiles.some(p => p.includes('.tsx'));
const hasTestChanges = allFiles.some(p => p.includes('.spec.tsx'));

const modifiedSpecFiles = danger.git.modified_files.filter(function(filePath) {
  return filePath.match(/\.spec\.(js|jsx|ts|tsx)$/gi);
});

const testFilesIncludeExclusion = modifiedSpecFiles.reduce(
  function(acc, value) {
    var content = fs.readFileSync(value).toString();
    var invalid = content.includes('it.only') || content.includes('describe.only');
github gatsbyjs / gatsby / peril / rules / merge-on-green.ts View on Github external
// this is for status.success

      // search returns first 100 results, we are not handling pagination right now
      // because it's unlikely to get more 100 results for given sha
      const results = await danger.github.api.search.issues({
        q: `${danger.github.commit.sha} is:open repo:${danger.github.repository.owner.login}/${danger.github.repository.name}`,
      })

      let i = 0
      while (i < results.data.items.length) {
        const pr = results.data.items[i]
        i++
        await checkPRConditionsAndMerge({
          number: pr.number,
          owner: danger.github.repository.owner.login,
          repo: danger.github.repository.name,
        })
      }
    } else if (
      danger.github.action === `submitted` &&
      danger.github.pull_request
    ) {
      // this is for pull_request_review.submitted
      await checkPRConditionsAndMerge({
        number: danger.github.pull_request.number,
        repo: danger.github.pull_request.base.repo.name,
        owner: danger.github.pull_request.base.repo.owner.login,
      })
    } else {
      // this is for pull_request.labeled
      await checkPRConditionsAndMerge({
        number: danger.github.pr.number,
github artsy / metaphysics / peril / upstreamSchemaValidator.ts View on Github external
}

  // Wait till we know we have to do work before actually importing helpers
  const {
    downloadSchemaFromURL,
    getBreakingChanges,
  } = await import("./schemaValidatorUtils")

  // This is a separate set of the endpoints with breaking changes
  const servicesWithBreakingChanges: EndPoints = {}

  // Loop through each API which changed, grab their new schema from
  // the metaphysics repo then compare it to their API's schema
  for (const serviceName of servicesWhichAreChangedInThisPR) {
    const service = serviceMap[serviceName]
    const localSchema = await danger.github.utils.fileContents(
      service.localSchemaPath
    )

    const endpoint = isProductionDeployPR ? service.production : service.staging
    const upstreamSchema = await downloadSchemaFromURL(endpoint)

    const breakingChanges = await getBreakingChanges(
      localSchema,
      upstreamSchema
    )

    // Create a new copy of the service, with the breaking changes added
    if (breakingChanges.length) {
      servicesWithBreakingChanges[serviceName] = {
        ...service,
        breakingChanges,