diff options
Diffstat (limited to 'source/features/revert-file.tsx')
-rw-r--r-- | source/features/revert-file.tsx | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/source/features/revert-file.tsx b/source/features/revert-file.tsx index 4b5597ce..76bff233 100644 --- a/source/features/revert-file.tsx +++ b/source/features/revert-file.tsx @@ -31,8 +31,7 @@ const getBaseReference = onetime(async (): Promise<string> => { return repository.pullRequest.baseRefOid; }); -async function getFile(menuItem: Element): Promise<{isTruncated: boolean; text: string} | null> { - const filePath = menuItem.closest<HTMLElement>('[data-path]')!.dataset.path!; +async function getFile(filePath: string): Promise<{isTruncated: boolean; text: string} | null> { const {repository} = await api.v4(` repository(${getRepoGQL()}) { file: object(expression: "${await getBaseReference()}:${filePath}") { @@ -54,12 +53,11 @@ async function deleteFile(menuItem: Element): Promise<void> { await postForm(form!); } -async function commitFileContent(menuItem: Element, content: string): Promise<void> { +async function commitFileContent(menuItem: Element, content: string, filePath: string): Promise<void> { let {pathname} = menuItem.previousElementSibling as HTMLAnchorElement; // Check if file was deleted by PR if (menuItem.closest('[data-file-deleted="true"]')) { menuItem.textContent = 'Undeleting…'; - const filePath = pathname.split('/')[5]; // The URL was something like /$user/$repo/blob/$startingCommit/$path pathname = `/${getRepoURL()}/new/${getCurrentBranch()}?filename=` + filePath; } else { menuItem.textContent = 'Committing…'; @@ -90,7 +88,8 @@ async function handleRevertFileClick(event: delegate.Event<MouseEvent, HTMLButto event.stopPropagation(); try { - const file = await getFile(menuItem); + const filePath = menuItem.closest<HTMLDivElement>('[data-path]')!.dataset.path!; + const file = await getFile(filePath); if (!file) { // The file was created by this PR. Revert === Delete. @@ -104,7 +103,7 @@ async function handleRevertFileClick(event: delegate.Event<MouseEvent, HTMLButto return; } - await commitFileContent(menuItem, file.text); + await commitFileContent(menuItem, file.text, filePath); // Hide file from view menuItem.closest('.file')!.remove(); |