Skip to content

Commit 133aa91

Browse files
committed
fix(markdown): normalize Bitbucket commit links in rendered changelog pages
closes #1404
1 parent 947e4dd commit 133aa91

2 files changed

Lines changed: 44 additions & 10 deletions

File tree

‎src/app/engines/markdown.engine.ts‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,20 +95,20 @@ export class MarkdownEngine {
9595
.catch(err => FileEngine.get(process.cwd() + path.sep + filepath))
9696
.then(data => {
9797
const returnedData: markdownReadedDatas = {
98-
markdown: this.markedInstance(data),
98+
markdown: this.renderMarkdown(data),
9999
rawData: data
100100
};
101101
return returnedData;
102102
});
103103
}
104104

105105
public getTraditionalMarkdownSync(filepath: string): string {
106-
return this.markedInstance(FileEngine.getSync(process.cwd() + path.sep + filepath));
106+
return this.renderMarkdown(FileEngine.getSync(process.cwd() + path.sep + filepath));
107107
}
108108

109109
private getReadmeFile(): Promise<string> {
110110
return FileEngine.get(process.cwd() + path.sep + 'README.md').then(data =>
111-
this.markedInstance(data)
111+
this.renderMarkdown(data)
112112
);
113113
}
114114

@@ -166,6 +166,17 @@ export class MarkdownEngine {
166166
.replace(/@/g, '&#64;');
167167
}
168168

169+
private renderMarkdown(markdown: string): string {
170+
return this.markedInstance(this.normalizeBitbucketCommitLinks(markdown));
171+
}
172+
173+
private normalizeBitbucketCommitLinks(markdown: string): string {
174+
return markdown.replace(
175+
/(https?:\/\/bitbucket\.org\/[^\s)\]>]+\/)commit\/([^\s)\]>]+)/g,
176+
'$1commits/$2'
177+
);
178+
}
179+
169180
/**
170181
* ['README'] => ['README', 'README.md']
171182
*/

‎test/src/cli/cli-markdown-files.spec.ts‎

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ import * as path from 'path';
66
const tmp = temporaryDir();
77

88
describe('CLI Markdown files generation', () => {
9-
const distFolder = tmp.name + '-markdown-files';
10-
const fixtureFolder = tmp.name + '-markdown-fixture';
9+
const distFolder = path.resolve(tmp.name + '-markdown-files');
10+
const fixtureFolder = path.resolve(tmp.name + '-markdown-fixture');
11+
const cliPath = path.resolve('./bin/index-cli.js');
1112

1213
describe('when CHANGELOG, CONTRIBUTING, and LICENSE markdown files exist', () => {
1314
let stdoutString = undefined;
@@ -50,14 +51,27 @@ describe('CLI Markdown files generation', () => {
5051
path.join(fixtureFolder, 'tsconfig.json'),
5152
JSON.stringify(tsconfigContent, null, 2)
5253
);
54+
55+
fs.writeFileSync(
56+
path.join(fixtureFolder, 'CHANGELOG.md'),
57+
'# Changelog\n\n- fix: bitbucket link ([abc1234](https://bitbucket.org/team/repo/commit/abc1234))\n'
58+
);
59+
fs.writeFileSync(
60+
path.join(fixtureFolder, 'CONTRIBUTING.md'),
61+
'# Contributing\n\nPlease contribute.\n'
62+
);
63+
fs.writeFileSync(
64+
path.join(fixtureFolder, 'LICENSE.md'),
65+
'# License\n\nMIT\n'
66+
);
5367

5468
const ls = shell('node', [
55-
'./bin/index-cli.js',
69+
cliPath,
5670
'-p',
57-
path.join(fixtureFolder, 'tsconfig.json'),
71+
'tsconfig.json',
5872
'-d',
5973
distFolder
60-
]);
74+
], { cwd: fixtureFolder });
6175

6276
if (ls.stderr.toString() !== '') {
6377
console.error(`shell error: ${ls.stderr.toString()}`);
@@ -93,10 +107,19 @@ describe('CLI Markdown files generation', () => {
93107
const changelogExists = exists(`${distFolder}/changelog.html`);
94108
expect(changelogExists).to.be.true;
95109
const changelogContent = read(`${distFolder}/changelog.html`);
96-
// Note: reads from project root CHANGELOG.md, not fixture
97110
expect(changelogContent).to.contain('changelog');
98111
});
99112

113+
it('should normalize bitbucket commit links in changelog to /commits/', () => {
114+
const changelogContent = read(`${distFolder}/changelog.html`);
115+
expect(changelogContent).to.contain(
116+
'https://bitbucket.org/team/repo/commits/abc1234'
117+
);
118+
expect(changelogContent).to.not.contain(
119+
'https://bitbucket.org/team/repo/commit/abc1234'
120+
);
121+
});
122+
100123
it('should generate contributing.html page', () => {
101124
const contributingExists = exists(`${distFolder}/contributing.html`);
102125
expect(contributingExists).to.be.true;
@@ -162,4 +185,4 @@ describe('CLI Markdown files generation', () => {
162185
expect(menuFile).to.contain('license.html');
163186
});
164187
});
165-
});
188+
});

0 commit comments

Comments
 (0)