Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions packages/utils/src/lib/git/git.commits-and-tags.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
import { type LogOptions as SimpleGitLogOptions, simpleGit } from 'simple-git';
import { type Commit, commitSchema } from '@code-pushup/models';
import { stringifyError } from '../errors.js';
import { ui } from '../logging.js';
import { isSemver } from '../semver.js';

export async function getLatestCommit(
git = simpleGit(),
): Promise<Commit | null> {
const log = await git.log({
maxCount: 1,
// git log -1 --pretty=format:"%H %s %an %aI" - See: https://git-scm.com/docs/pretty-formats
format: { hash: '%H', message: '%s', author: '%an', date: '%aI' },
});
return commitSchema.parse(log.latest);
try {
const log = await git.log({
maxCount: 1,
// git log -1 --pretty=format:"%H %s %an %aI" - See: https://git-scm.com/docs/pretty-formats
format: { hash: '%H', message: '%s', author: '%an', date: '%aI' },
});
return commitSchema.parse(log.latest);
} catch (error) {
ui().logger.error(stringifyError(error));
return null;
}
}

export async function getCurrentBranchOrTag(
Expand Down