MCPcopy Index your code
hub / github.com/peter-evans/create-pull-request / createOrUpdate

Method createOrUpdate

src/github-helper.ts:117–189  ·  view source on GitHub ↗
(
    inputs: Inputs,
    baseRepository: string,
    headRepository: string
  )

Source from the content-addressed store, hash-verified

115 }
116
117 private async createOrUpdate(
118 inputs: Inputs,
119 baseRepository: string,
120 headRepository: string
121 ): Promise<Pull> {
122 const [headOwner] = headRepository.split('/')
123 const headBranch = `${headOwner}:${inputs.branch}`
124
125 // Try to create the pull request
126 try {
127 core.info(`Attempting creation of pull request`)
128 const {data: pull} = await this.octokit.rest.pulls.create({
129 ...this.parseRepository(baseRepository),
130 title: inputs.title,
131 head: headBranch,
132 head_repo: headRepository,
133 base: inputs.base,
134 body: inputs.body,
135 draft: inputs.draft.value,
136 maintainer_can_modify: inputs.maintainerCanModify
137 })
138 core.info(
139 `Created pull request #${pull.number} (${headBranch} => ${inputs.base})`
140 )
141 return {
142 number: pull.number,
143 html_url: pull.html_url,
144 node_id: pull.node_id,
145 draft: pull.draft,
146 created: true
147 }
148 } catch (e) {
149 const errorMessage = utils.getErrorMessage(e)
150 if (errorMessage.includes(ERROR_PR_ALREADY_EXISTS)) {
151 core.info(`A pull request already exists for ${headBranch}`)
152 } else if (errorMessage.includes(ERROR_PR_FORK_COLLAB)) {
153 core.warning(
154 'An attempt was made to create a pull request using a token that does not have write access to the head branch.'
155 )
156 core.warning(
157 `For this case, set input 'maintainer-can-modify' to 'false' to allow pull request creation.`
158 )
159 throw e
160 } else {
161 throw e
162 }
163 }
164
165 // Update the pull request that exists for this branch and base
166 core.info(`Fetching existing pull request`)
167 const pullNumber = await this.getPullNumber(
168 baseRepository,
169 headBranch,
170 inputs.base
171 )
172 core.info(`Attempting update of pull request`)
173 const {data: pull} = await this.octokit.rest.pulls.update({
174 ...this.parseRepository(baseRepository),

Callers 1

Calls 3

parseRepositoryMethod · 0.95
getPullNumberMethod · 0.95
createMethod · 0.45

Tested by

no test coverage detected