UNPKG

git-release-manager

Version:

A tool to generate release notes from git commit history

55 lines 2.03 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getTags = getTags; exports.isGitTag = isGitTag; const simple_git_1 = __importDefault(require("simple-git")); const date_1 = require("../../../utils/date"); const cmd_1 = require("../../../utils/cmd"); const ReferenceTypesEnum_1 = require("../../changes/types/ReferenceTypesEnum"); const git = (0, simple_git_1.default)(); async function getTags(range) { try { // Include the commit hash, tag name, and commit date in the format string const logCommand = `git log --pretty=format:"%H %ci %D" ${range}`; const { stdout } = await (0, cmd_1.execWithErrorHandling)(logCommand); const tagRegex = /^([a-f0-9]{40})\s([\d-]+\s[\d:]+\s[+-]\d{4})\s.*tag: ([^,\s]+)/gm; const tagsWithRefs = []; let match; while ((match = tagRegex.exec(stdout.trim())) !== null) { const commitHash = match[1]; const commitDate = (0, date_1.formatISO8601)(match[2]); const tagName = match[3]; tagsWithRefs.push({ name: tagName, value: tagName, reference: commitHash, type: ReferenceTypesEnum_1.ReferenceTypesEnum.tag, date: commitDate, }); } return tagsWithRefs; } catch (error) { console.error('Error retrieving tags in range:', error); throw error; } } /** * Checks if the given value is a valid Git tag. * * @param value - The value to check against the list of Git tags. * @returns A promise that resolves to `true` if the value is a valid Git tag, otherwise `false`. */ async function isGitTag(value) { try { const tags = await git.tags(); return tags.all.includes(value); } catch (_a) { return false; } } //# sourceMappingURL=tagUtils.js.map