-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Meta: Use new APIs in
update-pr-from-base-branch
(#6103)
- Loading branch information
Showing
3 changed files
with
43 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,55 @@ | ||
import * as pageDetect from 'github-url-detection'; | ||
|
||
import * as api from './api'; | ||
import {getConversationNumber} from '.'; | ||
|
||
type PullRequestInfo = { | ||
// TODO: Probably can be used for #3863 and #4679 | ||
// TODO: Use this for `restore-file` when GHE supports `compare` | ||
baseRefOid: string; | ||
|
||
// https://docs.github.com/en/graphql/reference/enums#mergeablestate | ||
mergeable: 'CONFLICTING' | 'MERGEABLE' | 'UNKNOWN'; | ||
viewerCanEditFiles: boolean; | ||
}; | ||
|
||
export default async function getPrInfo(number = getConversationNumber()!): Promise<PullRequestInfo> { | ||
export default async function getPrInfo(base: string, head: string, number = getConversationNumber()!): Promise<PullRequestInfo | undefined> { | ||
if (pageDetect.isEnterprise()) { | ||
const {repository} = await api.v4(` | ||
repository() { | ||
pullRequest(number: ${number}) { | ||
mergeable | ||
viewerCanEditFiles | ||
} | ||
} | ||
`); | ||
|
||
const compare = await api.v3(`compare/${base}...${head}?page=10000`); // `page=10000` avoids fetching any commit information, which is heavy | ||
if (compare.status !== 'diverged') { | ||
return; | ||
} | ||
|
||
return repository.pullRequest; | ||
} | ||
|
||
const {repository} = await api.v4(` | ||
repository() { | ||
pullRequest(number: ${number}) { | ||
baseRefOid | ||
mergeable | ||
viewerCanEditFiles | ||
headRef { | ||
compare(headRef: "${base}") { | ||
status | ||
behindBy | ||
aheadBy | ||
} | ||
} | ||
} | ||
} | ||
`); | ||
|
||
if (repository.pullRequest.headRef.compare.status !== 'DIVERGED') { | ||
return; | ||
} | ||
|
||
return repository.pullRequest; | ||
} |