diff --git a/package.json b/package.json index 1c2aa678..ec786961 100644 --- a/package.json +++ b/package.json @@ -105,6 +105,11 @@ "title": "Setup Gitlab Token...", "category": "GitHub" }, + { + "command": "vscode-github.clearToken", + "title": "Remove Token...", + "category": "GitHub" + }, { "command": "vscode-github.browseProject", "title": "Browse project", diff --git a/src/commands/token.ts b/src/commands/token.ts index 992f20e0..cf2485d9 100644 --- a/src/commands/token.ts +++ b/src/commands/token.ts @@ -2,6 +2,7 @@ import { component, inject } from 'tsdi'; import * as vscode from 'vscode'; import { Command } from '../command'; +import { listTokenHosts, removeToken } from '../tokens'; import { WorkflowManager, Tokens } from '../workflow-manager'; @component({eager: true}) @@ -109,3 +110,23 @@ export class SetGitLabToken extends Command { } } + +@component({eager: true}) +export class ClearToken extends Command { + + public id = 'vscode-github.clearToken'; + + @inject('vscode.ExtensionContext') + private context: vscode.ExtensionContext; + + public async run(): Promise { + this.track('execute'); + const host = await vscode.window.showQuickPick(listTokenHosts(this.context.globalState), { + placeHolder: 'Token to remove' + }); + if (host) { + removeToken(this.context.globalState, host); + } + } + +} diff --git a/src/tokens.ts b/src/tokens.ts index 04e7f57f..896845d4 100644 --- a/src/tokens.ts +++ b/src/tokens.ts @@ -30,3 +30,19 @@ export function migrateToken(memento: Memento): void { memento.update('tokens', struct); } } + +export function listTokenHosts(memento: Memento): string[] { + const tokens: Tokens | undefined = memento.get('tokens'); + if (!tokens) { + return []; + } + return Object.keys(tokens); +} + +export function removeToken(memento: Memento, host: string): void { + const tokens: Tokens | undefined = memento.get('tokens'); + if (tokens) { + delete tokens[host]; + memento.update('tokens', tokens); + } +}