diff options
author | 2020-05-25 06:02:25 -0400 | |
---|---|---|
committer | 2020-05-25 12:02:25 +0200 | |
commit | ca781c410d2e72540e06065b78d9e1cc9119f1ca (patch) | |
tree | 506782e5aa6a9bd26f5a5d91e2fead697b24552c /source/features/revert-file.tsx | |
parent | e49dfdb29b212f1e895099b44e63ade773aceaf9 (diff) | |
download | refined-github-ca781c410d2e72540e06065b78d9e1cc9119f1ca.tar.gz refined-github-ca781c410d2e72540e06065b78d9e1cc9119f1ca.tar.zst refined-github-ca781c410d2e72540e06065b78d9e1cc9119f1ca.zip |
Minor bug fixes (#3130)
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(); |