Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: update danger to do more stuff #1200

Merged
merged 1 commit into from Aug 19, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
58 changes: 51 additions & 7 deletions dangerfile.ts
@@ -1,13 +1,57 @@
import { danger } from 'danger';
import { parse } from 'path';
import { danger, warn } 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');
}
const createOrAddLabelSafely = async (name: string, color: string) => {
try {
await danger.github.utils.createOrAddLabel({
name,
color,
description: '',
});
} catch (error) {
console.warn(error);
warn(`Was unable to create or add label "${name}"`);
}
};

const labelBasedOnRules = async () => {
const affectedRules = [
...danger.git.created_files,
...danger.git.modified_files,
...danger.git.deleted_files,
]
.filter(filename => {
const { dir, ext } = parse(filename);

return dir === 'src/rules' && ext === '.ts';
})
.map(filename => parse(filename).name);

await Promise.all(
affectedRules.map(rule =>
createOrAddLabelSafely(`rule: ${rule}`, '#7d3abc'),
),
);
};

const labelBasedOnCommits = async () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice! maybe check for BREAKING CHANGE as well and add some label for breaking changes?

const commits = danger.github.commits.map(commits => commits.commit.message);

if (commits.some(commit => commit.startsWith('fix'))) {
await createOrAddLabelSafely('bug', '#ee0701');
}

if (commits.some(commit => commit.startsWith('feat'))) {
await createOrAddLabelSafely('enhancement', '#84b6eb');
}
};

Promise.all([labelBasedOnRules(), labelBasedOnCommits()]).catch(error => {
console.error(error);
fail(`Something went very wrong: ${error}`);
});