How to use the danger.warn 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 Automattic / jetpack / dangerfile.js View on Github external
);
if ( notVerifiedCommits.length > 0 ) {
	warn( '`pre-commit` hook was skipped for one or more commits' );
}

// Use labels please!
const ghLabels = github.issue.labels;
if ( ! ghLabels.find( l => l.name.toLowerCase().includes( '[status]' ) ) ) {
	warn(
		'The PR is missing at least one `[Status]` label. Suggestions: `[Status] In Progress`, `[Status] Needs Review`'
	);
}

// Test instructions
if ( ! pr.body.includes( 'Testing instructions' ) ) {
	warn( '"Testing instructions" are missing for this PR. Please add some' );
}

// Proposed changelog entry
if ( ! pr.body.includes( 'Proposed changelog entry' ) ) {
	warn(
		'"Proposed changelog entry" is missing for this PR. Please include any meaningful changes'
	);
}

// Check if newly added .php files were added to phpcs linter whitelist
if ( newFiles.length > 0 ) {
	const newPHPFiles = newFiles.filter(
		fileName => fileName.includes( '.php' ) && ! fileName.includes( 'tests/php' )
	);

	const notWhitelistedFiles = [];
github contiamo / operational-scripts / dangerfile.ts View on Github external
if (packageChanged && wrongLockfileChanged) {
  fail(
    "This PR contains `package-lock.json`, but we expect a `yarn.lock` instead as yarn is the preferred package manager for this project. We should not have to maintain two lockfiles.",
  );
}

// No PR is too small to warrant a paragraph or two of summary
if (pr.body.length === 0) {
  fail("Please add a description to your PR.");
}

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

if (danger.github.pr.additions + danger.github.pr.deletions > bigPRThreshold) {
  warn(":exclamation: Big PR");
}

// Always ensure we assign someone, so that our Slackbot can do its work correctly
if (pr.assignee === null) {
  fail("Please assign someone to merge this PR, and optionally include people who should review.");
}

// Show TSLint errors inline
// 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?
// 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) {
github danreeves / react-tether / dangerfile.js View on Github external
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!');
}

schedule(istanbulCoverage());
github openkfw / TruBudget / dangerfile.js View on Github external
normal
  };
}

// When there are app-changes and it's not a PR marked as trivial, expect there to be CHANGELOG changes.
if (
  (frontendChanges ||
    apiSources.edited ||
    blockchainSources.edited ||
    frontendRootSources.edited ||
    provisioningSources.edited ||
    e2eTestSources.edited) &&
  !trivialPR &&
  !changelogChanges
) {
  warn("No CHANGELOG added.");
}

// If there are changes in the UI (except language files)
// and PR is not marked as trivial, expect there to be E2E-test updates
if (
  (frontendRootSources.edited || frontendPageSources.edited) &&
  !e2eTestSources.edited &&
  !trivialPR
) {
  warn(
    "There were changes in the frontend, but no E2E-test was added or modified!"
  );
}

// Async part to check for changes in files
(async function() {
github MCS-Lite / mcs-lite / dangerfile.js View on Github external
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.',
  );
}

// Warn when there is a big PR
const bigPRThreshold = 500;
if (danger.github.pr.additions + danger.github.pr.deletions > bigPRThreshold) {
  warn(':exclamation: Big PR');
}
github Automattic / vip-go-mu-plugins-built / jetpack / dangerfile.js View on Github external
const newPHPFiles = danger.git.created_files.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' );
		warn(
			'Consider adding 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.`
github styled-components / styled-components / dangerfile.js View on Github external
}
});

// Fail if there are app changes without a CHANGELOG
if (!danger.git.modified_files.includes('CHANGELOG.md') && hasAppChanges) {
  const changelogLink =
    'https://github.com/styled-components/styled-components/blob/master/CHANGELOG.md';
  fail(
    `Please include a CHANGELOG entry. You can find it at <a href="${changelogLink}">CHANGELOG.md</a>`
  );
}

// Warn if there are library changes, but not tests (excluding vendor)
const libraryOnlyFiles = jsModifiedFiles.filter(file =&gt; !vendorModifiedFiles.includes(file));
if (libraryOnlyFiles.length &gt; 0 &amp;&amp; !hasTestChanges) {
  warn(
    "There are library changes, but not tests. That's OK as long as you're refactoring existing code"
  );
}

// Warn if StyledComponent.js was edited but not StyledNativeComponent.js or viceversa
const hasStyledChanges =
  danger.git.modified_files.find(path =&gt; path.endsWith('StyledComponent.js')) !== null;
const hasNativeStyledChanges =
  danger.git.modified_files.find(path =&gt; path.endsWith('StyledNativeComponent.js')) !== null;
if (hasStyledChanges &amp;&amp; !hasNativeStyledChanges) {
  warn(
    "A change was made in StyledComponent.js that wasn't made in StyledNativeComponent.js or viceversa."
  );
}

// Changes to these files may need SemVer bumps
github styled-components / styled-components / dangerfile.js View on Github external
semverBumpFiles.forEach(file => {
  if (jsModifiedFiles.includes(file)) {
    warn('Changes to #{file} might be SemVer major changes.');
  }
});
github opengaming / osgameclones / dangerfile.js View on Github external
const checkFrameworkKnown = game => {
  if (!game.framework) return
  const unknownFrameworks = game.framework.filter(l => !knownFrameworks.includes(l))
  if (unknownFrameworks.length) {
    warn(
      `🌇 ${game.name} contains "${unknownFrameworks}" as framework, which is not known by us. ` +
      `Please check for spelling errors.`
    )
    unknownFrameworkDetected = true
  }
}
github thibaudcolas / draftjs-conductor / dangerfile.js View on Github external
"This PR appears to be a work in progress, and may not be ready to be merged yet.";
    warn(`${title} - <i>${idea}</i>`);
  }
}

if (hasLibChanges &amp;&amp; !hasREADMEChanges) {
  warn("This pull request updates the library. Should the docs be updated?");
}

const hasPackageChanges = danger.git.modified_files.includes("package.json");
const hasLockfileChanges = danger.git.modified_files.includes(
  "package-lock.json",
);

if (hasPackageChanges &amp;&amp; !hasLockfileChanges) {
  warn("There are package.json changes with no corresponding lockfile changes");
}

const linkDep = (dep) =&gt;
  danger.utils.href(`https://www.npmjs.com/package/${dep}`, dep);

schedule(async () =&gt; {
  const packageDiff = await danger.git.JSONDiffForFile("package.json");

  if (packageDiff.dependencies) {
    const added = packageDiff.dependencies.added;
    const removed = packageDiff.dependencies.removed;

    if (added.length) {
      const deps = danger.utils.sentence(added.map((d) =&gt; linkDep(d)));
      message(`Adding new dependencies: ${deps}`);
    }