Skip to content

Commit 61f3569

Browse files
authored
Merge pull request #112 from github/joshmgross/sign-in-sidebar
Add sign in experience to extension activity bar
2 parents 8f27ba5 + 9cf173b commit 61f3569

4 files changed

Lines changed: 70 additions & 14 deletions

File tree

package.json

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,24 +241,42 @@
241241
"category": "GitHub Actions",
242242
"title": "Unpin workflow",
243243
"icon": "$(pinned)"
244+
},
245+
{
246+
"command": "github-actions.sign-in",
247+
"title": "Sign in to GitHub"
244248
}
245249
],
246250
"views": {
247251
"github-actions": [
248252
{
249253
"id": "github-actions.current-branch",
250-
"name": "Current Branch"
254+
"name": "Current Branch",
255+
"when": "github-actions.signed-in"
251256
},
252257
{
253258
"id": "github-actions.workflows",
254-
"name": "Workflows"
259+
"name": "Workflows",
260+
"when": "github-actions.signed-in"
255261
},
256262
{
257263
"id": "github-actions.settings",
258-
"name": "Settings"
264+
"name": "Settings",
265+
"when": "github-actions.signed-in"
266+
},
267+
{
268+
"id": "github-actions.empty-view",
269+
"name": "",
270+
"when": "!github-actions.signed-in"
259271
}
260272
]
261273
},
274+
"viewsWelcome": [
275+
{
276+
"view": "github-actions.empty-view",
277+
"contents": "Sign in to GitHub to display runs, workflows, and configure Actions settings\n[Sign in to GitHub](command:github-actions.sign-in)"
278+
}
279+
],
262280
"viewsContainers": {
263281
"activitybar": [
264282
{
@@ -440,6 +458,10 @@
440458
{
441459
"command": "github-actions.workflow.unpin",
442460
"when": "false"
461+
},
462+
{
463+
"command": "github-actions.sign-in",
464+
"when": "false"
443465
}
444466
]
445467
}

src/auth/auth.ts

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,37 @@ export async function newSession(forceMessage: string): Promise<vscode.Authentic
2424
* Retrieves a session from the GitHub authentication provider or prompts the user to sign in
2525
* @returns A {@link vscode.AuthenticationSession} or undefined
2626
*/
27-
export async function getSession(): Promise<vscode.AuthenticationSession | undefined> {
28-
const session = await getSessionInternal(false);
29-
if (session || signInPrompted) {
27+
export async function getSession(skipPrompt = false): Promise<vscode.AuthenticationSession | undefined> {
28+
const session = await getSessionInternal(skipPrompt);
29+
if (session) {
30+
await vscode.commands.executeCommand("setContext", "github-actions.signed-in", true);
3031
return session;
3132
}
3233

34+
if (signInPrompted || skipPrompt) {
35+
return undefined;
36+
}
37+
3338
signInPrompted = true;
3439
const signInAction = "Sign in to GitHub";
35-
const result = await vscode.window.showInformationMessage(
36-
"Sign in to GitHub to access your repositories and GitHub Actions workflows.",
37-
signInAction
38-
);
39-
if (result === signInAction) {
40-
return await getSessionInternal(true);
41-
}
42-
throw new Error(SESSION_ERROR);
40+
vscode.window
41+
.showInformationMessage("Sign in to GitHub to access your repositories and GitHub Actions workflows.", signInAction)
42+
.then(
43+
async result => {
44+
if (result === signInAction) {
45+
const session = await getSessionInternal(true);
46+
if (session) {
47+
await vscode.commands.executeCommand("setContext", "github-actions.signed-in", true);
48+
}
49+
}
50+
},
51+
() => {
52+
// Ignore rejected promise
53+
}
54+
);
55+
56+
// User chose to not sign in or hasn't signed in yet
57+
return undefined;
4358
}
4459

4560
async function getSessionInternal(forceNewMessage: string): Promise<vscode.AuthenticationSession | undefined>;

src/commands/signIn.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import * as vscode from "vscode";
2+
import {getSession} from "../auth/auth";
3+
4+
export function registerSignIn(context: vscode.ExtensionContext) {
5+
context.subscriptions.push(
6+
vscode.commands.registerCommand("github-actions.sign-in", async () => {
7+
const session = await getSession(true);
8+
if (session) {
9+
await vscode.commands.executeCommand("setContext", "github-actions.signed-in", true);
10+
}
11+
})
12+
);
13+
}

src/extension.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,16 @@ import {initWorkspaceChangeTracker} from "./tracker/workspaceTracker";
3030
import {initResources} from "./treeViews/icons";
3131
import {initTreeViews} from "./treeViews/treeViews";
3232
import {deactivateLanguageServer, initLanguageServer} from "./workflow/languageServer";
33+
import {registerSignIn} from "./commands/signIn";
3334

3435
export async function activate(context: vscode.ExtensionContext) {
3536
initLogger();
3637

3738
log("Activating GitHub Actions extension...");
3839

40+
// Set signed-in context before other initializations use the session
41+
await vscode.commands.executeCommand("setContext", "github-actions.signed-in", false);
42+
3943
// Prefetch git repository origin url
4044
await getGitHubContext();
4145

@@ -75,6 +79,8 @@ export async function activate(context: vscode.ExtensionContext) {
7579
registerPinWorkflow(context);
7680
registerUnPinWorkflow(context);
7781

82+
registerSignIn(context);
83+
7884
// Log providers
7985
context.subscriptions.push(
8086
vscode.workspace.registerTextDocumentContentProvider(LogScheme, new WorkflowStepLogProvider())

0 commit comments

Comments
 (0)