-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Meta: Use new APIs in update-pr-from-base-branch
#6103
Merged
Changes from 18 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
04debc2
Untested
yakov116 8772193
Update get-pr-info.ts
yakov116 fadea1c
Update update-pr-from-base-branch.tsx
yakov116 317783c
dry
yakov116 0102417
support GHE
yakov116 bb8366c
DRY `restore-file`
yakov116 6d16061
lint
yakov116 11f8026
Update get-pr-info.ts
yakov116 cd9e7ec
Lint
yakov116 30ceada
Restore restore-file.tsx
yakov116 1f21079
Remove one time and add comment
yakov116 35c9cee
Merge Function
yakov116 e3de76a
Add todo
yakov116 22852cf
Fix typo
yakov116 0350631
and another one
yakov116 8283a5a
Fix ghe
yakov116 b73de32
then the change happens here
yakov116 b4d4d9b
move the uppercase
yakov116 2930a11
Check DIVERGED in the api request
yakov116 8e963ce
Function style
fregante File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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,59 @@ | ||
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 | ||
baseRefOid: string; | ||
|
||
// https://docs.github.com/en/graphql/reference/enums#mergeablestate | ||
mergeable: 'CONFLICTING' | 'MERGEABLE' | 'UNKNOWN'; | ||
viewerCanEditFiles: boolean; | ||
prInfo: { | ||
// 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; | ||
}; | ||
comparison: { | ||
status: 'BEHIND' | 'DIVERGED' | 'AHEAD' | 'IDENTICAL'; | ||
}; | ||
}; | ||
|
||
export default async function getPrInfo(number = getConversationNumber()!): Promise<PullRequestInfo> { | ||
export default async function getPrInfo(base: string, head: string, number = getConversationNumber()!): Promise<PullRequestInfo> { | ||
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 | ||
compare.status = compare.status.toUpperCase(); | ||
return { | ||
prInfo: repository.pullRequest, | ||
comparison: compare, | ||
yakov116 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}; | ||
} | ||
|
||
const {repository} = await api.v4(` | ||
repository() { | ||
pullRequest(number: ${number}) { | ||
baseRefOid | ||
mergeable | ||
viewerCanEditFiles | ||
headRef { | ||
compare(headRef: "${base}") { | ||
status | ||
behindBy | ||
aheadBy | ||
yakov116 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
} | ||
} | ||
`); | ||
return repository.pullRequest; | ||
|
||
return { | ||
prInfo: repository.pullRequest, | ||
comparison: repository.pullRequest.headRef.compare, | ||
}; | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can merge these into flat object, no need to have prInfo and comparison keys. While we're at it it can be simplified further, like setting
diverged: true
instead of matching strings outsideThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain this one more time I am not sure I understood what you said