diff --git a/dev-infra/ng-dev.js b/dev-infra/ng-dev.js index 8ab440e7b0..4dcd9b1082 100755 --- a/dev-infra/ng-dev.js +++ b/dev-infra/ng-dev.js @@ -5462,6 +5462,27 @@ class RenderContext { return include; }; } + /** + * Convert a commit object to a Markdown link. + */ + commitToLink(commit) { + const url = `https://github.com/${this.data.github.owner}/${this.data.github.name}/commit/${commit.hash}`; + return `[${commit.shortHash}](${url})`; + } + /** + * Convert a pull request number to a Markdown link. + */ + pullRequestToLink(prNumber) { + const url = `https://github.com/${this.data.github.owner}/${this.data.github.name}/pull/${prNumber}`; + return `[#${prNumber}](${url})`; + } + /** + * Transform a commit message header by replacing the parenthesized pull request reference at the + * end of the line (which is added by merge tooling) to a Markdown link. + */ + replaceCommitHeaderPullRequestNumber(header) { + return header.replace(/\(#(\d+)\)$/, (_, g) => `(${this.pullRequestToLink(+g)})`); + } } /** * Builds a date stamp for stamping in release notes. @@ -5497,7 +5518,7 @@ _%> <%_ for (const commit of group.commits) { _%> -| <%- commit.shortHash %> | <%- commit.header %> | +| <%- commitToLink(commit) %> | <%- replaceCommitHeaderPullRequestNumber(commit.header) %> | <%_ } } diff --git a/dev-infra/release/notes/cli.ts b/dev-infra/release/notes/cli.ts index 022a25cfc4..5f6e5217ab 100644 --- a/dev-infra/release/notes/cli.ts +++ b/dev-infra/release/notes/cli.ts @@ -11,7 +11,7 @@ import {join} from 'path'; import {SemVer} from 'semver'; import {Arguments, Argv, CommandModule} from 'yargs'; -import {debug, info} from '../../utils/console'; +import {info} from '../../utils/console'; import {GitClient} from '../../utils/git/git-client'; import {ReleaseNotes} from './release-notes'; diff --git a/dev-infra/release/notes/context.ts b/dev-infra/release/notes/context.ts index ae7612df85..c1c4093904 100644 --- a/dev-infra/release/notes/context.ts +++ b/dev-infra/release/notes/context.ts @@ -135,6 +135,32 @@ export class RenderContext { return include; }; } + + /** + * Convert a commit object to a Markdown link. + */ + commitToLink(commit: CommitFromGitLog): string { + const url = `https://github.com/${this.data.github.owner}/${this.data.github.name}/commit/${ + commit.hash}`; + return `[${commit.shortHash}](${url})`; + } + + /** + * Convert a pull request number to a Markdown link. + */ + pullRequestToLink(prNumber: number): string { + const url = + `https://github.com/${this.data.github.owner}/${this.data.github.name}/pull/${prNumber}`; + return `[#${prNumber}](${url})`; + } + + /** + * Transform a commit message header by replacing the parenthesized pull request reference at the + * end of the line (which is added by merge tooling) to a Markdown link. + */ + replaceCommitHeaderPullRequestNumber(header: string): string { + return header.replace(/\(#(\d+)\)$/, (_, g) => `(${this.pullRequestToLink(+g)})`); + } } diff --git a/dev-infra/release/notes/templates/changelog.ts b/dev-infra/release/notes/templates/changelog.ts index 56afd5e31d..462c3ac331 100644 --- a/dev-infra/release/notes/templates/changelog.ts +++ b/dev-infra/release/notes/templates/changelog.ts @@ -21,7 +21,7 @@ _%> <%_ for (const commit of group.commits) { _%> -| <%- commit.shortHash %> | <%- commit.header %> | +| <%- commitToLink(commit) %> | <%- replaceCommitHeaderPullRequestNumber(commit.header) %> | <%_ } }