Skip to content

Commit

Permalink
feat: handle multiline bulleted commit messages (#396)
Browse files Browse the repository at this point in the history
  • Loading branch information
bcoe committed Apr 4, 2020
1 parent 56cf69b commit 670d872
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 3 deletions.
9 changes: 9 additions & 0 deletions __snapshots__/indent-commit.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,12 @@ feat: my awesome commit message
* testing one line
* testing second line
`;

exports['indentCommit handles multiple lines of multi-line text 1'] = `
feat: my awesome commit message
* testing one line
this is a second line of text
this is a third line
* testing second line
this is a second line
`;
11 changes: 9 additions & 2 deletions src/util/indent-commit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,18 @@ import {Commit} from '../graphql-to-commits';

export function indentCommit(commit: Commit): string {
const reduced: string[] = [];
let inList = false;
commit.message.split(/\r?\n/).forEach((line, i) => {
if (i !== 0) line = ` ${line}`;
// to show up in CHANGELOG lines must start with '*'.
if (/^\s*\*/.test(line) || i === 0) {
else reduced.push(line);

if (/^\s*\*/.test(line)) {
inList = true;
reduced.push(line);
} else if (/^ +[\w]/.test(line) && inList) {
reduced[reduced.length - 1] = `${reduced[reduced.length - 1]}\n${line}`;
} else {
inList = false;
}
});
return reduced.join('\n');
Expand Down
15 changes: 15 additions & 0 deletions test/util/indent-commit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,19 @@ describe('indentCommit', () => {
})
);
});

it('handles multiple lines of multi-line text', () => {
snapshot(
indentCommit({
message: `feat: my awesome commit message
* testing one line
this is a second line of text
this is a third line
* testing second line
this is a second line`,
sha: 'abc123',
files: [],
})
);
});
});
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
},
"include": [
"src/**/*.ts",
"test/*.ts",
"test/**/*.ts",
"system-test/*.ts"
]
}

0 comments on commit 670d872

Please sign in to comment.