Skip to content

Commit

Permalink
feat: add include-commit-links & include-pr-links action inputs (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ardalanamini authored Apr 15, 2023
1 parent 59a206c commit 479475e
Show file tree
Hide file tree
Showing 7 changed files with 39,042 additions and 25 deletions.
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,30 @@ _Default:_
true
```

#### `include-pr-links`

**(Optional)**

Include GitHub pull request links at each log if applicable.

_Default:_

```yaml
true
```

#### `include-commit-links`

**(Optional)**

Include GitHub commit links at each log.

_Default:_

```yaml
true
```

#### `semver`

**(Optional)**
Expand Down Expand Up @@ -225,5 +249,7 @@ Using with custom inputs:
mention-authors: true
mention-new-contributors: true
include-compare: true
include-pr-lints: true
include-commit-lints: true
semver: true
```
10 changes: 10 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@ inputs:
required: true
default: 'true'

include-pr-links:
description: Include GitHub pull request links at each log if applicable
required: true
default: 'true'

include-commit-links:
description: Include GitHub commit links at each log
required: true
default: 'true'

semver:
description: Enable semver based version comparison
required: true
Expand Down
38,971 changes: 38,969 additions & 2 deletions action/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion action/index.js.map

Large diffs are not rendered by default.

46 changes: 26 additions & 20 deletions src/changelog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function unique(value: string[]): string[] {

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

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

const reference: ReferenceI = {
author: mentionAuthors ? commit.author?.login : null,
commit: commit.sha,
pr,
commit: includeCommitLinks ? commit.sha : null,
pr : includePRLinks ? pr : null,
};

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

for (const { title, references } of categoryGroup) {
changelog.push(`${ baseLine }* ${ title } (${ references
.map(reference => `${
reference.pr == null ? "" : `${ repoUrl }/pull/${ reference.pr } `
}${
repoUrl
}/commit/${
reference.commit
}${
reference.author == null
? ""
: (
reference.author.endsWith(APP_AUTHOR_SUFFIX)
? ` by [@${ reference.author }](https://github.com/apps/${ reference.author.slice(0, -APP_AUTHOR_SUFFIX_LENGTH) })`
: ` by @${ reference.author }`
)
}`)
.join(", ") })`);
let log = `${ baseLine }* ${ title }`;

const links: string[] = [];

for (const { pr, commit, author } of references) {
const link: string[] = [];

if (pr != null) link.push(`${ repoUrl }/pull/${ pr }`);

if (commit != null) link.push(`${ repoUrl }/commit/${ commit }`);

if (author != null) {
// eslint-disable-next-line max-depth
if (author.endsWith(APP_AUTHOR_SUFFIX)) link.push(`by [@${ author }](https://github.com/apps/${ author.slice(0, -APP_AUTHOR_SUFFIX_LENGTH) })`);
else link.push(`by @${ author }`);
}

if (link.length > 0) links.push(link.join(" "));
}

if (links.length > 0) log += ` (${ links.join(", ") })`;

changelog.push(log);
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ export interface LogI {

export interface ReferenceI {
author?: string | null;
commit: string;
pr?: string;
commit: string | null;
pr?: string | null;
}

export interface TagInputI {
Expand Down Expand Up @@ -49,7 +49,9 @@ export interface ChangelogInputI {
export interface ActionInputsI {
commitTypes: TypesI;
defaultCommitType: string;
includeCommitLinks: boolean;
includeCompare: boolean;
includePRLinks: boolean;
mentionAuthors: boolean;
mentionNewContributors: boolean;
releaseName: string;
Expand Down
6 changes: 6 additions & 0 deletions src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export async function getInputs(): Promise<ActionInputsI> {
required: true,
});
const includeCompare = getBooleanInput("include-compare", { required: true });
const includePRLinks = getBooleanInput("include-pr-links", { required: true });
const includeCommitLinks = getBooleanInput("include-commit-links", { required: true });
const semver = getBooleanInput("semver", { required: true });

return Joi.object<ActionInputsI, true>()
Expand All @@ -28,6 +30,8 @@ export async function getInputs(): Promise<ActionInputsI> {
mentionAuthors : Joi.boolean().required(),
mentionNewContributors: Joi.boolean().required(),
includeCompare : Joi.boolean().required(),
includePRLinks : Joi.boolean().required(),
includeCommitLinks : Joi.boolean().required(),
semver : Joi.boolean().required(),
})
.validateAsync({
Expand All @@ -37,6 +41,8 @@ export async function getInputs(): Promise<ActionInputsI> {
mentionAuthors,
mentionNewContributors,
includeCompare,
includePRLinks,
includeCommitLinks,
semver,
});
}

0 comments on commit 479475e

Please sign in to comment.