Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,12 @@
"when": "viewItem =~ /run/",
"icon": "$(globe)"
},
{
"command": "github-actions.workflow.run.importAnnotations",
"category": "GitHub Actions",
"title": "Import workflow run annotations",
"when": "viewItem =~ /run/"
},
{
"command": "github-actions.workflow.logs",
"category": "GitHub Actions",
Expand Down
30 changes: 30 additions & 0 deletions src/annotations/workflowRunAnnotations.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import {toDiagnosticAnnotation} from "./workflowRunAnnotations";

describe("toDiagnosticAnnotation", () => {
it.each([
["failure", "error"],
["warning", "warning"],
["notice", "information"]
] as const)("maps %s annotations to %s diagnostics", (annotation_level, severity) => {
expect(
toDiagnosticAnnotation({
annotation_level,
end_column: 8,
end_line: 4,
message: "Expected a value",
path: "src/index.ts",
start_column: 2,
start_line: 3,
title: "Type check"
})
).toEqual({
endColumn: 8,
endLine: 4,
message: "Type check: Expected a value",
path: "src/index.ts",
severity,
startColumn: 2,
startLine: 3
});
});
});
39 changes: 39 additions & 0 deletions src/annotations/workflowRunAnnotations.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
export interface WorkflowRunAnnotation {
annotation_level: "failure" | "warning" | "notice";
end_column: number;
end_line: number;
message: string;
path: string;
start_column: number;
start_line: number;
title: string;
}

export type AnnotationSeverity = "error" | "warning" | "information";

export interface DiagnosticAnnotation {
endColumn: number;
endLine: number;
message: string;
path: string;
severity: AnnotationSeverity;
startColumn: number;
startLine: number;
}

export function toDiagnosticAnnotation(annotation: WorkflowRunAnnotation): DiagnosticAnnotation {
return {
path: annotation.path,
startLine: annotation.start_line,
startColumn: annotation.start_column,
endLine: annotation.end_line,
endColumn: annotation.end_column,
message: annotation.title ? `${annotation.title}: ${annotation.message}` : annotation.message,
severity:
annotation.annotation_level === "failure"
? "error"
: annotation.annotation_level === "warning"
? "warning"
: "information"
};
}
53 changes: 53 additions & 0 deletions src/commands/importWorkflowRunAnnotations.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import * as vscode from "vscode";
import {toDiagnosticAnnotation} from "../annotations/workflowRunAnnotations";
import {WorkflowRunCommandArgs} from "../treeViews/shared/workflowRunNode";

const diagnostics = vscode.languages.createDiagnosticCollection("github-actions");

export function registerImportWorkflowRunAnnotations(context: vscode.ExtensionContext) {
context.subscriptions.push(diagnostics);
context.subscriptions.push(
vscode.commands.registerCommand(
"github-actions.workflow.run.importAnnotations",
async (args: WorkflowRunCommandArgs) => {
const {gitHubRepoContext, run} = args;
const annotations = await gitHubRepoContext.client.paginate(
"GET /repos/{owner}/{repo}/actions/runs/{run_id}/annotations",
{
owner: gitHubRepoContext.owner,
repo: gitHubRepoContext.name,
run_id: run.run.id,
per_page: 100
}
);

const byUri = new Map<string, vscode.Diagnostic[]>();
for (const annotation of annotations) {
const diagnostic = toDiagnosticAnnotation(annotation);
const range = new vscode.Range(
new vscode.Position(Math.max(diagnostic.startLine - 1, 0), Math.max(diagnostic.startColumn - 1, 0)),
new vscode.Position(Math.max(diagnostic.endLine - 1, 0), Math.max(diagnostic.endColumn - 1, 0))
);
const item = new vscode.Diagnostic(
range,
diagnostic.message,
diagnostic.severity === "error"
? vscode.DiagnosticSeverity.Error
: diagnostic.severity === "warning"
? vscode.DiagnosticSeverity.Warning
: vscode.DiagnosticSeverity.Information
);
item.source = "GitHub Actions";
const uri = vscode.Uri.joinPath(gitHubRepoContext.workspaceUri, diagnostic.path).toString();
byUri.set(uri, [...(byUri.get(uri) ?? []), item]);
}

diagnostics.clear();
for (const [uri, items] of byUri) {
diagnostics.set(vscode.Uri.parse(uri), items);
}
void vscode.window.showInformationMessage(`Imported ${annotations.length} workflow run annotation(s).`);
}
)
);
}
2 changes: 2 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {initTreeViews} from "./treeViews/treeViews";
import {deactivateLanguageServer, initLanguageServer} from "./workflow/languageServer";
import {registerSignIn} from "./commands/signIn";
import {registerDebugger, registerDebuggerAvailabilityGuard} from "./debugger/debugger";
import {registerImportWorkflowRunAnnotations} from "./commands/importWorkflowRunAnnotations";

export async function activate(context: vscode.ExtensionContext) {
initLogger();
Expand Down Expand Up @@ -78,6 +79,7 @@ export async function activate(context: vscode.ExtensionContext) {
registerTriggerWorkflowRun(context);
registerReRunWorkflowRun(context);
registerCancelWorkflowRun(context);
registerImportWorkflowRunAnnotations(context);

registerAddSecret(context);
registerDeleteSecret(context);
Expand Down