From 666e14a802561273619b2726af54b961713dd22a Mon Sep 17 00:00:00 2001 From: Igor Vinokur Date: Tue, 13 Oct 2020 12:29:37 +0300 Subject: [PATCH] Add vscode github built-in plugin as a default plugin Signed-off-by: Igor Vinokur --- generator/src/templates/theiaPlugins.json | 1 + .../src/github-auth-plugin.ts | 64 +++++++++---------- 2 files changed, 33 insertions(+), 32 deletions(-) diff --git a/generator/src/templates/theiaPlugins.json b/generator/src/templates/theiaPlugins.json index 49d3bb15e..8f0187cdc 100644 --- a/generator/src/templates/theiaPlugins.json +++ b/generator/src/templates/theiaPlugins.json @@ -52,6 +52,7 @@ "vscode-builtin-yaml": "https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/yaml-1.39.1-prel.vsix", "vscode-editorconfig": "https://github.com/theia-ide/editorconfig-vscode/releases/download/v0.14.4/EditorConfig-0.14.4.vsix", "vscode-git": "https://open-vsx.org/api/vscode/git/1.49.3/file/vscode.git-1.49.3.vsix", + "vscode-github": "https://open-vsx.org/api/vscode/github/1.50.0/file/vscode.github-1.50.0.vsix", "vscode-references-view": "https://github.com/theia-ide/vscode-references-view/releases/download/v0.0.47/references-view-0.0.47.vsix", "vscode-builtin-theme-abyss": "https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/theme-abyss-1.39.1-prel.vsix", "vscode-builtin-theme-defaults": "https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/theme-defaults-1.39.1-prel.vsix", diff --git a/plugins/github-auth-plugin/src/github-auth-plugin.ts b/plugins/github-auth-plugin/src/github-auth-plugin.ts index 35e318f10..96ef9c74f 100644 --- a/plugins/github-auth-plugin/src/github-auth-plugin.ts +++ b/plugins/github-auth-plugin/src/github-auth-plugin.ts @@ -12,40 +12,40 @@ import * as theia from '@theia/plugin'; import * as che from '@eclipse-che/plugin'; export async function start(context: theia.PluginContext): Promise { - if (theia.plugins.getPlugin('github.vscode-pull-request-github')) { - let session: theia.AuthenticationSession | undefined = context.workspaceState.get('session'); - const onDidChangeSessions = new theia.EventEmitter(); - theia.authentication.registerAuthenticationProvider({ - id: 'github', - label: 'GitHub', - supportsMultipleAccounts: false, - onDidChangeSessions: onDidChangeSessions.event, - getSessions: async () => { - if (session) { - return [session]; - } else { - return []; - } - }, - login: async (scopes: string[]) => { - const githubUser = await che.github.getUser(); - session = { - id: 'github-session', - accessToken: await che.github.getToken(), - account: {label: githubUser.login, id: githubUser.id.toString()}, - scopes - }; - context.workspaceState.update('session', session); - onDidChangeSessions.fire({ added: [session.id], removed: [], changed: [] }); - return session; - }, - logout: async (id: string) => { - session = undefined; - context.workspaceState.update('session', session); - onDidChangeSessions.fire({ added: [], removed: [id], changed: [] }); + let session: theia.AuthenticationSession | undefined = context.workspaceState.get('session'); + const onDidChangeSessions = new theia.EventEmitter(); + theia.authentication.registerAuthenticationProvider({ + id: 'github', + label: 'GitHub', + supportsMultipleAccounts: false, + onDidChangeSessions: onDidChangeSessions.event, + getSessions: async () => { + if (session) { + return [session]; + } else { + return []; } + }, + login: async (scopes: string[]) => { + const githubUser = await che.github.getUser(); + session = { + id: 'github-session', + accessToken: await che.github.getToken(), + account: {label: githubUser.login, id: githubUser.id.toString()}, + scopes + }; + context.workspaceState.update('session', session); + onDidChangeSessions.fire({ added: [session.id], removed: [], changed: [] }); + return session; + }, + logout: async (id: string) => { + session = undefined; + context.workspaceState.update('session', session); + onDidChangeSessions.fire({ added: [], removed: [id], changed: [] }); } - ); + } + ); + if (theia.plugins.getPlugin('github.vscode-pull-request-github')) { if (session) { onDidChangeSessions.fire({ added: [session.id], removed: [], changed: [] }); // TODO Remove the notification when https://github.com/eclipse-theia/theia/issues/7178 is fixed.