Skip to content

Commit 479475e

Browse files
authored
feat: add include-commit-links & include-pr-links action inputs (#136)
1 parent 59a206c commit 479475e

File tree

7 files changed

+39042
-25
lines changed

7 files changed

+39042
-25
lines changed

README.md

+26
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,30 @@ _Default:_
149149
true
150150
```
151151

152+
#### `include-pr-links`
153+
154+
**(Optional)**
155+
156+
Include GitHub pull request links at each log if applicable.
157+
158+
_Default:_
159+
160+
```yaml
161+
true
162+
```
163+
164+
#### `include-commit-links`
165+
166+
**(Optional)**
167+
168+
Include GitHub commit links at each log.
169+
170+
_Default:_
171+
172+
```yaml
173+
true
174+
```
175+
152176
#### `semver`
153177

154178
**(Optional)**
@@ -225,5 +249,7 @@ Using with custom inputs:
225249
mention-authors: true
226250
mention-new-contributors: true
227251
include-compare: true
252+
include-pr-lints: true
253+
include-commit-lints: true
228254
semver: true
229255
```

action.yml

+10
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,16 @@ inputs:
5959
required: true
6060
default: 'true'
6161

62+
include-pr-links:
63+
description: Include GitHub pull request links at each log if applicable
64+
required: true
65+
default: 'true'
66+
67+
include-commit-links:
68+
description: Include GitHub commit links at each log
69+
required: true
70+
default: 'true'
71+
6272
semver:
6373
description: Enable semver based version comparison
6474
required: true

action/index.js

+38,969-2
Large diffs are not rendered by default.

action/index.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/changelog.ts

+26-20
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ function unique(value: string[]): string[] {
2020

2121
export async function generate(input: ChangelogInputI): Promise<string> {
2222
const { octokit, owner, repo, sha, tagRef, inputs } = input;
23-
const { commitTypes, defaultCommitType, mentionAuthors } = inputs;
23+
const { commitTypes, defaultCommitType, mentionAuthors, includePRLinks, includeCommitLinks } = inputs;
2424

2525
const repoUrl = `https://github.com/${ owner }/${ repo }`;
2626
const commits: LogsI = {};
@@ -66,8 +66,8 @@ export async function generate(input: ChangelogInputI): Promise<string> {
6666

6767
const reference: ReferenceI = {
6868
author: mentionAuthors ? commit.author?.login : null,
69-
commit: commit.sha,
70-
pr,
69+
commit: includeCommitLinks ? commit.sha : null,
70+
pr : includePRLinks ? pr : null,
7171
};
7272

7373
if (existingCommit == null) {
@@ -102,23 +102,29 @@ export async function generate(input: ChangelogInputI): Promise<string> {
102102
const baseLine = defaultCategory ? "" : " ";
103103

104104
for (const { title, references } of categoryGroup) {
105-
changelog.push(`${ baseLine }* ${ title } (${ references
106-
.map(reference => `${
107-
reference.pr == null ? "" : `${ repoUrl }/pull/${ reference.pr } `
108-
}${
109-
repoUrl
110-
}/commit/${
111-
reference.commit
112-
}${
113-
reference.author == null
114-
? ""
115-
: (
116-
reference.author.endsWith(APP_AUTHOR_SUFFIX)
117-
? ` by [@${ reference.author }](https://github.com/apps/${ reference.author.slice(0, -APP_AUTHOR_SUFFIX_LENGTH) })`
118-
: ` by @${ reference.author }`
119-
)
120-
}`)
121-
.join(", ") })`);
105+
let log = `${ baseLine }* ${ title }`;
106+
107+
const links: string[] = [];
108+
109+
for (const { pr, commit, author } of references) {
110+
const link: string[] = [];
111+
112+
if (pr != null) link.push(`${ repoUrl }/pull/${ pr }`);
113+
114+
if (commit != null) link.push(`${ repoUrl }/commit/${ commit }`);
115+
116+
if (author != null) {
117+
// eslint-disable-next-line max-depth
118+
if (author.endsWith(APP_AUTHOR_SUFFIX)) link.push(`by [@${ author }](https://github.com/apps/${ author.slice(0, -APP_AUTHOR_SUFFIX_LENGTH) })`);
119+
else link.push(`by @${ author }`);
120+
}
121+
122+
if (link.length > 0) links.push(link.join(" "));
123+
}
124+
125+
if (links.length > 0) log += ` (${ links.join(", ") })`;
126+
127+
changelog.push(log);
122128
}
123129
}
124130

src/constants.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ export interface LogI {
1919

2020
export interface ReferenceI {
2121
author?: string | null;
22-
commit: string;
23-
pr?: string;
22+
commit: string | null;
23+
pr?: string | null;
2424
}
2525

2626
export interface TagInputI {
@@ -49,7 +49,9 @@ export interface ChangelogInputI {
4949
export interface ActionInputsI {
5050
commitTypes: TypesI;
5151
defaultCommitType: string;
52+
includeCommitLinks: boolean;
5253
includeCompare: boolean;
54+
includePRLinks: boolean;
5355
mentionAuthors: boolean;
5456
mentionNewContributors: boolean;
5557
releaseName: string;

src/context.ts

+6
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ export async function getInputs(): Promise<ActionInputsI> {
1616
required: true,
1717
});
1818
const includeCompare = getBooleanInput("include-compare", { required: true });
19+
const includePRLinks = getBooleanInput("include-pr-links", { required: true });
20+
const includeCommitLinks = getBooleanInput("include-commit-links", { required: true });
1921
const semver = getBooleanInput("semver", { required: true });
2022

2123
return Joi.object<ActionInputsI, true>()
@@ -28,6 +30,8 @@ export async function getInputs(): Promise<ActionInputsI> {
2830
mentionAuthors : Joi.boolean().required(),
2931
mentionNewContributors: Joi.boolean().required(),
3032
includeCompare : Joi.boolean().required(),
33+
includePRLinks : Joi.boolean().required(),
34+
includeCommitLinks : Joi.boolean().required(),
3135
semver : Joi.boolean().required(),
3236
})
3337
.validateAsync({
@@ -37,6 +41,8 @@ export async function getInputs(): Promise<ActionInputsI> {
3741
mentionAuthors,
3842
mentionNewContributors,
3943
includeCompare,
44+
includePRLinks,
45+
includeCommitLinks,
4046
semver,
4147
});
4248
}

0 commit comments

Comments
 (0)