Skip to content

Commit

Permalink
chore(danger): check Smoke test branch & unmodified tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JackuB committed Aug 25, 2020
1 parent 32e143c commit db9ea14
Showing 1 changed file with 45 additions and 7 deletions.
52 changes: 45 additions & 7 deletions dangerfile.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
const {danger, warn, fail, message} = require('danger');
const { danger, warn, fail, message } = require('danger');

const MAX_COMMIT_MESSAGE_LENGTH = 72;
const SMOKE_TEST_BRANCH = 'feat/smoke-test';
const SMOKE_TEST_WORKFLOW_FILE_PATH = '.github/workflows/smoke-tests.yml';

if (danger.github && danger.github.pr) {
const commitizenRegex = /^(feat|fix|chore|test|docs|perf|refactor|revert)(\(.*\))?:(.+)$/;
const ghCommits = danger.github.commits;
let willTriggerRelease = false;
for (const {commit} of ghCommits) {
const {message, url} = commit;
for (const { commit } of ghCommits) {
const { message, url } = commit;
const firstLine = message.split('\n')[0];

if (message.startsWith('feat') || message.startsWith('fix')) {
Expand All @@ -14,15 +18,49 @@ if (danger.github && danger.github.pr) {

const regexMatch = commitizenRegex.exec(firstLine);
if (!regexMatch) {
fail(`Commit ["${firstLine}"](${url}) is not a valid commitizen message. See [Contributing page](https://github.com/snyk/snyk/blob/master/.github/CONTRIBUTING.md#commit-types) with required commit message format.`);
fail(
`Commit ["${firstLine}"](${url}) is not a valid commitizen message. See [Contributing page](https://github.com/snyk/snyk/blob/master/.github/CONTRIBUTING.md#commit-types) with required commit message format.`,
);
}

if (firstLine.length >= 72) {
warn(`Your commit message ["${firstLine}"](${url}) is too long. Keep first line of your commit under 72 characters.`);
if (firstLine.length >= MAX_COMMIT_MESSAGE_LENGTH) {
warn(
`Your commit message ["${firstLine}"](${url}) is too long. Keep first line of your commit under ${MAX_COMMIT_MESSAGE_LENGTH} characters.`,
);
}
}

if (!willTriggerRelease) {
message('This PR will not trigger a new version. It doesn\'t include any commit message with `feat` or `fix`.');
message(
"This PR will not trigger a new version. It doesn't include any commit message with `feat` or `fix`.",
);
}

// Forgotten tests check
const modifiedTest = danger.git.modified_files.some((f) =>
f.startsWith('test/'),
);
const modifiedSrc = danger.git.modified_files.some((f) =>
f.startsWith('src/'),
);

if (modifiedSrc && !modifiedTest) {
// TODO: let's be careful about wording here. Maybe including Contributing guidelines and project goals document here
warn(
"You've modified files in src/ directory, but haven't updated anything in test folder. Is there something that could be tested?",
);
}

// Smoke test modification check
const modifiedSmokeTest =
danger.git.modified_files.some((f) => f.startsWith('test/smoke/')) ||
danger.git.modified_files.includes(SMOKE_TEST_WORKFLOW_FILE_PATH);

const isOnSmokeTestBranch = danger.github.pr.head.ref === SMOKE_TEST_BRANCH;

if (modifiedSmokeTest && !isOnSmokeTestBranch) {
message(
`You are modifying something in test/smoke directory, yet you are not on the branch ${SMOKE_TEST_BRANCH}. You can rename your branch to ${SMOKE_TEST_BRANCH} and Smoke tests will trigger for this PR.`,
);
}
}

0 comments on commit db9ea14

Please sign in to comment.