Skip to content

Commit 08c7fbf

Browse files
committed
Add open step logs command
1 parent 0ff1a03 commit 08c7fbf

3 files changed

Lines changed: 76 additions & 0 deletions

File tree

package.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,16 @@
147147
"light": "resources/icons/light/logs.svg"
148148
}
149149
},
150+
{
151+
"command": "github-actions.step.logs",
152+
"category": "GitHub Actions",
153+
"title": "View logs",
154+
"when": "viewItem =~ /step/",
155+
"icon": {
156+
"dark": "resources/icons/dark/logs.svg",
157+
"light": "resources/icons/light/logs.svg"
158+
}
159+
},
150160
{
151161
"command": "github-actions.workflow.run.rerun",
152162
"category": "GitHub Actions",
@@ -363,6 +373,11 @@
363373
"group": "inline",
364374
"when": "viewItem =~ /job/ && viewItem =~ /completed/"
365375
},
376+
{
377+
"command": "github-actions.step.logs",
378+
"group": "inline",
379+
"when": "viewItem =~ /step/ && viewItem =~ /completed/"
380+
},
366381
{
367382
"command": "github-actions.workflow.run.cancel",
368383
"when": "viewItem =~ /run/ && viewItem =~ /cancelable/"
@@ -438,6 +453,10 @@
438453
"command": "github-actions.workflow.logs",
439454
"when": "false"
440455
},
456+
{
457+
"command": "github-actions.step.logs",
458+
"when": "false"
459+
},
441460
{
442461
"command": "github-actions.workflow.run.rerun",
443462
"when": "false"
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import * as vscode from "vscode";
2+
import {GitHubRepoContext} from "../git/repository";
3+
import {updateDecorations} from "../logs/formatProvider";
4+
import {getLogInfo} from "../logs/logInfo";
5+
import {buildLogURI} from "../logs/scheme";
6+
import {WorkflowJob} from "../store/WorkflowJob";
7+
import { WorkflowStep } from "../model";
8+
9+
export interface OpenWorkflowStepLogsCommandArgs {
10+
gitHubRepoContext: GitHubRepoContext;
11+
job: WorkflowJob;
12+
step: WorkflowStep;
13+
}
14+
15+
export function registerOpenWorkflowStepLogs(context: vscode.ExtensionContext) {
16+
context.subscriptions.push(
17+
vscode.commands.registerCommand("github-actions.step.logs", async (args: OpenWorkflowStepLogsCommandArgs) => {
18+
const gitHubRepoContext = args.gitHubRepoContext;
19+
const job = args.job;
20+
const step = args.step;
21+
22+
const uri = buildLogURI(
23+
`%23${job.job.run_id} - ${job.job.name}`,
24+
gitHubRepoContext.owner,
25+
gitHubRepoContext.name,
26+
job.job.id
27+
);
28+
29+
const doc = await vscode.workspace.openTextDocument(uri);
30+
const editor = await vscode.window.showTextDocument(doc, {
31+
preview: false
32+
});
33+
34+
const logInfo = getLogInfo(uri);
35+
if (!logInfo) {
36+
throw new Error("Could not get log info");
37+
}
38+
39+
const section = logInfo.sections.find(s => s.name === step.name);
40+
const startLine = section ? section.start : 0;
41+
const endLine = section ? section.end : 0;
42+
43+
44+
const stepInfo = {
45+
updatedLogLines: logInfo["updatedLogLines"].slice(startLine, endLine),
46+
sections: logInfo["sections"].filter(s => s.name === step.name),
47+
styleFormats: logInfo["styleFormats"].filter(s => s.line >= startLine && s.line <= endLine)
48+
};
49+
50+
51+
// Custom formatting after the editor has been opened
52+
updateDecorations(editor, stepInfo);
53+
})
54+
);
55+
}

src/extension.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {getSession} from "./auth/auth";
55
import {registerCancelWorkflowRun} from "./commands/cancelWorkflowRun";
66
import {registerOpenWorkflowFile} from "./commands/openWorkflowFile";
77
import {registerOpenWorkflowJobLogs} from "./commands/openWorkflowJobLogs";
8+
import {registerOpenWorkflowStepLogs} from "./commands/openWorkflowStepLogs";
89
import {registerOpenWorkflowRun} from "./commands/openWorkflowRun";
910
import {registerPinWorkflow} from "./commands/pinWorkflow";
1011
import {registerReRunWorkflowRun} from "./commands/rerunWorkflowRun";
@@ -71,6 +72,7 @@ export async function activate(context: vscode.ExtensionContext) {
7172
registerOpenWorkflowRun(context);
7273
registerOpenWorkflowFile(context);
7374
registerOpenWorkflowJobLogs(context);
75+
registerOpenWorkflowStepLogs(context);
7476
registerTriggerWorkflowRun(context);
7577
registerReRunWorkflowRun(context);
7678
registerCancelWorkflowRun(context);

0 commit comments

Comments
 (0)