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

Commit

Permalink
Register GitHub Authentication provider for the vscode Github PR plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
vinokurig committed Aug 26, 2020
1 parent cbe0f00 commit eb12fb9
Showing 1 changed file with 31 additions and 15 deletions.
46 changes: 31 additions & 15 deletions plugins/github-auth-plugin/src/github-auth-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,38 @@
import * as theia from '@theia/plugin';
import * as che from '@eclipse-che/plugin';

export function start(context: theia.PluginContext): void {
export async function start(context: theia.PluginContext): Promise<void> {
let session: theia.AuthenticationSession | undefined;
if (theia.plugins.getPlugin('github.vscode-pull-request-github')) {
const command = {
id: 'github-plugin-authenticate',
label: 'GitHub authenticate'
};
context.subscriptions.push(theia.commands.registerCommand(command, async () => {
const token = await che.github.getToken();
const conf = theia.workspace.getConfiguration();
await conf.update('githubPullRequests.hosts', [{
host: 'github.com',
token
}], theia.ConfigurationTarget.Global);
theia.window.showWarningMessage('GitHub token has been set to preferences. ' +
'Refresh the page to reinitialise the vscode GitHub pull-request plugin with the token');
}));
const onDidChangeSessions = new theia.EventEmitter<theia.AuthenticationProviderAuthenticationSessionsChangeEvent>();
theia.authentication.registerAuthenticationProvider({
id: 'github',
label: 'GitHub',
supportsMultipleAccounts: false,
onDidChangeSessions: onDidChangeSessions.event,
getSessions: async () => {
if (session) {
return [session];
} else {
return [];
}
},
login: async (scopeList: string[]) => {
session = {
id: 'sessionId',
accessToken: await che.github.getToken(),
account: {label: 'accountName1', id: 'accountId'},
scopes: scopeList
};
onDidChangeSessions.fire({added: [session.id], removed: [], changed: []});
return session;
},
logout: async (id: string) => {
session = undefined;
onDidChangeSessions.fire({added: [], removed: [id], changed: []});
}
}
);
}
}

Expand Down

0 comments on commit eb12fb9

Please sign in to comment.