From 26c54fa865f12bd58ab84c335b44b996a454faa7 Mon Sep 17 00:00:00 2001 From: Benjamin Gilbert Date: Thu, 28 Sep 2023 19:58:31 -0500 Subject: [PATCH] RFC: allow push-to-fork to push to sibling repos Fixes #2412. --- src/create-pull-request.ts | 17 ++++++++++++++--- src/github-helper.ts | 6 ++---- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/create-pull-request.ts b/src/create-pull-request.ts index 526c5a43b8..516892e2cc 100644 --- a/src/create-pull-request.ts +++ b/src/create-pull-request.ts @@ -83,11 +83,22 @@ export async function createPullRequest(inputs: Inputs): Promise { core.info( `Checking if '${branchRepository}' is a fork of '${baseRemote.repository}'` ) - const parentRepository = + const baseParentRepository = await githubHelper.getRepositoryParent( + baseRemote.repository + ) + const branchParentRepository = await githubHelper.getRepositoryParent(branchRepository) - if (parentRepository != baseRemote.repository) { + if (branchParentRepository == null) { + throw new Error( + `Repository '${branchRepository}' is not a fork. Unable to continue.` + ) + } + if ( + branchParentRepository != baseRemote.repository && + baseParentRepository != branchParentRepository + ) { throw new Error( - `Repository '${branchRepository}' is not a fork of '${baseRemote.repository}'. Unable to continue.` + `Repository '${branchRepository}' is not a fork of '${baseRemote.repository}', nor are they siblings. Unable to continue.` ) } // Add a remote for the fork diff --git a/src/github-helper.ts b/src/github-helper.ts index d1d224e0b1..cc596a9eb2 100644 --- a/src/github-helper.ts +++ b/src/github-helper.ts @@ -101,14 +101,12 @@ export class GitHubHelper { } } - async getRepositoryParent(headRepository: string): Promise { + async getRepositoryParent(headRepository: string): Promise { const {data: headRepo} = await this.octokit.rest.repos.get({ ...this.parseRepository(headRepository) }) if (!headRepo.parent) { - throw new Error( - `Repository '${headRepository}' is not a fork. Unable to continue.` - ) + return null } return headRepo.parent.full_name }