( repo: ReleaseRepoWithApi, branchName: string, )
| 61 | |
| 62 | /** Gets the version info for a branch by reading the `package.json` upstream. */ |
| 63 | export 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. */ |
| 91 | export function isVersionBranch(branchName: string): boolean { |
no test coverage detected