How to use the danger.markdown 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 / metaphysics / dangerfile.js View on Github external
// Move all JS files towards using flow
const changedFiles = danger.git.created_files.concat(danger.git.modified_files);
const unFlowedFiles = changedFiles.filter(path => !path.startsWith('test/') && path.endsWith('js'))
  .filter(filepath => {
    const content = fs.readFileSync(filepath);
    return content.includes('@flow');
  });

if (unFlowedFiles.length > 0) {
  const flowLinks = [
    ' * [Main Site](https://flowtype.org)',
    ' * [Types](https://flowtype.org/docs/quick-reference.html#primitives)',
    ' * [What is Flow?](https://code.facebook.com/posts/1505962329687926/flow-a-new-static-type-checker-for-javascript/)', // eslint-disable-line
    ' * [Danger\'s flow glossary](https://github.com/danger/danger-js/blob/master/docs/js_glossary.md)',
  ];
  markdown('--- \n\n If you are new to Flow, here are some resources: \n\n' + flowLinks.join('\n'));
  warn(`These new JS files do not have Flow enabled: ${unFlowedFiles.join(', ')}`);
}

// Request a CHANGELOG entry, but allow a PR to say it doesn't neeed one
const hasChangelog = changedFiles.includes('changelog.md');
const declaredTrivial = danger.pr.title.indexOf('trivial') !== -1;

if (!hasChangelog && !declaredTrivial) {
  fail('Please add a changelog entry noting your changes.');
}

// Politely ask for their name on the entry too
if (hasChangelog) {
  const changelogDiff = danger.git.diffForFile('changelog.md');
  const contributorName = danger.github.pr.user.login;
  if (changelogDiff && changelogDiff.indexOf(contributorName) === -1) {
github artsy / emission / dangerfile.ts View on Github external
// Yes, this is a bit lossy, we run the linter twice now, but its still a short amount of time
// Perhaps we could indicate that tslint failed somehow the first time?
if (fs.existsSync("tslint-errors.json")) {
  const tslintErrors = JSON.parse(fs.readFileSync("tslint-errors.json", "utf8")) as any[]
  if (tslintErrors.length) {
    const errors = tslintErrors.map(error => {
      const format = error.ruleSeverity === "ERROR" ? ":no_entry_sign:" : ":warning:"
      const linkToFile = danger.github.utils.fileLinks([error.name])
      return `* ${format} ${linkToFile} - ${error.ruleName} -${error.failure}`
    })
    const tslintMarkdown = `
  ## TSLint Issues:

  ${errors.join("\n")}
  `
    markdown(tslintMarkdown)
  }
}

// Show Jest fails in the PR
import jest from "danger-plugin-jest"
if (fs.existsSync("test-results.json")) {
  jest({ testResultsJsonPath: "test-results.json" })
}

// Raise when native code changes are made, but the package.json does not
// have a bump for the native code version
//
const hasNativeCodeChanges = modified.find(p => p.includes("Pod/Classes") && p.includes(".h"))
const hasPackageJSONChanges = modified.find(p => p === "package.json")
if (hasNativeCodeChanges && !hasPackageJSONChanges && !acceptedNoNativeChanges) {
  fail(
github mui-org / material-ui / dangerfile.js View on Github external
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) {
    const importantChanges = results
      .filter(createComparisonFilter(parsedSizeChangeThreshold, gzipSizeChangeThreshold))
      .filter(isPackageComparison)
      .map(generateEmphasizedChange);

    // have to guard against empty strings
    if (importantChanges.length > 0) {
      markdown(importantChanges.join('\n'));
    }

    const detailsTable = generateMDTable(
      [
        { label: 'bundle' },
        { label: 'Size Change', align: 'right' },
        { label: 'Size', align: 'right' },
        { label: 'Gzip Change', align: 'right' },
        { label: 'Gzip', align: 'right' },
      ],
      results
        .map(([bundleId, size]) => [computeBundleLabel(bundleId), size])
        // orderBy(|parsedDiff| DESC, |gzipDiff| DESC, name ASC)
        .sort(([labelA, statsA], [labelB, statsB]) => {
          const compareParsedDiff =
            Math.abs(statsB.parsed.absoluteDiff) - Math.abs(statsA.parsed.absoluteDiff);
github contiamo / operational-scripts / dangerfile.ts View on Github external
// This process should always fail, so needs the `|| true` so it won't raise.
child_process.execSync(`npm run lint -- -- --format json --out tslint-errors.json || true`);

if (fs.existsSync("tslint-errors.json")) {
  const tslintErrors = JSON.parse(fs.readFileSync("tslint-errors.json", "utf8")) as any[];
  if (tslintErrors.length) {
    const errors = tslintErrors.map(error => {
      const format = error.ruleSeverity === "ERROR" ? ":no_entry_sign:" : ":warning:";
      const linkToFile = danger.github.utils.fileLinks([error.name]);
      return `* ${format} ${linkToFile} - ${error.ruleName} - ${error.failure}`;
    });
    const tslintMarkdown = `
  ## TSLint Issues:
  ${errors.join("\n")}
  `;
    markdown(tslintMarkdown);
  }
}
github StoDevX / AAO-React-Native / dangerfile.js View on Github external
let buildStatus = readLogFile('./logs/build-status')

	if (buildStatus !== '0') {
		// returning early here because if the build fails, there's nothing to analyze
		fastlaneBuildLogTail(logFile, 'iOS Build Failed')
		return
	}

	// tee the "fastlane" output to a log, and run the analysis script
	// to report back the longest compilation units
	let analysisFile = readFile('./logs/analysis')
	if (!analysisFile.trim().length) {
		return
	}

	markdown(
		h.h2('iOS Report'),
		h.details(
			h.summary('Analysis of slow build times (>20s)'),
			m.code({}, analysisFile),
		),
	)
}
github opengaming / osgameclones / dangerfile.js View on Github external
const {danger, markdown, message, warn} = require('danger')
const http = require('http')
const url = require('url')
const yaml = require('js-yaml')
const fs = require('fs')

markdown("Hey there! Thanks for contributing a PR to osgameclones! 🎉")

let namesAdded = []
let namesChanged = []
let namesRemoved = []

const isGame = game => /^games\/\w+\.yaml$/.test(game)

let unknownLanguageDetected = false
const knownLanguages = [
  'ActionScript',
  'Ada',
  'AngelScript',
  'Assembly',
  'Blitz BASIC',
  'C',
  'C#',
github tinacms / tinacms / dangerfile.ts View on Github external
function listTouchedPackages(modifiedPackages: TinaPackage[]) {
  if (!modifiedPackages.length) return
  markdown(`### Modified Packages

The following packages were modified by this pull request:

* ${modifiedPackages
    .map(({ packageJson }) => `\`${packageJson.name}\``)
    .join('\n* ')}`)
}
github StoDevX / AAO-React-Native / dangerfile.js View on Github external
function xcodeproj() {
	let pbxprojChanged = danger.git.modified_files.find(filepath =>
		filepath.endsWith('project.pbxproj'),
	)

	if (!pbxprojChanged) {
		return
	}

	markdown(
		'The Xcode project file changed. Maintainers, double-check the changes!',
	)
}
github facebook / react / dangerfile.js View on Github external
allTables.push(`\n## ${name}`);
      allTables.push(generateMDTable(mdHeaders, mdRows));
    }

    const summary = `
  <details>
  <summary>Details of bundled changes.</summary>

  <p>Comparing: ${baseCommit}...${danger.github.pr.head.sha}</p>


  ${allTables.join('\n')}

  </details>
  `;
    markdown(summary);
  } else {
    markdown('No significant bundle size changes to report.');
  }
})();