Skip to content

Commit bb3fb30

Browse files
committed
fix: Fix links in monorepos.
1 parent f984a7b commit bb3fb30

File tree

3 files changed

+7
-25
lines changed

3 files changed

+7
-25
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
#### 🐞 Fixes
44

55
- Will not autolink `@username` tokens that are wrapped in backticks.
6+
- Will properly link commits and issues within monorepos, or projects that define invalid
7+
`package.json` repository URLs.
68

79
#### 📦 Dependencies
810

src/writerOpts.ts

+4-24
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import fs from 'fs';
44
import path from 'path';
55
import getTypeGroup from './getTypeGroup';
66
import { GROUPS } from './constants';
7-
import { WriterOptions, CommitGroupLabel, Context, Reference } from './types';
7+
import { WriterOptions, CommitGroupLabel, Context } from './types';
88

99
type GroupMap<T> = { [K in CommitGroupLabel]: T };
1010

@@ -31,28 +31,8 @@ const sortWeights: GroupMap<number> = {
3131
Internals: -5,
3232
};
3333

34-
function createLink(paths: string[], context: Context, reference: Partial<Reference> = {}): string {
35-
const owner = reference.owner || context.owner;
36-
const repository = reference.repository || context.repository;
37-
const url: string[] = [];
38-
39-
if (repository) {
40-
if (context.host) {
41-
url.push(context.host);
42-
}
43-
44-
if (owner) {
45-
url.push(owner);
46-
}
47-
48-
url.push(repository);
49-
} else {
50-
url.push(context.repoUrl);
51-
}
52-
53-
url.push(...paths);
54-
55-
return url.join('/');
34+
function createLink(paths: string[], context: Context): string {
35+
return [context.host, context.owner, context.repository, ...paths].filter(Boolean).join('/');
5636
}
5737

5838
const options: Partial<WriterOptions> = {
@@ -120,7 +100,7 @@ const options: Partial<WriterOptions> = {
120100
commit.hashLink = createLink([context.commit, commit.hash], context);
121101

122102
commit.references.forEach(reference => {
123-
reference.issueLink = createLink([context.issue, reference.issue], context, reference);
103+
reference.issueLink = createLink([context.issue, reference.issue], context);
124104

125105
let source = `${reference.repository || ''}#${reference.issue}`;
126106

tests/__snapshots__/index.test.ts.snap

+1-1
Original file line numberDiff line numberDiff line change
@@ -210,5 +210,5 @@ exports[`conventional-changelog-beemo works with unknown host 1`] = `
210210
211211
#### 📘 Docs
212212
213-
- add manual ([a1b2c3d](http://unknown/commits/a1b2c3d))"
213+
- add manual ([a1b2c3d](commits/a1b2c3d))"
214214
`;

0 commit comments

Comments
 (0)