-
Notifications
You must be signed in to change notification settings - Fork 174
Expand file tree
/
Copy pathtreeViews.ts
More file actions
83 lines (71 loc) · 3.11 KB
/
treeViews.ts
File metadata and controls
83 lines (71 loc) · 3.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import * as vscode from "vscode";
import {canReachGitHubAPI} from "../api/canReachGitHubAPI";
import {executeCacheClearCommand} from "../workflow/languageServer";
import {getGitHubContext} from "../git/repository";
import {logDebug} from "../log";
import {RunStore} from "../store/store";
import {CurrentBranchTreeProvider} from "./currentBranch";
import {SettingsTreeProvider} from "./settings";
import {WorkflowsTreeProvider} from "./workflows";
export async function initTreeViews(context: vscode.ExtensionContext, store: RunStore): Promise<void> {
const workflowTreeProvider = new WorkflowsTreeProvider(store);
const workflowTreeView = vscode.window.createTreeView("github-actions.workflows", {
treeDataProvider: workflowTreeProvider
});
context.subscriptions.push(workflowTreeView);
store.setViewVisible(workflowTreeView.visible);
context.subscriptions.push(
workflowTreeView.onDidChangeVisibility(e => {
store.setViewVisible(e.visible);
})
);
const settingsTreeProvider = new SettingsTreeProvider();
context.subscriptions.push(vscode.window.registerTreeDataProvider("github-actions.settings", settingsTreeProvider));
const currentBranchTreeProvider = new CurrentBranchTreeProvider(store);
context.subscriptions.push(
vscode.window.registerTreeDataProvider("github-actions.current-branch", currentBranchTreeProvider)
);
context.subscriptions.push(
vscode.commands.registerCommand("github-actions.explorer.refresh", async () => {
const canReachAPI = await canReachGitHubAPI();
await vscode.commands.executeCommand("setContext", "github-actions.internet-access", canReachAPI);
const ghContext = await getGitHubContext();
const hasGitHubRepos = ghContext && ghContext.repos.length > 0;
await vscode.commands.executeCommand("setContext", "github-actions.has-repos", hasGitHubRepos);
if (canReachAPI && hasGitHubRepos) {
await workflowTreeProvider.refresh();
await settingsTreeProvider.refresh();
}
await executeCacheClearCommand();
})
);
context.subscriptions.push(
vscode.commands.registerCommand("github-actions.explorer.current-branch.refresh", async () => {
await currentBranchTreeProvider.refresh();
})
);
const gitHubContext = await getGitHubContext();
if (!gitHubContext) {
logDebug("Could not register branch change event handler");
return;
}
for (const repo of gitHubContext.repos) {
if (!repo.repositoryState) {
continue;
}
let currentAhead = repo.repositoryState.HEAD?.ahead;
let currentHeadName = repo.repositoryState.HEAD?.name;
repo.repositoryState.onDidChange(async () => {
// When the current head/branch changes, or the number of commits ahead changes (which indicates
// a push), refresh the current-branch view
if (
repo.repositoryState?.HEAD?.name !== currentHeadName ||
(repo.repositoryState?.HEAD?.ahead || 0) < (currentAhead || 0)
) {
currentHeadName = repo.repositoryState?.HEAD?.name;
currentAhead = repo.repositoryState?.HEAD?.ahead;
await currentBranchTreeProvider.refresh();
}
});
}
}