Skip to content

Commit

Permalink
fix prepareVersionChangelog for non-tagged repos
Browse files Browse the repository at this point in the history
  • Loading branch information
TimurRin committed Jul 23, 2024
1 parent 3a5db83 commit 1022a9e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
11 changes: 9 additions & 2 deletions src/changelog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import { promptText } from "clivo";
import fs from "fs";
import path from "path";

import { checkVersionExistsInGitTags, getGitLog } from "./git.js";
import {
checkVersionExistsInGitTags,
getGitLog,
getMostRecentGitTag,
} from "./git.js";
import { CinnabarMetaGitLogItem, CinnabarMetaRepo } from "./types.js";

const COMMENT_LINE = "[comment]: # (Insert new version after this line)";
Expand All @@ -20,11 +24,14 @@ function prepareVersionChangelog(
newVersion: string,
versionComment: null | string,
) {
const lastTag = getMostRecentGitTag();
const gitLogs: CinnabarMetaGitLogItem[] = checkVersionExistsInGitTags(
oldVersion,
)
? getGitLog("v" + oldVersion)
: [];
: lastTag != null
? getGitLog(lastTag)
: getGitLog();
const changesMap = new Map<string, string[]>();

gitLogs.forEach((log) => {
Expand Down
6 changes: 3 additions & 3 deletions src/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import { execSync } from "child_process";
import { CinnabarMetaGitLogItem } from "./types.js";

/**
*
* Gets an array of objects contains log since specified tag or commit
* @param tagOrCommit
*/
export function getGitLog(tagOrCommit: string): CinnabarMetaGitLogItem[] {
export function getGitLog(tagOrCommit?: string): CinnabarMetaGitLogItem[] {
try {
const log = execSync(
`git log ${tagOrCommit}..HEAD --pretty=format:'%H%n%B'`,
`git log ${tagOrCommit ? tagOrCommit + "..HEAD " : ""}--pretty=format:'%H%n%B'`,
).toString();
return log.split("\n\n").map((line) => {
const [hash, ...message] = line.split("\n");
Expand Down

0 comments on commit 1022a9e

Please sign in to comment.