Skip to content

Commit d2dc315

Browse files
committed
fix(markdown): await generateMarkdown in changelog functions and update URL generation logic
1 parent 87cdf96 commit d2dc315

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

src/git.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export function getFromToTags(tags: string[]) {
8282
return result.reverse();
8383
}
8484

85-
async function getGitMainBranchName() {
85+
export async function getGitMainBranchName() {
8686
const main = await execCommand('git', ['rev-parse', '--abbrev-ref', 'HEAD']);
8787

8888
return main;

src/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export async function getChangelogMarkdown(options?: Partial<ChangelogOption>, s
2020
const resolvedLogins = new Map<string, string>();
2121
const { commits, contributors } = await getGitCommitsAndResolvedAuthors(gitCommits, opts.github, resolvedLogins);
2222

23-
const markdown = generateMarkdown({ commits, options: opts, showTitle, contributors });
23+
const markdown = await generateMarkdown({ commits, options: opts, showTitle, contributors });
2424

2525
return {
2626
markdown,
@@ -33,7 +33,7 @@ export async function getChangelogMarkdown(options?: Partial<ChangelogOption>, s
3333
* Get the changelog markdown by the total git tags
3434
*
3535
* @param options The changelog options
36-
* @param showProgress Whither show the progress bar
36+
* @param showProgress Whether show the progress bar
3737
*/
3838
export async function getTotalChangelogMarkdown(options?: Partial<ChangelogOption>, showProgress = true) {
3939
const opts = await createOptions(options);
@@ -64,7 +64,7 @@ export async function getTotalChangelogMarkdown(options?: Partial<ChangelogOptio
6464
const gitCommits = await getGitCommits(from, to);
6565
const { commits, contributors } = await getGitCommitsAndResolvedAuthors(gitCommits, opts.github, resolvedLogins);
6666

67-
const nextMd = generateMarkdown({ commits, options: { ...opts, from, to }, showTitle: true, contributors });
67+
const nextMd = await generateMarkdown({ commits, options: { ...opts, from, to }, showTitle: true, contributors });
6868

6969
markdown = `${nextMd}\n\n${markdown}`;
7070

src/markdown.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import dayjs from 'dayjs';
44
import { convert } from 'convert-gitmoji';
55
import { capitalize, groupBy, join, partition } from './shared';
66
import { VERSION_REG_OF_MARKDOWN, VERSION_WITH_RELEASE } from './constant';
7+
import { getGitMainBranchName } from './git';
78
import type { ChangelogOption, GitCommit, Reference, ResolvedAuthor } from './types';
89

910
function formatReferences(references: Reference[], githubRepo: string, type: 'issues' | 'hash'): string {
@@ -138,7 +139,7 @@ function createContributorLine(contributors: ResolvedAuthor[]) {
138139
return `${loginLine}\n${unLoginLine}`;
139140
}
140141

141-
export function generateMarkdown(params: {
142+
export async function generateMarkdown(params: {
142143
commits: GitCommit[];
143144
options: ChangelogOption;
144145
showTitle: boolean;
@@ -151,7 +152,11 @@ export function generateMarkdown(params: {
151152

152153
const lines: string[] = [];
153154

154-
const url = `https://github.com/${options.github.repo}/compare/${options.from}...${options.to || options.from}`;
155+
let url = `https://github.com/${options.github.repo}/compare/${options.from}...${options.to}`;
156+
if (!options.from) {
157+
const mainBranch = await getGitMainBranchName();
158+
url = `https://github.com/${options.github.repo}/compare/${options.to}...${mainBranch || 'HEAD'}`;
159+
}
155160

156161
if (showTitle) {
157162
const date = options.tagDateMap.get(options.to) || dayjs().format('YYYY-MM-DD');

0 commit comments

Comments
 (0)