(inputs: Inputs)
| 40 | } |
| 41 | |
| 42 | export async function createPullRequest(inputs: Inputs): Promise<void> { |
| 43 | let gitConfigHelper, git |
| 44 | try { |
| 45 | core.startGroup('Prepare git configuration') |
| 46 | const repoPath = utils.getRepoPath(inputs.path) |
| 47 | git = await GitCommandManager.create(repoPath) |
| 48 | gitConfigHelper = await GitConfigHelper.create(git) |
| 49 | core.endGroup() |
| 50 | |
| 51 | core.startGroup('Determining the base and head repositories') |
| 52 | const baseRemote = gitConfigHelper.getGitRemote() |
| 53 | // Init the GitHub clients |
| 54 | const ghBranch = new GitHubHelper(baseRemote.hostname, inputs.branchToken) |
| 55 | const ghPull = new GitHubHelper(baseRemote.hostname, inputs.token) |
| 56 | // Determine the head repository; the target for the pull request branch |
| 57 | const branchRemoteName = inputs.pushToFork ? 'fork' : 'origin' |
| 58 | const branchRepository = inputs.pushToFork |
| 59 | ? inputs.pushToFork |
| 60 | : baseRemote.repository |
| 61 | if (inputs.pushToFork) { |
| 62 | // Check if the supplied fork is really a fork of the base |
| 63 | core.info( |
| 64 | `Checking if '${branchRepository}' is a fork of '${baseRemote.repository}'` |
| 65 | ) |
| 66 | const baseParentRepository = await ghBranch.getRepositoryParent( |
| 67 | baseRemote.repository |
| 68 | ) |
| 69 | const branchParentRepository = |
| 70 | await ghBranch.getRepositoryParent(branchRepository) |
| 71 | if (branchParentRepository == null) { |
| 72 | throw new Error( |
| 73 | `Repository '${branchRepository}' is not a fork. Unable to continue.` |
| 74 | ) |
| 75 | } |
| 76 | if ( |
| 77 | branchParentRepository != baseRemote.repository && |
| 78 | baseParentRepository != branchParentRepository |
| 79 | ) { |
| 80 | throw new Error( |
| 81 | `Repository '${branchRepository}' is not a fork of '${baseRemote.repository}', nor are they siblings. Unable to continue.` |
| 82 | ) |
| 83 | } |
| 84 | // Add a remote for the fork |
| 85 | const remoteUrl = utils.getRemoteUrl( |
| 86 | baseRemote.protocol, |
| 87 | baseRemote.hostname, |
| 88 | branchRepository |
| 89 | ) |
| 90 | await git.exec(['remote', 'add', 'fork', remoteUrl]) |
| 91 | } |
| 92 | core.endGroup() |
| 93 | core.info( |
| 94 | `Pull request branch target repository set to ${branchRepository}` |
| 95 | ) |
| 96 | |
| 97 | // Configure auth |
| 98 | if (baseRemote.protocol == 'HTTPS') { |
| 99 | core.startGroup('Configuring credential for HTTPS authentication') |
no test coverage detected