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
This commit is contained in:
parent
19bcdfb028
commit
c3620f9a5f
|
@ -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) %> |
|
||||
<%_
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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';
|
||||
|
|
|
@ -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)})`);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ _%>
|
|||
<%_
|
||||
for (const commit of group.commits) {
|
||||
_%>
|
||||
| <%- commit.shortHash %> | <%- commit.header %> |
|
||||
| <%- commitToLink(commit) %> | <%- replaceCommitHeaderPullRequestNumber(commit.header) %> |
|
||||
<%_
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue