Merge branch 'main' into cschleiden/events-without-default-types
This commit is contained in:
@@ -14,7 +14,7 @@ jobs:
|
||||
runs-on: [self-hosted]
|
||||
steps:
|
||||
- run: echo "Hello World"`;
|
||||
const result = await documentLinks(createDocument("test.yaml", input));
|
||||
const result = await documentLinks(createDocument("test.yaml", input), undefined);
|
||||
expect(result).toHaveLength(0);
|
||||
});
|
||||
|
||||
@@ -23,7 +23,7 @@ jobs:
|
||||
jobs:
|
||||
build:
|
||||
runs-on: [self-hosted]`;
|
||||
const result = await documentLinks(createDocument("test.yaml", input));
|
||||
const result = await documentLinks(createDocument("test.yaml", input), undefined);
|
||||
expect(result).toHaveLength(0);
|
||||
});
|
||||
|
||||
@@ -36,7 +36,7 @@ jobs:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v3
|
||||
- uses: github/codeql-action/init@v2`;
|
||||
const result = await documentLinks(createDocument("test.yaml", input));
|
||||
const result = await documentLinks(createDocument("test.yaml", input), undefined);
|
||||
expect(result).toEqual([
|
||||
{
|
||||
range: {
|
||||
@@ -82,4 +82,51 @@ jobs:
|
||||
}
|
||||
]);
|
||||
});
|
||||
|
||||
it("links for reusable local workflow", async () => {
|
||||
const input = `on: push
|
||||
jobs:
|
||||
build:
|
||||
uses: ./.github/workflows/reusable-workflow.yml`;
|
||||
const result = await documentLinks(createDocument("test.yaml", input), "file:///workspace/");
|
||||
expect(result).toEqual([
|
||||
{
|
||||
range: {
|
||||
end: {
|
||||
character: 51,
|
||||
line: 3
|
||||
},
|
||||
start: {
|
||||
character: 10,
|
||||
line: 3
|
||||
}
|
||||
},
|
||||
target: "file:///workspace/.github/workflows/reusable-workflow.yml"
|
||||
}
|
||||
]);
|
||||
});
|
||||
|
||||
it("links for reusable remote workflow", async () => {
|
||||
const input = `on: push
|
||||
jobs:
|
||||
build:
|
||||
uses: seismis-rainier/workflows/reusable-workflow.yml@main`;
|
||||
const result = await documentLinks(createDocument("test.yaml", input), "file:///workspace/");
|
||||
expect(result).toEqual([
|
||||
{
|
||||
range: {
|
||||
end: {
|
||||
character: 62,
|
||||
line: 3
|
||||
},
|
||||
start: {
|
||||
character: 10,
|
||||
line: 3
|
||||
}
|
||||
},
|
||||
target: "https://www.github.com/seismis-rainier/workflows/tree/main/reusable-workflow.yml",
|
||||
tooltip: "Open reusable workflow on GitHub"
|
||||
}
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
import {ErrorPolicy} from "@github/actions-workflow-parser/model/convert";
|
||||
import {isJob} from "@github/actions-workflow-parser/model/type-guards";
|
||||
import {isJob, isReusableWorkflowJob} from "@github/actions-workflow-parser/model/type-guards";
|
||||
import {File} from "@github/actions-workflow-parser/workflows/file";
|
||||
import {parseFileReference} from "@github/actions-workflow-parser/workflows/file-reference";
|
||||
import {TextDocument} from "vscode-languageserver-textdocument";
|
||||
import {DocumentLink} from "vscode-languageserver-types";
|
||||
import vscodeURI from "vscode-uri/lib/umd"; // work around issues with the vscode-uri package
|
||||
import {actionUrl, parseActionReference} from "./action";
|
||||
import {mapRange} from "./utils/range";
|
||||
import {fetchOrParseWorkflow, fetchOrConvertWorkflowTemplate} from "./utils/workflow-cache";
|
||||
import {fetchOrConvertWorkflowTemplate, fetchOrParseWorkflow} from "./utils/workflow-cache";
|
||||
|
||||
export async function documentLinks(document: TextDocument): Promise<DocumentLink[]> {
|
||||
export async function documentLinks(document: TextDocument, workspace: string | undefined): Promise<DocumentLink[]> {
|
||||
const file: File = {
|
||||
name: document.uri,
|
||||
content: document.getText()
|
||||
@@ -22,30 +24,61 @@ export async function documentLinks(document: TextDocument): Promise<DocumentLin
|
||||
errorPolicy: ErrorPolicy.TryConversion
|
||||
});
|
||||
|
||||
// Add links to referenced actions
|
||||
const actionLinks: DocumentLink[] = [];
|
||||
const links: DocumentLink[] = [];
|
||||
|
||||
for (const job of template?.jobs || []) {
|
||||
if (!job || !isJob(job)) {
|
||||
if (!job) {
|
||||
continue;
|
||||
}
|
||||
for (const step of job.steps || []) {
|
||||
if ("uses" in step) {
|
||||
const actionRef = parseActionReference(step.uses.value);
|
||||
if (!actionRef) {
|
||||
continue;
|
||||
|
||||
if (isJob(job)) {
|
||||
// Add links to referenced actions
|
||||
for (const step of job.steps || []) {
|
||||
if ("uses" in step) {
|
||||
const actionRef = parseActionReference(step.uses.value);
|
||||
if (!actionRef) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const url = actionUrl(actionRef);
|
||||
|
||||
links.push({
|
||||
range: mapRange(step.uses.range),
|
||||
target: url,
|
||||
tooltip: `Open action on GitHub`
|
||||
});
|
||||
}
|
||||
}
|
||||
} else if (isReusableWorkflowJob(job)) {
|
||||
// Add links to referenced reusable workflows
|
||||
const ref = parseFileReference(job.ref.value);
|
||||
if ("repository" in ref) {
|
||||
// Remote workflow
|
||||
const url = actionUrl({
|
||||
owner: ref.owner,
|
||||
name: ref.repository,
|
||||
path: ref.path,
|
||||
ref: ref.version
|
||||
});
|
||||
|
||||
const url = actionUrl(actionRef);
|
||||
|
||||
actionLinks.push({
|
||||
range: mapRange(step.uses.range),
|
||||
links.push({
|
||||
range: mapRange(job.ref.range),
|
||||
target: url,
|
||||
tooltip: `Open action on GitHub`
|
||||
tooltip: `Open reusable workflow on GitHub`
|
||||
});
|
||||
} else if (workspace) {
|
||||
// We need workspace information to generate this link
|
||||
// Local workflow, generate workspace link
|
||||
const workspaceURI = vscodeURI.URI.parse(workspace);
|
||||
const refURI = vscodeURI.Utils.joinPath(workspaceURI, job.ref.value);
|
||||
|
||||
links.push({
|
||||
range: mapRange(job.ref.range),
|
||||
target: refURI.toString()
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return [...actionLinks];
|
||||
return [...links];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user