MCPcopy Create free account
hub / github.com/Snapchat/Valdi / getLatestReleaseTagFromGit

Function getLatestReleaseTagFromGit

npm_modules/cli/src/utils/githubUtils.ts:78–95  ·  view source on GitHub ↗

* Fallback: resolve tag refs via git ls-remote and return the latest tag by semver. * git ls-remote returns refs sorted by refname (alphabetically), so we parse all tags * and pick the highest semantic version.

(repoUrl: string)

Source from the content-addressed store, hash-verified

76 * and pick the highest semantic version.
77 */
78async function getLatestReleaseTagFromGit(repoUrl: string): Promise<string> {
79 const gitUrl = repoUrl.includes('.git') ? repoUrl : `${repoUrl}.git`;
80 const result = await runCliCommand(`git ls-remote --tags --refs ${gitUrl}`, undefined, true);
81 const lines = result.stdout.trim().split('\n').filter(Boolean);
82 const tags: string[] = [];
83 for (const line of lines) {
84 const ref = line.split(/\s+/)[1];
85 if (ref?.startsWith('refs/tags/')) {
86 const tag = ref.slice('refs/tags/'.length);
87 if (tag) tags.push(tag);
88 }
89 }
90 if (tags.length === 0) {
91 throw new Error('No tags found in repository');
92 }
93 tags.sort(compareSemverTags);
94 return tags[tags.length - 1]!;
95}
96
97/** @deprecated Use getLatestReleaseTag for the GitHub "Latest" release; this returns an arbitrary tag from git ls-remote. */
98export async function resolveLatestReleaseRef(repoUrl: string): Promise<string> {

Callers 2

getLatestReleaseTagFunction · 0.85
resolveLatestReleaseRefFunction · 0.85

Calls 7

runCliCommandFunction · 0.90
filterMethod · 0.80
splitMethod · 0.80
startsWithMethod · 0.80
sortMethod · 0.65
trimMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected