MCPcopy Create free account
hub / github.com/angular/dev-infra / getVersionInfoForBranch

Function getVersionInfoForBranch

ng-dev/release/versioning/version-branches.ts:63–88  ·  view source on GitHub ↗
(
  repo: ReleaseRepoWithApi,
  branchName: string,
)

Source from the content-addressed store, hash-verified

61
62/** Gets the version info for a branch by reading the `package.json` upstream. */
63export async function getVersionInfoForBranch(
64 repo: ReleaseRepoWithApi,
65 branchName: string,
66): Promise<VersionInfo> {
67 const {data} = await repo.api.repos.getContent({
68 owner: repo.owner,
69 repo: repo.name,
70 path: '/package.json',
71 ref: branchName,
72 });
73 // Workaround for: https://github.com/octokit/rest.js/issues/32.
74 // TODO: Remove cast once types of Octokit `getContent` are fixed.
75 const content = (data as {content?: string}).content;
76 if (!content) {
77 throw Error(`Unable to read "package.json" file from repository.`);
78 }
79 const pkgJson = JSON.parse(Buffer.from(content, 'base64').toString()) as PackageJson;
80 const parsedVersion = semver.parse(pkgJson.version);
81 if (parsedVersion === null) {
82 throw Error(`Invalid version detected in following branch: ${branchName}.`);
83 }
84 return {
85 version: parsedVersion,
86 isExceptionalMinor: pkgJson[exceptionalMinorPackageIndicator] === true,
87 };
88}
89
90/** Whether the given branch corresponds to a version branch. */
91export function isVersionBranch(branchName: string): boolean {

Calls 1

toStringMethod · 0.45

Tested by

no test coverage detected