Skip to content

Commit

Permalink
fix: skipping default merge commit messages
Browse files Browse the repository at this point in the history
Currently, merge commits are validated for whether they contain a Rally story,
defect, or task. For scenarios where the branch name contains a Rally ticket
identifier, when that branch is merged, the branch name containing the Rally
ticket identifier will show up in the merge commit message and fail
validation as it may be missing a #.  This changeset will omit merge commits
with the default merge commit message from being validated for Rally ticket
identifiers.
  • Loading branch information
tashrafy authored and BearAlliance committed May 12, 2020
1 parent 43499f2 commit a7e631a
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 3 deletions.
43 changes: 43 additions & 0 deletions src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,29 @@ describe('rally', () => {
expect(global.fail)
.toHaveBeenCalledWith(`The following are referenced in the commit body, but are not prefixed by \`#\`.
- US1234567
Tools like [standard-version](https://www.npmjs.com/package/standard-version) rely on this marker to generate links to the ticket in the \`CHANGELOG\``);
});
it('fails with a message and skips merge commits', () => {
global.danger = {
bitbucket_server: {
pr: { title: 'My Test Title', description: 'some description' }
},
git: {
commits: [
{
message:
'Merge pull request #1234 in BearAlliance/danger-plugin-rally from ~USER/danger-plugin-rally:feature/US1234567 to staging\n* commit h1a2s3h'
},
{
message: 'chore: do something\ncloses US1234567'
}
]
}
};
rally({ requirePound: true });
expect(global.fail)
.toHaveBeenCalledWith(`The following are referenced in the commit body, but are not prefixed by \`#\`.
- US1234567
Tools like [standard-version](https://www.npmjs.com/package/standard-version) rely on this marker to generate links to the ticket in the \`CHANGELOG\``);
});
});
Expand All @@ -110,6 +133,26 @@ Tools like [standard-version](https://www.npmjs.com/package/standard-version) re
rally({ requirePound: true });
expect(global.fail).not.toHaveBeenCalled();
});
it('does not fail and skips merge commits', () => {
global.danger = {
bitbucket_server: {
pr: { title: 'My Test Title', description: 'some description' }
},
git: {
commits: [
{
message:
'Merge pull request #1234 in BearAlliance/danger-plugin-rally from ~USER/danger-plugin-rally:feature/US1234567 to staging\n* commit h1a2s3h'
},
{
message: 'chore: do something\ncloses #US1234567'
}
]
}
};
rally({ requirePound: true });
expect(global.fail).not.toHaveBeenCalled();
});
});
});
});
Expand Down
9 changes: 6 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export declare function markdown(message: string): void;
const rallyStoryPattern = /US\d{7}/g;
const rallyDefectPattern = /DE\d{6}/g;
const rallyTaskPattern = /TA\d{7}/g;
const mergeCommitPattern = /^Merge (pull request|branch)/;

export interface RallyPluginConfig {
domain?: string;
Expand Down Expand Up @@ -88,16 +89,18 @@ export default function rally(config?: RallyPluginConfig) {
const bbs = danger.bitbucket_server;
const prDescription = bbs.pr.description;
const prTitle = bbs.pr.title;

const commitMessages = danger.git.commits
const nonMergeCommits = danger.git.commits.filter(
commit => !commit.message.match(mergeCommitPattern)
);
const commitMessages = nonMergeCommits
.map(commit => commit.message)
.join('\n');

if (requirePound) {
checkForPound(commitMessages);
}
if (bodyOnly) {
checkBody(danger.git.commits.map(commit => commit.message));
checkBody(nonMergeCommits.map(commit => commit.message));
}

const storyNumbers = (prDescription + prTitle + commitMessages).match(
Expand Down

0 comments on commit a7e631a

Please sign in to comment.