mirror of
https://github.com/EnixCoda/Gitako.git
synced 2026-03-11 08:54:44 +00:00
fix: resolve sha from partially loaded DOM can be unreliable
This commit is contained in:
parent
e6cba2c7e6
commit
f22f270523
2 changed files with 5 additions and 8 deletions
|
|
@ -115,9 +115,11 @@ export async function getPullPageDocument(
|
|||
const filesDOM = await getDOM(
|
||||
`https://${window.location.host}/${userName}/${repoName}/pull/${pullId}/files?_pjax=%23js-repo-pjax-container`,
|
||||
)
|
||||
const hookElement: HTMLDivElement | null = filesDOM.querySelector('div.js-pull-refresh-on-pjax')
|
||||
const hookSearchParams = new URLSearchParams(hookElement?.dataset.url)
|
||||
const [baseSHA, headSHA] = [
|
||||
filesDOM.querySelector('input[name="comparison_start_oid"]')?.getAttribute('value'),
|
||||
filesDOM.querySelector('input[name="comparison_end_oid"]')?.getAttribute('value'),
|
||||
hookSearchParams.get('start_commit_oid'),
|
||||
hookSearchParams.get('end_commit_oid'),
|
||||
]
|
||||
if (!baseSHA || !headSHA) throw new Error(`Cannot fetch SHA for comparison`)
|
||||
|
||||
|
|
|
|||
|
|
@ -249,12 +249,7 @@ export const GitHub: Platform = {
|
|||
}
|
||||
|
||||
async function createPullFileResolver(userName: string, repoName: string, pullId: string) {
|
||||
let doc: Document
|
||||
if (URLHelper.parse().path[1] === 'files') {
|
||||
doc = document
|
||||
} else {
|
||||
doc = await API.getPullPageDocument(userName, repoName, pullId)
|
||||
}
|
||||
const doc = await API.getPullPageDocument(userName, repoName, pullId)
|
||||
|
||||
return (path: string) => {
|
||||
const id = doc.querySelector(`*[data-path^="${path}"]`)?.parentElement?.id
|
||||
|
|
|
|||
Loading…
Reference in a new issue