Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@
"viewsWelcome": [
{
"view": "github-actions.empty-view",
"contents": "Sign in to GitHub to display runs, workflows, and configure Actions settings.\n[Sign in to GitHub](command:github-actions.sign-in)",
"contents": "Sign in to GitHub to display runs, workflows, and configure Actions settings.\n[Sign in to GitHub](command:sign-in)",
"when": "!github-actions.signed-in"
},
{
Expand Down
7 changes: 2 additions & 5 deletions src/commands/signIn.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import * as vscode from "vscode";
import {getSession} from "../auth/auth";
import {setViewContexts} from "../viewContexts";

export function registerSignIn(context: vscode.ExtensionContext) {
context.subscriptions.push(
vscode.commands.registerCommand("github-actions.sign-in", async () => {
const session = await getSession(true);
if (session) {
await vscode.commands.executeCommand("setContext", "github-actions.signed-in", true);
}
await setViewContexts();
})
);
}
17 changes: 2 additions & 15 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import * as vscode from "vscode";

import {canReachGitHubAPI} from "./api/canReachGitHubAPI";
import {getSession} from "./auth/auth";
import {registerCancelWorkflowRun} from "./commands/cancelWorkflowRun";
import {registerOpenWorkflowFile} from "./commands/openWorkflowFile";
import {registerOpenWorkflowJobLogs} from "./commands/openWorkflowJobLogs";
Expand All @@ -19,7 +17,6 @@ import {registerCopyVariable} from "./commands/variables/copyVariable";
import {registerDeleteVariable} from "./commands/variables/deleteVariable";
import {registerUpdateVariable} from "./commands/variables/updateVariable";
import {initConfiguration} from "./configuration/configuration";
import {getGitHubContext} from "./git/repository";
import {init as initLogger, log, revealLog} from "./log";
import {LogScheme} from "./logs/constants";
import {WorkflowStepLogProvider} from "./logs/fileProvider";
Expand All @@ -33,24 +30,14 @@ import {initResources} from "./treeViews/icons";
import {initTreeViews} from "./treeViews/treeViews";
import {deactivateLanguageServer, initLanguageServer} from "./workflow/languageServer";
import {registerSignIn} from "./commands/signIn";
import {setViewContexts} from "./viewContexts";

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

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

const hasSession = !!(await getSession());
const canReachAPI = hasSession && (await canReachGitHubAPI());

// Prefetch git repository origin url
const ghContext = hasSession && (await getGitHubContext());
const hasGitHubRepos = ghContext && ghContext.repos.length > 0;

await Promise.all([
vscode.commands.executeCommand("setContext", "github-actions.signed-in", hasSession),
vscode.commands.executeCommand("setContext", "github-actions.internet-access", canReachAPI),
vscode.commands.executeCommand("setContext", "github-actions.has-repos", hasGitHubRepos)
]);
await setViewContexts();

initResources(context);
initConfiguration(context);
Expand Down
8 changes: 4 additions & 4 deletions src/tracker/workspaceTracker.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import * as vscode from "vscode";

import {getGitHubContext, resetGitHubContext} from "../git/repository";
import {resetGitHubContext} from "../git/repository";
import {setViewContexts} from "../viewContexts";

export function initWorkspaceChangeTracker(context: vscode.ExtensionContext) {
const onDidChangeWorkspaceFolders = async (event: vscode.WorkspaceFoldersChangeEvent) => {
if (event.added.length > 0 || event.removed.length > 0) {
resetGitHubContext();
const context = await getGitHubContext();
const hasGitHubRepos = context && context.repos.length > 0;
await vscode.commands.executeCommand("setContext", "github-actions.has-repos", hasGitHubRepos);

await setViewContexts();
}
};
context.subscriptions.push(vscode.workspace.onDidChangeWorkspaceFolders(onDidChangeWorkspaceFolders));
Expand Down
4 changes: 3 additions & 1 deletion src/treeViews/treeViews.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {RunStore} from "../store/store";
import {CurrentBranchTreeProvider} from "./currentBranch";
import {SettingsTreeProvider} from "./settings";
import {WorkflowsTreeProvider} from "./workflows";
import {setViewContexts} from "../viewContexts";

export async function initTreeViews(context: vscode.ExtensionContext, store: RunStore): Promise<void> {
const workflowTreeProvider = new WorkflowsTreeProvider(store);
Expand All @@ -23,8 +24,9 @@ export async function initTreeViews(context: vscode.ExtensionContext, store: Run

context.subscriptions.push(
vscode.commands.registerCommand("github-actions.explorer.refresh", async () => {
await setViewContexts();

const canReachAPI = await canReachGitHubAPI();
await vscode.commands.executeCommand("setContext", "github-actions.internet-access", canReachAPI);
if (canReachAPI) {
await workflowTreeProvider.refresh();
await settingsTreeProvider.refresh();
Expand Down
20 changes: 20 additions & 0 deletions src/viewContexts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import * as vscode from "vscode";
import {getSession} from "./auth/auth";
import {canReachGitHubAPI} from "./api/canReachGitHubAPI";
import {getGitHubContext} from "./git/repository";

export async function setViewContexts() {
// getSession() will setContext for github-actions.signed-in
const session = await getSession(true);

if (session) {
const canReachAPI = await canReachGitHubAPI();
const ghContext = await getGitHubContext();
const hasGitHubRepos = ghContext && ghContext.repos.length > 0;

await Promise.all([
vscode.commands.executeCommand("setContext", "github-actions.internet-access", canReachAPI),
vscode.commands.executeCommand("setContext", "github-actions.has-repos", hasGitHubRepos)
]);
}
}