Skip to content

Commit 181f1d9

Browse files
authored
Merge pull request #114 from github/joshmgross/error-experience
Improve experience when outside a GitHub repo
2 parents 61f3569 + 4c8be4c commit 181f1d9

4 files changed

Lines changed: 36 additions & 11 deletions

File tree

package.json

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -252,29 +252,40 @@
252252
{
253253
"id": "github-actions.current-branch",
254254
"name": "Current Branch",
255-
"when": "github-actions.signed-in"
255+
"when": "github-actions.internet-access && github-actions.signed-in && github-actions.has-repos"
256256
},
257257
{
258258
"id": "github-actions.workflows",
259259
"name": "Workflows",
260-
"when": "github-actions.signed-in"
260+
"when": "github-actions.internet-access && github-actions.signed-in && github-actions.has-repos"
261261
},
262262
{
263263
"id": "github-actions.settings",
264264
"name": "Settings",
265-
"when": "github-actions.signed-in"
265+
"when": "github-actions.internet-access && github-actions.signed-in && github-actions.has-repos"
266266
},
267267
{
268268
"id": "github-actions.empty-view",
269269
"name": "",
270-
"when": "!github-actions.signed-in"
270+
"when": "!github-actions.internet-access || !github-actions.signed-in || !github-actions.has-repos"
271271
}
272272
]
273273
},
274274
"viewsWelcome": [
275275
{
276276
"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)"
277+
"contents": "Unable to connect to the GitHub API, please check your internet connection.\n[Refresh](command:github-actions.explorer.refresh)",
278+
"when": "!github-actions.internet-access"
279+
},
280+
{
281+
"view": "github-actions.empty-view",
282+
"contents": "Sign in to GitHub to display runs, workflows, and configure Actions settings.\n[Sign in to GitHub](command:github-actions.sign-in)",
283+
"when": "github-actions.internet-access && !github-actions.signed-in"
284+
},
285+
{
286+
"view": "github-actions.empty-view",
287+
"contents": "No GitHub repositories found. Please open a folder that contains a GitHub repository.",
288+
"when": "github-actions.internet-access && github-actions.signed-in && !github-actions.has-repos"
278289
}
279290
],
280291
"viewsContainers": {

src/extension.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as vscode from "vscode";
22

3+
import {getSession} from "./auth/auth";
34
import {registerCancelWorkflowRun} from "./commands/cancelWorkflowRun";
45
import {registerOpenWorkflowFile} from "./commands/openWorkflowFile";
56
import {registerOpenWorkflowJobLogs} from "./commands/openWorkflowJobLogs";
@@ -31,17 +32,23 @@ import {initResources} from "./treeViews/icons";
3132
import {initTreeViews} from "./treeViews/treeViews";
3233
import {deactivateLanguageServer, initLanguageServer} from "./workflow/languageServer";
3334
import {registerSignIn} from "./commands/signIn";
35+
import {canReachGitHubAPI} from "./util";
3436

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

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

40-
// Set signed-in context before other initializations use the session
41-
await vscode.commands.executeCommand("setContext", "github-actions.signed-in", false);
42+
const canReachAPI = await canReachGitHubAPI();
43+
const hasSession = canReachAPI && !!(await getSession());
4244

4345
// Prefetch git repository origin url
44-
await getGitHubContext();
46+
const ghContext = hasSession && (await getGitHubContext());
47+
const hasGitHubRepos = ghContext && ghContext.repos.length > 0;
48+
49+
await vscode.commands.executeCommand("setContext", "github-actions.internet-access", canReachAPI);
50+
await vscode.commands.executeCommand("setContext", "github-actions.signed-in", hasSession);
51+
await vscode.commands.executeCommand("setContext", "github-actions.has-repos", hasGitHubRepos);
4552

4653
initResources(context);
4754
initConfiguration(context);

src/tracker/workspaceTracker.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ export function initWorkspaceChangeTracker(context: vscode.ExtensionContext) {
66
const onDidChangeWorkspaceFolders = async (event: vscode.WorkspaceFoldersChangeEvent) => {
77
if (event.added.length > 0 || event.removed.length > 0) {
88
resetGitHubContext();
9-
await getGitHubContext();
9+
const context = await getGitHubContext();
10+
const hasGitHubRepos = context && context.repos.length > 0;
11+
await vscode.commands.executeCommand("setContext", "github-actions.has-repos", hasGitHubRepos);
1012
}
1113
};
1214
context.subscriptions.push(vscode.workspace.onDidChangeWorkspaceFolders(onDidChangeWorkspaceFolders));

src/treeViews/treeViews.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {executeCacheClearCommand} from "../workflow/languageServer";
33
import {getGitHubContext} from "../git/repository";
44
import {logDebug} from "../log";
55
import {RunStore} from "../store/store";
6+
import {canReachGitHubAPI} from "../util";
67
import {CurrentBranchTreeProvider} from "./currentBranch";
78
import {SettingsTreeProvider} from "./settings";
89
import {WorkflowsTreeProvider} from "./workflows";
@@ -21,8 +22,12 @@ export async function initTreeViews(context: vscode.ExtensionContext, store: Run
2122

2223
context.subscriptions.push(
2324
vscode.commands.registerCommand("github-actions.explorer.refresh", async () => {
24-
await workflowTreeProvider.refresh();
25-
await settingsTreeProvider.refresh();
25+
const canReachAPI = await canReachGitHubAPI();
26+
await vscode.commands.executeCommand("setContext", "github-actions.internet-access", canReachAPI);
27+
if (canReachAPI) {
28+
await workflowTreeProvider.refresh();
29+
await settingsTreeProvider.refresh();
30+
}
2631
await executeCacheClearCommand();
2732
})
2833
);

0 commit comments

Comments
 (0)