diff --git a/dev-infra/pr/merge/defaults/branches.ts b/dev-infra/pr/merge/defaults/branches.ts index 8cab89bc8f..151ec0aa72 100644 --- a/dev-infra/pr/merge/defaults/branches.ts +++ b/dev-infra/pr/merge/defaults/branches.ts @@ -7,16 +7,12 @@ */ import * as semver from 'semver'; -import {GithubClient} from '../../../utils/git/github'; +import {GithubClient, GithubRepo} from '../../../utils/git/github'; /** Type describing a Github repository with corresponding API client. */ -export interface GithubRepo { +export interface GithubRepoWithApi extends GithubRepo { /** API client that can access the repository. */ api: GithubClient; - /** Owner login of the repository. */ - owner: string; - /** Name of the repository. */ - repo: string; } /** Type describing a version-branch. */ @@ -51,7 +47,7 @@ const releaseTrainBranchNameRegex = /(\d+)\.(\d+)\.x/; * a currently active feature-freeze/release-candidate release-train. */ export async function fetchActiveReleaseTrainBranches( - repo: GithubRepo, nextVersion: semver.SemVer): Promise<{ + repo: GithubRepoWithApi, nextVersion: semver.SemVer): Promise<{ /** Release-train currently in active release-candidate/feature-freeze phase. */ releaseCandidate: ReleaseTrain | null, /** Latest non-prerelease release train (i.e. for the patch branch). */ @@ -102,9 +98,9 @@ export async function fetchActiveReleaseTrainBranches( /** Gets the version of a given branch by reading the `package.json` upstream. */ export async function getVersionOfBranch( - repo: GithubRepo, branchName: string): Promise { - const {data} = - await repo.api.repos.getContents({...repo, path: '/package.json', ref: branchName}); + repo: GithubRepoWithApi, branchName: string): Promise { + const {data} = await repo.api.repos.getContents( + {owner: repo.owner, repo: repo.name, path: '/package.json', ref: branchName}); const {version} = JSON.parse(Buffer.from(data.content, 'base64').toString()); const parsedVersion = semver.parse(version); if (parsedVersion === null) { @@ -136,8 +132,9 @@ export function getVersionForReleaseTrainBranch(branchName: string): semver.SemV * order. i.e. latest version branches first. */ export async function getBranchesForMajorVersions( - repo: GithubRepo, majorVersions: number[]): Promise { - const {data: branchData} = await repo.api.repos.listBranches({...repo, protected: true}); + repo: GithubRepoWithApi, majorVersions: number[]): Promise { + const {data: branchData} = + await repo.api.repos.listBranches({owner: repo.owner, repo: repo.name, protected: true}); const branches: VersionBranch[] = []; for (const {name} of branchData) { @@ -159,7 +156,7 @@ export async function getBranchesForMajorVersions( /** Finds the currently active release trains from the specified version branches. */ export async function findActiveReleaseTrainsFromVersionBranches( - repo: GithubRepo, nextVersion: semver.SemVer, branches: VersionBranch[], + repo: GithubRepoWithApi, nextVersion: semver.SemVer, branches: VersionBranch[], expectedReleaseCandidateMajor: number): Promise<{ latest: ReleaseTrain | null, releaseCandidate: ReleaseTrain | null, diff --git a/dev-infra/pr/merge/defaults/labels.ts b/dev-infra/pr/merge/defaults/labels.ts index 2ee896336f..09a67659b9 100644 --- a/dev-infra/pr/merge/defaults/labels.ts +++ b/dev-infra/pr/merge/defaults/labels.ts @@ -11,7 +11,7 @@ import {GithubClient} from '../../../utils/git/github'; import {TargetLabel} from '../config'; import {InvalidTargetBranchError, InvalidTargetLabelError} from '../target-label'; -import {fetchActiveReleaseTrainBranches, getVersionOfBranch, GithubRepo, isReleaseTrainBranch, nextBranchName} from './branches'; +import {fetchActiveReleaseTrainBranches, getVersionOfBranch, GithubRepoWithApi, isReleaseTrainBranch, nextBranchName} from './branches'; import {assertActiveLtsBranch} from './lts-branch'; /** @@ -22,7 +22,7 @@ import {assertActiveLtsBranch} from './lts-branch'; */ export async function getDefaultTargetLabelConfiguration( api: GithubClient, github: GithubConfig, npmPackageName: string): Promise { - const repo: GithubRepo = {owner: github.owner, repo: github.name, api}; + const repo: GithubRepoWithApi = {owner: github.owner, name: github.name, api}; const nextVersion = await getVersionOfBranch(repo, nextBranchName); const hasNextMajorTrain = nextVersion.minor === 0; const {latest, releaseCandidate} = await fetchActiveReleaseTrainBranches(repo, nextVersion); diff --git a/dev-infra/pr/merge/defaults/lts-branch.ts b/dev-infra/pr/merge/defaults/lts-branch.ts index a259b28b8a..49073b46cf 100644 --- a/dev-infra/pr/merge/defaults/lts-branch.ts +++ b/dev-infra/pr/merge/defaults/lts-branch.ts @@ -12,7 +12,7 @@ import * as semver from 'semver'; import {promptConfirm, red, warn, yellow} from '../../../utils/console'; import {InvalidTargetBranchError} from '../target-label'; -import {getVersionOfBranch, GithubRepo} from './branches'; +import {getVersionOfBranch, GithubRepoWithApi} from './branches'; /** * Number of months a major version in Angular is actively supported. See: @@ -39,7 +39,7 @@ const majorActiveTermSupportDuration = 12; * @param branchName Branch that is checked to be an active LTS version-branch. * */ export async function assertActiveLtsBranch( - repo: GithubRepo, representativeNpmPackage: string, branchName: string) { + repo: GithubRepoWithApi, representativeNpmPackage: string, branchName: string) { const version = await getVersionOfBranch(repo, branchName); const {'dist-tags': distTags, time} = await (await fetch(`https://registry.npmjs.org/${representativeNpmPackage}`)).json(); diff --git a/dev-infra/utils/git/github.ts b/dev-infra/utils/git/github.ts index 158bd66775..b2aaa8b3f0 100644 --- a/dev-infra/utils/git/github.ts +++ b/dev-infra/utils/git/github.ts @@ -11,6 +11,14 @@ import * as Octokit from '@octokit/rest'; import {RequestParameters} from '@octokit/types'; import {query, types} from 'typed-graphqlify'; +/** Interface describing a Github repository. */ +export interface GithubRepo { + /** Owner login of the repository. */ + owner: string; + /** Name of the repository. */ + name: string; +} + /** Error for failed Github API requests. */ export class GithubApiRequestError extends Error { constructor(public status: number, message: string) {