This repository has been archived by the owner on Apr 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 111
Register GitHub Authentication provider for the vscode GitHub PR plugin #841
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
41c6c34
Register GitHub Authentication provider for the vscode Github PR plugin
vinokurig 987222e
fixup! Register GitHub Authentication provider for the vscode Github …
vinokurig d001946
fixup! Register GitHub Authentication provider for the vscode Github …
vinokurig 04b27e1
merge with master
vinokurig File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -164,4 +164,4 @@ | |
"path": "../examples/assembly/compile.tsconfig.json" | ||
} | ||
] | ||
} | ||
} | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,22 +11,54 @@ | |
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> { | ||
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'); | ||
})); | ||
let session: theia.AuthenticationSession | undefined = context.workspaceState.get('session'); | ||
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 (scopes: string[]) => { | ||
const githubUser = await che.github.getUser(); | ||
session = { | ||
id: 'github-session', | ||
accessToken: await che.github.getToken(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what happen on fresh install, I'm not sure che.github.getToken() or che.github.getUser() is returning something ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In this case the GitHub authentication page appears: |
||
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 (session) { | ||
onDidChangeSessions.fire({ added: [session.id], removed: [], changed: [] }); | ||
// TODO Remove the notification when https://github.com/eclipse-theia/theia/issues/7178 is fixed. | ||
} else { | ||
const signIn = 'Sign in'; | ||
const result = await theia.window.showInformationMessage( | ||
'In order to use the Pull Requests functionality, you must sign in to GitHub', | ||
signIn); | ||
|
||
if (result === signIn) { | ||
theia.authentication.getSession('github', ['read:user', 'user:email', 'repo'], { createIfNone: true }); | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please, revert it to have the checks passed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, thank you!