From c3620f9a5f9477848320839e83ba4534f01cbde4 Mon Sep 17 00:00:00 2001 From: George Kalpakas Date: Fri, 2 Jul 2021 12:08:05 +0300 Subject: [PATCH] fix(dev-infra): convert commit SHAs and PR numbers to links when generating changelog (#42732) Previously, the commit SHAs and PR numbers referenced in the generated `CHANGELOG.md` were not automatically converted to links in the GitHub UI (as happens for release notes and issue/PR comments). This made it less straight-forward for someone reading the changelog to get to the commit/PR corresponding to a change. This commit updates the tooling that generates the changelog to convert the commit SHA and the corresponding PR number (referenced at the end of the commit message header) to links. PR Close #42732 --- dev-infra/ng-dev.js | 23 +++++++++++++++- dev-infra/release/notes/cli.ts | 2 +- dev-infra/release/notes/context.ts | 26 +++++++++++++++++++ .../release/notes/templates/changelog.ts | 2 +- 4 files changed, 50 insertions(+), 3 deletions(-) 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) %> | <%_ } }