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

Method getPullNumber

src/github-helper.ts:73–115  ·  view source on GitHub ↗
(
    baseRepository: string,
    headBranch: string,
    baseBranch: string
  )

Source from the content-addressed store, hash-verified

71 }
72
73 private async getPullNumber(
74 baseRepository: string,
75 headBranch: string,
76 baseBranch: string
77 ): Promise<number> {
78 const {data: pulls} = await this.octokit.rest.pulls.list({
79 ...this.parseRepository(baseRepository),
80 state: 'open',
81 head: headBranch,
82 base: baseBranch
83 })
84 let pullNumber: number | undefined = undefined
85 if (pulls?.length === 0 || pulls === null || pulls === undefined) {
86 // This is a fallback due to a bug that affects the list endpoint when called on forks with the same owner as the repository parent.
87 core.info(
88 `Pull request not found via list endpoint; attempting fallback mechanism`
89 )
90 for await (const response of this.octokit.paginate.iterator(
91 this.octokit.rest.pulls.list,
92 {
93 ...this.parseRepository(baseRepository),
94 state: 'open',
95 base: baseBranch
96 }
97 )) {
98 const existingPull = response.data.find(
99 pull => pull.head.label === headBranch
100 )
101 if (existingPull !== undefined) {
102 pullNumber = existingPull.number
103 break
104 }
105 }
106 } else {
107 pullNumber = pulls[0].number
108 }
109 if (pullNumber === undefined) {
110 throw new Error(
111 `Failed to find pull request number for branch ${headBranch}`
112 )
113 }
114 return pullNumber
115 }
116
117 private async createOrUpdate(
118 inputs: Inputs,

Callers 1

createOrUpdateMethod · 0.95

Calls 1

parseRepositoryMethod · 0.95

Tested by

no test coverage detected