Skip to content
This repository was archived by the owner on Nov 27, 2023. It is now read-only.

Commit f34b116

Browse files
committed
feat: add remove token command
Add command to remove old or invalid tokens from registry/storage. Closes #193
1 parent 52eeeff commit f34b116

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,11 @@
105105
"title": "Setup Gitlab Token...",
106106
"category": "GitHub"
107107
},
108+
{
109+
"command": "vscode-github.clearToken",
110+
"title": "Remove Token...",
111+
"category": "GitHub"
112+
},
108113
{
109114
"command": "vscode-github.browseProject",
110115
"title": "Browse project",

src/commands/token.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { component, inject } from 'tsdi';
22
import * as vscode from 'vscode';
33

44
import { Command } from '../command';
5+
import { listTokenHosts, removeToken } from '../tokens';
56
import { WorkflowManager, Tokens } from '../workflow-manager';
67

78
@component({eager: true})
@@ -109,3 +110,23 @@ export class SetGitLabToken extends Command {
109110
}
110111

111112
}
113+
114+
@component({eager: true})
115+
export class ClearToken extends Command {
116+
117+
public id = 'vscode-github.clearToken';
118+
119+
@inject('vscode.ExtensionContext')
120+
private context: vscode.ExtensionContext;
121+
122+
public async run(): Promise<void> {
123+
this.track('execute');
124+
const host = await vscode.window.showQuickPick(listTokenHosts(this.context.globalState), {
125+
placeHolder: 'Token to remove'
126+
});
127+
if (host) {
128+
removeToken(this.context.globalState, host);
129+
}
130+
}
131+
132+
}

src/tokens.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,19 @@ export function migrateToken(memento: Memento): void {
3030
memento.update('tokens', struct);
3131
}
3232
}
33+
34+
export function listTokenHosts(memento: Memento): string[] {
35+
const tokens: Tokens | undefined = memento.get('tokens');
36+
if (!tokens) {
37+
return [];
38+
}
39+
return Object.keys(tokens);
40+
}
41+
42+
export function removeToken(memento: Memento, host: string): void {
43+
const tokens: Tokens | undefined = memento.get('tokens');
44+
if (tokens) {
45+
delete tokens[host];
46+
memento.update('tokens', tokens);
47+
}
48+
}

0 commit comments

Comments
 (0)