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

Function getLatestReleaseTag

npm_modules/cli/src/utils/githubUtils.ts:24–51  ·  view source on GitHub ↗
(repoUrl: string)

Source from the content-addressed store, hash-verified

22 * Falls back to git ls-remote only when the repo has no releases (404).
23 */
24export async function getLatestReleaseTag(repoUrl: string): Promise<string> {
25 const slug = parseGitHubRepoSlug(repoUrl);
26 let response: Response;
27 try {
28 response = await fetch(`https://api.github.com/repos/${slug}/releases/latest`, {
29 headers: { 'User-Agent': 'Valdi-CLI' },
30 });
31 } catch (error) {
32 const message = error instanceof Error ? error.message : String(error);
33 throw new Error(
34 `Could not fetch latest release from GitHub (${message}). ${LATEST_RELEASE_HINT}`,
35 );
36 }
37 if (!response.ok) {
38 if (response.status === 404) {
39 // No releases or no "latest" release – fall back to git ls-remote
40 return getLatestReleaseTagFromGit(repoUrl);
41 }
42 throw new Error(
43 `GitHub API returned ${response.status} (rate limit or server error). ${LATEST_RELEASE_HINT}`,
44 );
45 }
46 const data = (await response.json()) as { tag_name?: string };
47 if (typeof data?.tag_name !== 'string') {
48 throw new Error(`Invalid response: missing tag_name. ${LATEST_RELEASE_HINT}`);
49 }
50 return data.tag_name;
51}
52
53/** Matches semver-like tags (e.g. v1.0.0, 2.3.1, beta-0.0.1). Captures major, minor, patch. */
54const SEMVER_TAG_REGEX = /^(?:\w+-)?v?(\d+)\.(\d+)\.(\d+)(?:[-.]\S+)?$/u;

Callers 1

resolveValdiReleaseTagFunction · 0.90

Calls 4

parseGitHubRepoSlugFunction · 0.85
fetchFunction · 0.85
StringClass · 0.50

Tested by

no test coverage detected