Skip to content

Commit 9584892

Browse files
authored
feat: add migration note parsing (#204)
1 parent 5ebf428 commit 9584892

File tree

6 files changed

+48
-3
lines changed

6 files changed

+48
-3
lines changed

__snapshots__/default-changelog-notes.ts.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ exports['DefaultChangelogNotes buildNotes should handle BREAKING CHANGE notes 1'
4646
### ⚠ BREAKING CHANGES
4747
4848
* some bugfix
49+
* **Migration:** migration note
4950
5051
### Bug Fixes
5152

src/changelog-notes/default.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,10 @@ export class DefaultChangelogNotes implements ChangelogNotes {
8787
})
8888
.map(commit => {
8989
const notes = commit.notes
90-
.filter(note => note.title === 'BREAKING CHANGE')
90+
.filter(
91+
note =>
92+
note.title === 'BREAKING CHANGE' || note.title === 'Migration'
93+
)
9194
.map(note =>
9295
replaceIssueLink(
9396
note,

src/commit.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,30 @@ function toConventionalChangelogFormat(
116116

117117
// [<any body-text except pre-footer>]
118118
if (body) {
119+
const migrationMessage: parser.Note = {
120+
title: 'Migration',
121+
text: '',
122+
};
123+
let hasMigration = false;
119124
visit(body, ['text', 'newline'], (node: parser.Text) => {
120125
headerCommit.body += node.value;
126+
if (node.value.includes('# Migration')) {
127+
hasMigration = true;
128+
}
129+
if (hasMigration) {
130+
migrationMessage.text += node.value;
131+
}
121132
});
133+
if (migrationMessage.text !== '') {
134+
// remove leading # Migration\n
135+
migrationMessage.text = migrationMessage.text
136+
.split('\n')
137+
.slice(1)
138+
.join('\n')
139+
.trim();
140+
migrationMessage.text = '**Migration:** ' + migrationMessage.text;
141+
headerCommit.notes.push(migrationMessage);
142+
}
122143
}
123144

124145
// Extract BREAKING CHANGE notes, regardless of whether they fall in
@@ -169,7 +190,7 @@ function toConventionalChangelogFormat(
169190
}
170191
}
171192
);
172-
if (breaking.text !== '') headerCommit.notes.push(breaking);
193+
if (breaking.text !== '') headerCommit.notes.unshift(breaking);
173194

174195
// Populates references array from footers:
175196
// references: [{

test/changelog-notes/default-changelog-notes.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,10 @@ describe('DefaultChangelogNotes', () => {
9898
type: 'fix',
9999
scope: null,
100100
bareMessage: 'some bugfix',
101-
notes: [{title: 'BREAKING CHANGE', text: 'some bugfix'}],
101+
notes: [
102+
{title: 'BREAKING CHANGE', text: 'some bugfix'},
103+
{title: 'Migration', text: '**Migration:** migration note'},
104+
],
102105
references: [],
103106
breaking: true,
104107
},

test/commits.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,15 @@ describe('parseConventionalCommits', () => {
262262
// expect(conventionalCommits[0].type).to.equal('docs');
263263
// expect(conventionalCommits[0].scope).is.null;
264264
// });
265+
266+
it('handles migration messages', async () => {
267+
const commits = [buildCommitFromFixture('migration-message')];
268+
const conventionalCommits = parseConventionalCommits(commits);
269+
expect(conventionalCommits[0].notes[1].title).to.eql('Migration');
270+
expect(conventionalCommits[0].notes[1].text).to.eql(
271+
'**Migration:** my message'
272+
);
273+
});
265274
});
266275

267276
function assertHasCommit(
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
refactor(sdk)!: change how path parameters are passed to resource methods
2+
3+
We’ve changed the shape of how API path parameters (\`/api/pipes/{pipeId}\`)
4+
are passed to SDK methods (\`client.pipes.get(…)\`).
5+
6+
# Migration
7+
8+
my message

0 commit comments

Comments
 (0)