Skip to content

Commit

Permalink
feat: allow push-to-fork to push to sibling repos (#2414)
Browse files Browse the repository at this point in the history
Fixes #2412.
  • Loading branch information
bgilbert authored and peter-evans committed Dec 19, 2023
1 parent cbe1686 commit 4a2f9e2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
17 changes: 14 additions & 3 deletions src/create-pull-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,22 @@ export async function createPullRequest(inputs: Inputs): Promise<void> {
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
Expand Down
6 changes: 2 additions & 4 deletions src/github-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,12 @@ export class GitHubHelper {
}
}

async getRepositoryParent(headRepository: string): Promise<string> {
async getRepositoryParent(headRepository: string): Promise<string | null> {
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
}
Expand Down

0 comments on commit 4a2f9e2

Please sign in to comment.