Skip to content
This repository was archived by the owner on Mar 28, 2023. It is now read-only.

Commit 65f789a

Browse files
committed
Multi-repo tree view
1 parent 58b52d2 commit 65f789a

31 files changed

Lines changed: 807 additions & 698 deletions

src/auth/auth.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export async function getSession(): Promise<vscode.AuthenticationSession> {
2727

2828
if (!existingSession) {
2929
throw new Error(
30-
"Could not get token from the GitHub provider. \nPlease sign-in and allow access."
30+
"Could not get token from the GitHub authentication provider. \nPlease sign-in and allow access."
3131
);
3232
}
3333

src/extension.ts

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,18 @@
11
import * as vscode from "vscode";
2-
3-
import { GitHubContext, getGitHead, getGitHubContext } from "./git/repository";
4-
import {
5-
OrgSecret,
6-
RepoSecret,
7-
Workflow,
8-
WorkflowJob,
9-
WorkflowRun,
10-
WorkflowStep,
11-
} from "./model";
12-
import { getWorkflowUri, parseWorkflow } from "./workflow/workflow";
13-
14-
import { LogScheme } from "./logs/constants";
15-
import { SettingsTreeProvider } from "./treeViews/settings";
16-
import { WorkflowStepLogFoldingProvider } from "./logs/foldingProvider";
17-
import { WorkflowStepLogProvider } from "./logs/fileProvider";
18-
import { WorkflowStepLogSymbolProvider } from "./logs/symbolProvider";
19-
import { ActionsExplorerProvider as WorkflowsTreeProvider } from "./treeViews/workflows";
20-
import { buildLogURI } from "./logs/scheme";
21-
import { enableOrgFeatures } from "./auth/auth";
22-
import { encodeSecret } from "./secrets";
23-
import { getLogInfo } from "./logs/logInfoProvider";
24-
import { init } from "./workflow/diagnostics";
25-
import { initConfiguration } from "./configuration/configuration";
26-
import { initPinnedWorkflows } from "./pinnedWorkflows/pinnedWorkflows";
27-
import { initResources } from "./treeViews/icons";
2+
import { getGitHubContext } from "./git/repository";
283
import { initWorkflowDocumentTracking } from "./tracker/workflowDocumentTracker";
29-
import { updateDecorations } from "./logs/formatProvider";
4+
import { initResources } from "./treeViews/icons";
5+
import { SettingsTreeProvider } from "./treeViews/settings";
6+
import { WorkflowsTreeProvider } from "./treeViews/workflows";
307

318
export function activate(context: vscode.ExtensionContext) {
329
// Prefetch git repository origin url
3310
getGitHubContext();
3411

3512
initResources(context);
3613

37-
initConfiguration(context);
38-
initPinnedWorkflows(context);
14+
// initConfiguration(context);
15+
// initPinnedWorkflows(context);
3916

4017
// Track workflow
4118
initWorkflowDocumentTracking(context);
@@ -63,6 +40,8 @@ export function activate(context: vscode.ExtensionContext) {
6340
settingsTreeProvider.refresh();
6441
})
6542
);
43+
44+
/*
6645
context.subscriptions.push(
6746
vscode.commands.registerCommand(
6847
"github-actions.explorer.openRun",
@@ -519,4 +498,5 @@ export function activate(context: vscode.ExtensionContext) {
519498
// Editing features
520499
//
521500
init(context);
501+
*/
522502
}

src/git/repository.ts

Lines changed: 48 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { getClient } from "../api/api";
44
import { getSession } from "../auth/auth";
55
import { Protocol } from "../external/protocol";
66
import { API, GitExtension, RefType } from "../typings/git";
7-
import { flatten } from "../utils/array";
87

98
async function getGitExtension(): Promise<API | undefined> {
109
const gitExtension =
@@ -45,40 +44,41 @@ export async function getGitHead(): Promise<string | undefined> {
4544
}
4645
}
4746

48-
export async function getGitHubUrl(): Promise<string | null> {
47+
export async function getGitHubUrls(): Promise<string[] | null> {
4948
const git = await getGitExtension();
5049

5150
if (git && git.repositories.length > 0) {
52-
// To keep it very simple for now, look for the first remote in the current workspace that is a
53-
// github.com remote. This will be the repository for the workflow explorer.
54-
const originRemotes = flatten(
55-
git.repositories.map((r) =>
56-
r.state.remotes.filter((remote) => remote.name === "origin")
57-
)
58-
);
51+
return git.repositories
52+
.map((r) => {
53+
const originRemote = r.state.remotes.filter(
54+
(remote) => remote.name === "origin"
55+
);
56+
if (
57+
originRemote.length > 0 &&
58+
originRemote[0].pushUrl?.indexOf("github.com") !== -1
59+
) {
60+
return originRemote[0].pushUrl!;
61+
}
5962

60-
const githubRemotes = originRemotes.filter(
61-
(x) => x.pushUrl?.indexOf("github.com") !== -1
62-
);
63-
if (githubRemotes.length > 0) {
64-
return githubRemotes[0].pushUrl!;
65-
}
63+
return undefined;
64+
})
65+
.filter((x) => !!x) as string[];
6666
}
6767

6868
return null;
6969
}
7070

71-
export async function getGitHubProtocol(): Promise<Protocol | null> {
72-
const url = await getGitHubUrl();
71+
export async function getGitHubProtocols(): Promise<Protocol[] | null> {
72+
const urls = await getGitHubUrls();
7373

74-
if (url) {
75-
return new Protocol(url);
74+
if (urls) {
75+
return urls.map((url) => new Protocol(url));
7676
}
7777

7878
return null;
7979
}
8080

81-
export interface GitHubContext {
81+
export interface GitHubRepoContext {
8282
client: Octokit;
8383

8484
id: number;
@@ -91,20 +91,28 @@ export interface GitHubContext {
9191
orgFeaturesEnabled?: boolean;
9292
}
9393

94+
export interface GitHubContext {
95+
repos: GitHubRepoContext[];
96+
}
97+
9498
let gitHubContext: Promise<GitHubContext | undefined> | undefined;
9599

96100
export async function getGitHubContext(): Promise<GitHubContext | undefined> {
97-
if (!gitHubContext) {
98-
gitHubContext = (async (): Promise<GitHubContext | undefined> => {
99-
try {
100-
const session = await getSession();
101-
102-
const protocolInfo = await getGitHubProtocol();
103-
if (!protocolInfo) {
104-
return undefined;
105-
}
101+
if (gitHubContext) {
102+
return gitHubContext;
103+
}
104+
105+
try {
106+
const session = await getSession();
107+
const client = getClient(session.accessToken);
108+
109+
const protocolInfos = await getGitHubProtocols();
110+
if (!protocolInfos) {
111+
return undefined;
112+
}
106113

107-
const client = getClient(session.accessToken);
114+
const repos = await Promise.all(
115+
protocolInfos.map(async (protocolInfo): Promise<GitHubRepoContext> => {
108116
const repoInfo = await client.repos.get({
109117
repo: protocolInfo.repositoryName,
110118
owner: protocolInfo.owner,
@@ -121,14 +129,16 @@ export async function getGitHubContext(): Promise<GitHubContext | undefined> {
121129
session.scopes.find((x) => x.toLocaleLowerCase() === "admin:org") !=
122130
null,
123131
};
124-
} catch (e) {
125-
// Reset the context so the next attempt will try this flow again
126-
gitHubContext = undefined;
127-
128-
// Rethrow original error
129-
throw e;
130-
}
131-
})();
132+
})
133+
);
134+
135+
gitHubContext = Promise.resolve({ repos });
136+
} catch (e) {
137+
// Reset the context so the next attempt will try this flow again
138+
gitHubContext = undefined;
139+
140+
// Rethrow original error
141+
throw e;
132142
}
133143

134144
return gitHubContext;

src/logs/fileProvider.ts

Lines changed: 40 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,49 @@
11
import * as vscode from "vscode";
22

3-
import { cacheLogInfo } from "./logInfoProvider";
4-
import { getGitHubContext } from "../git/repository";
5-
import { parseLog } from "./model";
6-
import { parseUri } from "./scheme";
7-
83
export class WorkflowStepLogProvider
9-
implements vscode.TextDocumentContentProvider {
4+
implements vscode.TextDocumentContentProvider
5+
{
106
onDidChangeEmitter = new vscode.EventEmitter<vscode.Uri>();
117
onDidChange = this.onDidChangeEmitter.event;
128

139
async provideTextDocumentContent(uri: vscode.Uri): Promise<string> {
14-
const { owner, repo, jobId } = parseUri(uri);
15-
16-
const githubContext = await getGitHubContext();
17-
if (!githubContext) {
18-
throw new Error("Could not load logs");
19-
}
20-
21-
try {
22-
const result = await githubContext?.client.actions.downloadJobLogsForWorkflowRun(
23-
{
24-
owner: owner,
25-
repo: repo,
26-
job_id: jobId,
27-
}
28-
);
29-
30-
const log = result.data as any;
31-
32-
const logInfo = parseLog(log);
33-
cacheLogInfo(uri, logInfo);
34-
35-
return logInfo.updatedLog;
36-
} catch (e) {
37-
if ("status" in e && e.status === 410) {
38-
cacheLogInfo(uri, {
39-
colorFormats: [],
40-
sections: [],
41-
updatedLog: "",
42-
});
43-
44-
return "Could not open logs, they are expired.";
45-
}
46-
47-
console.error("Error loading logs", e);
48-
return `Could not open logs, unhandled error: ${e?.message || e}`;
49-
}
10+
// const { owner, repo, jobId } = parseUri(uri);
11+
12+
// const githubContext = await getGitHubContext();
13+
// if (!githubContext) {
14+
// throw new Error("Could not load logs");
15+
// }
16+
17+
// try {
18+
// const result = await githubContext?.client.actions.downloadJobLogsForWorkflowRun(
19+
// {
20+
// owner: owner,
21+
// repo: repo,
22+
// job_id: jobId,
23+
// }
24+
// );
25+
26+
// const log = result.data as any;
27+
28+
// const logInfo = parseLog(log);
29+
// cacheLogInfo(uri, logInfo);
30+
31+
// return logInfo.updatedLog;
32+
// } catch (e) {
33+
// if ("status" in e && e.status === 410) {
34+
// cacheLogInfo(uri, {
35+
// colorFormats: [],
36+
// sections: [],
37+
// updatedLog: "",
38+
// });
39+
40+
// return "Could not open logs, they are expired.";
41+
// }
42+
43+
// console.error("Error loading logs", e);
44+
// return `Could not open logs, unhandled error: ${e?.message || e}`;
45+
// }
46+
47+
return "IMPLEMENT ME";
5048
}
5149
}

0 commit comments

Comments
 (0)