summaryrefslogtreecommitdiff
path: root/source/features/quick-repo-deletion.tsx
diff options
context:
space:
mode:
authorGravatar Federico Brigante <me@fregante.com> 2022-07-20 00:25:37 +0700
committerGravatar GitHub <noreply@github.com> 2022-07-20 00:25:37 +0700
commitf2c07257766df27d3b3787ff17b3e5e4f9ed5aaf (patch)
tree6ddeb95ad4f3a6ac0183e93ad4dd4630cf04d86f /source/features/quick-repo-deletion.tsx
parent6223de2cc8140a69ddefa82fe2708a7c1611ede1 (diff)
downloadrefined-github-f2c07257766df27d3b3787ff17b3e5e4f9ed5aaf.tar.gz
refined-github-f2c07257766df27d3b3787ff17b3e5e4f9ed5aaf.tar.zst
refined-github-f2c07257766df27d3b3787ff17b3e5e4f9ed5aaf.zip
Lint (#5830)
Co-authored-by: Kid <44045911+kidonng@users.noreply.github.com> Co-authored-by: yakov116 <16872793+yakov116@users.noreply.github.com>
Diffstat (limited to 'source/features/quick-repo-deletion.tsx')
-rw-r--r--source/features/quick-repo-deletion.tsx42
1 files changed, 23 insertions, 19 deletions
diff --git a/source/features/quick-repo-deletion.tsx b/source/features/quick-repo-deletion.tsx
index d06473df..9eb040e9 100644
--- a/source/features/quick-repo-deletion.tsx
+++ b/source/features/quick-repo-deletion.tsx
@@ -5,6 +5,7 @@ import select from 'select-dom';
import delegate from 'delegate-it';
import {TrashIcon} from '@primer/octicons-react';
import elementReady from 'element-ready';
+import {assertError} from 'ts-extras';
import * as pageDetect from 'github-url-detection';
import features from '.';
@@ -40,11 +41,12 @@ function handleToggle(event: delegate.Event<Event, HTMLDetailsElement>): void {
async function verifyScopesWhileWaiting(abortController: AbortController): Promise<void> {
try {
await api.expectTokenScope('delete_repo');
- } catch (error: unknown) {
+ } catch (error) {
+ assertError(error);
abortController.abort();
addNotice([
'Could not delete the repository. ',
- parseBackticks((error as Error).message),
+ parseBackticks(error.message),
], {
type: 'error',
action: (
@@ -89,37 +91,39 @@ async function start(buttonContainer: HTMLDetailsElement): Promise<void> {
}
select('.btn', buttonContainer)!.textContent = 'Deleting repo…';
+ const {nameWithOwner, owner} = getRepo()!;
try {
- const {nameWithOwner, owner} = getRepo()!;
await api.v3('/repos/' + nameWithOwner, {
method: 'DELETE',
json: false,
});
- const forkSource = '/' + getForkedRepo()!;
- const restoreURL = pageDetect.isOrganizationRepo()
- ? `/organizations/${owner}/settings/deleted_repositories`
- : '/settings/deleted_repositories';
- const otherForksURL = `/${owner}?tab=repositories&type=fork`;
- addNotice(
- <><TrashIcon/> <span>Repository <strong>{nameWithOwner}</strong> deleted. <a href={restoreURL}>Restore it</a>, <a href={forkSource}>visit the source repo</a>, or see <a href={otherForksURL}>your other forks.</a></span></>,
- {action: false},
- );
- select('.application-main')!.remove();
- if (document.hidden) {
- // Try closing the tab if in the background. Could fail, so we still update the UI above
- void browser.runtime.sendMessage({closeTab: true});
- }
- } catch (error: unknown) {
+ } catch (error) {
+ assertError(error);
buttonContainer.closest('li')!.remove(); // Remove button
addNotice([
'Could not delete the repository. ',
- (error as any).response?.message ?? (error as any).message,
+ (error as api.RefinedGitHubAPIError).response?.message ?? error.message,
], {
type: 'error',
});
throw error;
}
+
+ const forkSource = '/' + getForkedRepo()!;
+ const restoreURL = pageDetect.isOrganizationRepo()
+ ? `/organizations/${owner}/settings/deleted_repositories`
+ : '/settings/deleted_repositories';
+ const otherForksURL = `/${owner}?tab=repositories&type=fork`;
+ addNotice(
+ <><TrashIcon/> <span>Repository <strong>{nameWithOwner}</strong> deleted. <a href={restoreURL}>Restore it</a>, <a href={forkSource}>visit the source repo</a>, or see <a href={otherForksURL}>your other forks.</a></span></>,
+ {action: false},
+ );
+ select('.application-main')!.remove();
+ if (document.hidden) {
+ // Try closing the tab if in the background. Could fail, so we still update the UI above
+ void browser.runtime.sendMessage({closeTab: true});
+ }
}
async function init(): Promise<Deinit | false> {