Skip to content

Commit 18fd7a8

Browse files
committed
Add sign in experience to extension activity bar
1 parent c824ef5 commit 18fd7a8

4 files changed

Lines changed: 50 additions & 6 deletions

File tree

package.json

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,24 +223,42 @@
223223
"category": "GitHub Actions",
224224
"title": "Unpin workflow",
225225
"icon": "$(pinned)"
226+
},
227+
{
228+
"command": "github-actions.sign-in",
229+
"title": "Sign in to GitHub"
226230
}
227231
],
228232
"views": {
229233
"github-actions": [
230234
{
231235
"id": "github-actions.current-branch",
232-
"name": "Current Branch"
236+
"name": "Current Branch",
237+
"when": "github-actions.signed-in"
233238
},
234239
{
235240
"id": "github-actions.workflows",
236-
"name": "Workflows"
241+
"name": "Workflows",
242+
"when": "github-actions.signed-in"
237243
},
238244
{
239245
"id": "github-actions.settings",
240-
"name": "Settings"
246+
"name": "Settings",
247+
"when": "github-actions.signed-in"
248+
},
249+
{
250+
"id": "github-actions.empty-view",
251+
"name": "Sign in to GitHub",
252+
"when": "!github-actions.signed-in"
241253
}
242254
]
243255
},
256+
"viewsWelcome": [
257+
{
258+
"view": "github-actions.empty-view",
259+
"contents": "Sign in to GitHub to display runs, workflows, and configure Actions settings\n[Sign in to GitHub](command:github-actions.sign-in)"
260+
}
261+
],
244262
"viewsContainers": {
245263
"activitybar": [
246264
{
@@ -422,6 +440,10 @@
422440
{
423441
"command": "github-actions.workflow.unpin",
424442
"when": "false"
443+
},
444+
{
445+
"command": "github-actions.sign-in",
446+
"when": "!github-actions.signed-in"
425447
}
426448
]
427449
}

src/auth/auth.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,17 @@ 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";
3540
vscode.window

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: 4 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+
await vscode.commands.executeCommand("setContext", "github-actions.signed-in", false);
41+
registerSignIn(context);
42+
3943
// Prefetch git repository origin url
4044
await getGitHubContext();
4145

0 commit comments

Comments
 (0)