Skip to content

Commit 34f691c

Browse files
committed
Wait for repositories get ready before looking for remotes
1 parent 7c3a17c commit 34f691c

13 files changed

Lines changed: 224 additions & 86 deletions

File tree

.vscode/launch.json

Lines changed: 8 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,23 @@
1-
// A launch configuration that compiles the extension and then opens it inside a new window
2-
// Use IntelliSense to learn about possible attributes.
3-
// Hover to view descriptions of existing attributes.
4-
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
51
{
62
"version": "0.2.0",
73
"configurations": [
84
{
9-
"name": "Run Extension",
5+
"name": "Watch & Launch Extension",
106
"type": "extensionHost",
117
"request": "launch",
12-
"runtimeExecutable": "${execPath}",
138
"args": [
14-
"--extensionDevelopmentPath=${workspaceFolder}"
15-
],
16-
"outFiles": [
17-
"${workspaceFolder}/dist/*.js"
9+
"--extensionDevelopmentPath=${workspaceFolder}",
1810
],
1911
"skipFiles": [
20-
"<node_internals>/**/*.js"
12+
"<node_internals>/**/*.js",
13+
"**/node_modules/**/*.js"
2114
],
22-
"resolveSourceMapLocations": [
23-
"dist/**/*.js",
24-
"node_modules/github-actions-parser/**/*.js",
25-
],
26-
// "preLaunchTask": "npm: watch",
15+
"preLaunchTask": "npm: watch",
2716
"smartStep": true,
28-
"sourceMaps": true
29-
},
30-
{
31-
"name": "Extension Tests",
32-
"type": "extensionHost",
33-
"request": "launch",
34-
"runtimeExecutable": "${execPath}",
35-
"args": [
36-
"--extensionDevelopmentPath=${workspaceFolder}",
37-
"--extensionTestsPath=${workspaceFolder}/out/test/suite/index"
38-
],
17+
"sourceMaps": true,
3918
"outFiles": [
40-
"${workspaceFolder}/dist/test/**/*.js"
41-
],
42-
"preLaunchTask": "${defaultBuildTask}"
19+
"${workspaceFolder}/dist/*.js"
20+
]
4321
}
4422
]
4523
}

.vscode/tasks.json

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,11 @@
66
{
77
"type": "npm",
88
"script": "watch",
9-
"presentation": {
10-
"echo": true,
11-
"reveal": "never",
12-
"focus": false,
13-
"panel": "shared",
14-
"showReuseMessage": true,
15-
"clear": false
16-
},
179
"group": "build",
1810
"isBackground": true,
19-
"problemMatcher": "$ts-webpack-watch"
11+
"problemMatcher": [
12+
"$ts-webpack-watch"
13+
],
2014
},
21-
{
22-
"type": "npm",
23-
"script": "ts-compile",
24-
"problemMatcher": "$tsc",
25-
"presentation": {
26-
"echo": true,
27-
"reveal": "never",
28-
"focus": false,
29-
"panel": "shared",
30-
"showReuseMessage": true,
31-
"clear": false
32-
},
33-
}
3415
]
3516
}

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -329,17 +329,17 @@
329329
},
330330
"scripts": {
331331
"clean": "rimraf ./dist ./out",
332-
"watch": "webpack --mode development --watch",
333332
"package": "npm run clean && vsce package",
334333
"build": "webpack --mode production",
335-
"vscode:prepublish": "npm run build"
334+
"vscode:prepublish": "npm run build",
335+
"watch": "webpack --watch --mode development --env esbuild --info-verbosity verbose"
336336
},
337337
"devDependencies": {
338338
"@types/glob": "^7.1.1",
339339
"@types/js-yaml": "^3.12.1",
340340
"@types/node": "14.14.32",
341341
"@types/uuid": "^3.4.6",
342-
"@types/vscode": "1.53.0",
342+
"@types/vscode": "1.63.1",
343343
"@types/yaml": "^1.2.0",
344344
"glob": "^7.1.5",
345345
"node-loader": "^0.6.0",

src/extension.ts

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

3+
import { init as initLogger, log } from "./log";
4+
35
import { LogScheme } from "./logs/constants";
46
import { SettingsTreeProvider } from "./treeViews/settings";
57
import { WorkflowStepLogFoldingProvider } from "./logs/foldingProvider";
@@ -28,6 +30,9 @@ import { registerUnPinWorkflow } from "./commands/unpinWorkflow";
2830
import { registerUpdateSecret } from "./commands/secrets/updateSecret";
2931

3032
export function activate(context: vscode.ExtensionContext) {
33+
initLogger();
34+
log("Activating GitHub Actions extension...");
35+
3136
// Prefetch git repository origin url
3237
getGitHubContext();
3338

@@ -118,4 +123,6 @@ export function activate(context: vscode.ExtensionContext) {
118123
// Editing features
119124
//
120125
init(context);
126+
127+
log("...initialized");
121128
}

src/git/repository.ts

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
import { Octokit } from "@octokit/rest";
21
import * as vscode from "vscode";
2+
3+
import { API, GitExtension, RefType } from "../typings/git";
4+
import { logDebug, logError } from "../log";
5+
6+
import { Octokit } from "@octokit/rest";
7+
import { Protocol } from "../external/protocol";
38
import { getClient } from "../api/api";
49
import { getSession } from "../auth/auth";
5-
import { Protocol } from "../external/protocol";
6-
import { API, GitExtension, RefType } from "../typings/git";
710

811
async function getGitExtension(): Promise<API | undefined> {
912
const gitExtension =
@@ -53,8 +56,13 @@ export async function getGitHubUrls(): Promise<
5356
> {
5457
const git = await getGitExtension();
5558
if (git && git.repositories.length > 0) {
56-
return git.repositories
57-
.map((r) => {
59+
logDebug("Found git extension");
60+
61+
const p = await Promise.all(
62+
git.repositories.map(async (r) => {
63+
logDebug("Find `origin` remote for repository", r.rootUri.path);
64+
await r.status();
65+
5866
// In the future we might make this configurable, but for now continue to look
5967
// for a remote named "origin".
6068
const originRemote = r.state.remotes.filter(
@@ -73,9 +81,12 @@ export async function getGitHubUrls(): Promise<
7381
};
7482
}
7583

84+
logDebug("No `origin` remote found, skipping repository");
85+
7686
return undefined;
7787
})
78-
.filter((x) => !!x) as any;
88+
);
89+
return p.filter((x) => !!x) as any;
7990
}
8091

8192
// If we cannot find the git extension, assume for now that we are running a web context,
@@ -140,11 +151,16 @@ export async function getGitHubContext(): Promise<GitHubContext | undefined> {
140151

141152
const protocolInfos = await getGitHubUrls();
142153
if (!protocolInfos) {
154+
logDebug("Could not get protocol infos");
143155
return undefined;
144156
}
145157

158+
logDebug("Found protocol infos", protocolInfos.length.toString());
159+
146160
const repos = await Promise.all(
147161
protocolInfos.map(async (protocolInfo): Promise<GitHubRepoContext> => {
162+
logDebug("Getting infos for repository", protocolInfo.url);
163+
148164
const repoInfo = await client.repos.get({
149165
repo: protocolInfo.protocol.repositoryName,
150166
owner: protocolInfo.protocol.owner,
@@ -169,10 +185,12 @@ export async function getGitHubContext(): Promise<GitHubContext | undefined> {
169185
repos,
170186
reposByUri: new Map(repos.map((r) => [r.workspaceUri.toString(), r])),
171187
});
172-
} catch (e) {
188+
} catch (e: any) {
173189
// Reset the context so the next attempt will try this flow again
174190
gitHubContext = undefined;
175191

192+
logError(e, "Error getting GitHub context");
193+
176194
// Rethrow original error
177195
throw e;
178196
}

src/log.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import * as vscode from "vscode";
2+
3+
enum LogLevel {
4+
Debug,
5+
Info,
6+
}
7+
8+
var logger: vscode.OutputChannel;
9+
var level: LogLevel = LogLevel.Debug;
10+
11+
export function init() {
12+
logger = vscode.window.createOutputChannel("GitHub Actions");
13+
}
14+
15+
export function log(...values: string[]) {
16+
logger.appendLine(values.join(" "));
17+
}
18+
19+
export function logDebug(...values: string[]) {
20+
if (level > LogLevel.Debug) {
21+
return;
22+
}
23+
24+
logger.appendLine(values.join(" "));
25+
}
26+
27+
export function logError(e: Error, ...values: string[]) {
28+
logger.appendLine(values.join(" "));
29+
logger.appendLine(e.message);
30+
if (e.stack) {
31+
logger.appendLine(e.stack);
32+
}
33+
}

src/pinnedWorkflows/pinnedWorkflows.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
1-
import { sep } from "path";
21
import * as vscode from "vscode";
2+
3+
import {
4+
GitHubRepoContext,
5+
getGitHubContextForWorkspaceUri,
6+
} from "../git/repository";
37
import {
48
getPinnedWorkflows,
59
isPinnedWorkflowsRefreshEnabled,
610
onPinnedWorkflowsChange,
711
pinnedWorkflowsRefreshInterval,
812
} from "../configuration/configuration";
9-
import {
10-
getGitHubContextForWorkspaceUri,
11-
GitHubRepoContext,
12-
} from "../git/repository";
13+
1314
import { WorkflowRun } from "../model";
1415
import { getCodIconForWorkflowrun } from "../treeViews/icons";
16+
import { sep } from "path";
1517

1618
interface PinnedWorkflow {
1719
/** Displayed name */
@@ -26,7 +28,7 @@ interface PinnedWorkflow {
2628
}
2729

2830
const pinnedWorkflows: PinnedWorkflow[] = [];
29-
let refreshTimer: NodeJS.Timeout | undefined;
31+
let refreshTimer: /*NodeJS.Timeout*/ any | undefined;
3032

3133
export async function initPinnedWorkflows(context: vscode.ExtensionContext) {
3234
// Register handler for configuration changes

src/treeViews/workflows.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
import * as vscode from "vscode";
2-
import { getGitHubContext } from "../git/repository";
2+
3+
import { log, logDebug, logError } from "../log";
4+
35
import { AuthenticationNode } from "./shared/authenticationNode";
46
import { ErrorNode } from "./shared/errorNode";
57
import { NoGitHubRepositoryNode } from "./shared/noGitHubRepositoryNode";
68
import { WorkflowJobNode } from "./workflows/workflowJobNode";
79
import { WorkflowNode } from "./workflows/workflowNode";
810
import { WorkflowRunNode } from "./workflows/workflowRunNode";
9-
import { WorkflowsRepoNode } from "./workflows/workflowsRepoNode";
1011
import { WorkflowStepNode } from "./workflows/workflowStepNode";
12+
import { WorkflowsRepoNode } from "./workflows/workflowsRepoNode";
13+
import { getGitHubContext } from "../git/repository";
1114

1215
type WorkflowsTreeNode =
1316
| AuthenticationNode
@@ -24,6 +27,7 @@ export class WorkflowsTreeProvider
2427
readonly onDidChangeTreeData = this._onDidChangeTreeData.event;
2528

2629
refresh(): void {
30+
logDebug("Refreshing workflow tree");
2731
this._onDidChangeTreeData.fire(null);
2832
}
2933

@@ -36,17 +40,25 @@ export class WorkflowsTreeProvider
3640
async getChildren(
3741
element?: WorkflowsTreeNode | undefined
3842
): Promise<WorkflowsTreeNode[]> {
43+
logDebug("Getting root children");
44+
3945
if (!element) {
4046
try {
4147
const gitHubContext = await getGitHubContext();
4248
if (!gitHubContext) {
49+
logDebug("could not get github context");
4350
return [];
4451
}
4552

4653
if (gitHubContext.repos.length > 0) {
4754
return gitHubContext.repos.map((r) => new WorkflowsRepoNode(r));
4855
}
49-
} catch (e) {
56+
57+
log("No GitHub repositories found");
58+
return [];
59+
} catch (e: any) {
60+
logError(e as Error, "Failed to get GitHub context");
61+
5062
if (
5163
`${e?.message}`.startsWith(
5264
"Could not get token from the GitHub authentication provider."

src/treeViews/workflows/workflowNode.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { Workflow } from "../../model";
66
import { WorkflowRunNode } from "./workflowRunNode";
77
import { getPinnedWorkflows } from "../../configuration/configuration";
88
import { getWorkflowUri } from "../../workflow/workflow";
9+
import { logDebug } from "../../log";
910

1011
export class WorkflowNode extends vscode.TreeItem {
1112
constructor(
@@ -47,6 +48,8 @@ export class WorkflowNode extends vscode.TreeItem {
4748
}
4849

4950
async getRuns(): Promise<WorkflowRunNode[]> {
51+
logDebug("Getting workflow runs");
52+
5053
const result = await this.gitHubRepoContext.client.actions.listWorkflowRuns(
5154
{
5255
owner: this.gitHubRepoContext.owner,

0 commit comments

Comments
 (0)