MCPcopy
hub / github.com/peter-evans/create-pull-request / createPullRequest

Function createPullRequest

src/create-pull-request.ts:42–332  ·  view source on GitHub ↗
(inputs: Inputs)

Source from the content-addressed store, hash-verified

40}
41
42export 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')

Callers 1

runFunction · 0.90

Calls 15

getRepositoryParentMethod · 0.95
pushSignedCommitsMethod · 0.95
convertToDraftMethod · 0.95
getCommitMethod · 0.95
getWorkingBaseAndTypeFunction · 0.90
createOrUpdateBranchFunction · 0.90
getGitRemoteMethod · 0.80
execMethod · 0.80
configureTokenMethod · 0.80
revParseMethod · 0.80
setIdentityGitOptionsMethod · 0.80

Tested by

no test coverage detected