Skip to content

Commit

Permalink
feat: parse commit title even if it is a squash
Browse files Browse the repository at this point in the history
  • Loading branch information
darioblanco committed Apr 13, 2020
1 parent f9eac64 commit 016c596
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
2 changes: 1 addition & 1 deletion dist/run.js

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions src/lib/commits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,12 @@ export async function commitParser(
const majorMatch = majorRegExp.exec(message);
if (majorMatch) nextVersionType = VersionType.major;

// Detect if commit is a Github squash. In that case, ignore commit title and convert
// in multiple single line commits
// Detect if commit is a Github squash. In that case, convert body
// in multiple single line commits and parse
if (/\* .*\n/.test(message)) {
const messageLines = message.split('* ');
// Categorize all commits except first one
messageLines
.slice(1)
.forEach(messageLine =>
categorizeCommit({
username,
Expand Down
5 changes: 4 additions & 1 deletion test/lib/__snapshots__/commits.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ exports[`commit render gh squashed commits with scope, PRs and tasks for http://
"- Set values for staging and production - [62ec8ea7](https://commiturl)([@darioblanco](https://authorurl))
**:zap: Features**
- Main commit of my PR (#1716) - [62ec8ea7](https://commiturl)([@darioblanco](https://authorurl))
- Set login endpoint controller - [62ec8ea7](https://commiturl)([@darioblanco](https://authorurl))
- Set expiration of the cookie to the amount of time of the token - [62ec8ea7](https://commiturl)([@darioblanco](https://authorurl))
Expand All @@ -64,6 +65,7 @@ exports[`commit render gh squashed commits with scope, PRs and tasks for undefin
"- Set values for staging and production - [62ec8ea7](https://commiturl)([@darioblanco](https://authorurl))
**:zap: Features**
- Main commit of my PR (#1716) - [62ec8ea7](https://commiturl)([@darioblanco](https://authorurl))
- Set login endpoint controller - [62ec8ea7](https://commiturl)([@darioblanco](https://authorurl))
- Set expiration of the cookie to the amount of time of the token - [62ec8ea7](https://commiturl)([@darioblanco](https://authorurl))
Expand All @@ -79,6 +81,7 @@ exports[`commit render gh squashed commits with scope, PRs and tasks for undefin
`;

exports[`commit render github squashed commits without scope, PRs and tasks 1`] = `
"- Set login endpoint controller - [62ec8ea7](https://commiturl)([@darioblanco](https://authorurl))
"- Title of my PR - [62ec8ea7](https://commiturl)([@darioblanco](https://authorurl))
- Set login endpoint controller - [62ec8ea7](https://commiturl)([@darioblanco](https://authorurl))
- Add integration test for login endpoint - [62ec8ea7](https://commiturl)([@darioblanco](https://authorurl))"
`;
11 changes: 7 additions & 4 deletions test/lib/commits.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ describe('commit', () => {
[undefined, 'http://my-task-url'].forEach(taskBaseUrl =>
test(`render gh squashed commits with scope, PRs and tasks for ${taskBaseUrl}`, async () => {
const commitMessage =
'JIRA-2772 Title of my PR (#1716)\n\n' +
'feat(auth): main commit of my PR (#1716)\n\n' +
'* feat(auth): set login endpoint controller\n\n' +
'* test(auth): add integration test for login endpoint #MAJOR\n\n' +
'* fix(auth): set secure and http only options\n\n' +
Expand All @@ -150,7 +150,8 @@ describe('commit', () => {
'* Address comment from PR\n\n' +
'This is the body of the previous commit\n\n' +
'* feat(auth): set expiration of the cookie to the amount of time of the token\n\n' +
'* fix(auth): remove joi validation since it does not accept localhost';
'* fix(auth): remove joi validation since it does not accept localhost\n\n' +
'Closes: JIRA-2772';
const compareSquashedCommitsResponse = {
data: {
commits: [
Expand Down Expand Up @@ -178,7 +179,7 @@ describe('commit', () => {
JSON.stringify(
commitMessage
.split('* ')
.slice(2)
.slice(1)
.map(() => sha),
), // 6 commits
);
Expand Down Expand Up @@ -219,7 +220,9 @@ describe('commit', () => {
);
expect(setOutput).toBeCalledWith(
'changes',
'["62ec8ea713fdf14e4abaef3d7d5138194dec49ce","62ec8ea713fdf14e4abaef3d7d5138194dec49ce"]',
'["62ec8ea713fdf14e4abaef3d7d5138194dec49ce",' +
'"62ec8ea713fdf14e4abaef3d7d5138194dec49ce",' +
'"62ec8ea713fdf14e4abaef3d7d5138194dec49ce"]',
);
expect(setOutput).toBeCalledWith('tasks', '[]');
expect(setOutput).toBeCalledWith('pull_requests', '[]');
Expand Down

0 comments on commit 016c596

Please sign in to comment.