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

Commit

Permalink
feat: add remove token command
Browse files Browse the repository at this point in the history
Add command to remove old or invalid tokens from registry/storage.

Closes #193
  • Loading branch information
KnisterPeter committed Oct 2, 2017
1 parent 52eeeff commit f34b116
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
21 changes: 21 additions & 0 deletions src/commands/token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down Expand Up @@ -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<void> {
this.track('execute');
const host = await vscode.window.showQuickPick(listTokenHosts(this.context.globalState), {
placeHolder: 'Token to remove'
});
if (host) {
removeToken(this.context.globalState, host);
}
}

}
16 changes: 16 additions & 0 deletions src/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit f34b116

Please sign in to comment.