Wrap fetchActionsMetadata in provider checking sessionToken
This commit is contained in:
@@ -26,7 +26,7 @@ import {getFileProvider} from "./file-provider";
|
|||||||
import {InitializationOptions, RepositoryContext} from "./initializationOptions";
|
import {InitializationOptions, RepositoryContext} from "./initializationOptions";
|
||||||
import {onCompletion} from "./on-completion";
|
import {onCompletion} from "./on-completion";
|
||||||
import {ReadFileRequest, Requests} from "./request";
|
import {ReadFileRequest, Requests} from "./request";
|
||||||
import {fetchActionMetadata} from "./utils/action-metadata";
|
import {getActionsMetadataProvider} from "./utils/action-metadata";
|
||||||
import {TTLCache} from "./utils/cache";
|
import {TTLCache} from "./utils/cache";
|
||||||
import {timeOperation} from "./utils/timer";
|
import {timeOperation} from "./utils/timer";
|
||||||
import {valueProviders} from "./value-providers";
|
import {valueProviders} from "./value-providers";
|
||||||
@@ -108,13 +108,7 @@ export function initConnection(connection: Connection) {
|
|||||||
const config: ValidationConfig = {
|
const config: ValidationConfig = {
|
||||||
valueProviderConfig: valueProviders(client, repoContext, cache),
|
valueProviderConfig: valueProviders(client, repoContext, cache),
|
||||||
contextProviderConfig: contextProviders(client, repoContext, cache),
|
contextProviderConfig: contextProviders(client, repoContext, cache),
|
||||||
fetchActionMetadata: async action => {
|
actionsMetadataProvider: getActionsMetadataProvider(client, cache),
|
||||||
if (client) {
|
|
||||||
return await fetchActionMetadata(client, cache, action);
|
|
||||||
}
|
|
||||||
|
|
||||||
return undefined;
|
|
||||||
},
|
|
||||||
fileProvider: getFileProvider(client, cache, repoContext?.workspaceUri, async path => {
|
fileProvider: getFileProvider(client, cache, repoContext?.workspaceUri, async path => {
|
||||||
return await connection.sendRequest(Requests.ReadFile, {path} satisfies ReadFileRequest);
|
return await connection.sendRequest(Requests.ReadFile, {path} satisfies ReadFileRequest);
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,10 +1,24 @@
|
|||||||
import {actionIdentifier, ActionMetadata, ActionReference} from "@actions/languageservice/action";
|
import {actionIdentifier, ActionMetadata, ActionReference} from "@actions/languageservice/action";
|
||||||
|
import {ActionsMetadataProvider} from "@actions/languageservice";
|
||||||
import {error} from "@actions/languageservice/log";
|
import {error} from "@actions/languageservice/log";
|
||||||
import {Octokit, RestEndpointMethodTypes} from "@octokit/rest";
|
import {Octokit, RestEndpointMethodTypes} from "@octokit/rest";
|
||||||
import {parse} from "yaml";
|
import {parse} from "yaml";
|
||||||
import {TTLCache} from "./cache";
|
import {TTLCache} from "./cache";
|
||||||
import {errorMessage, errorStatus} from "./error";
|
import {errorMessage, errorStatus} from "./error";
|
||||||
|
|
||||||
|
export function getActionsMetadataProvider(
|
||||||
|
client: Octokit | undefined,
|
||||||
|
cache: TTLCache
|
||||||
|
): ActionsMetadataProvider | undefined {
|
||||||
|
if (!client) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
fetchActionMetadata: async action => fetchActionMetadata(client, cache, action)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
export async function fetchActionMetadata(
|
export async function fetchActionMetadata(
|
||||||
client: Octokit,
|
client: Octokit,
|
||||||
cache: TTLCache,
|
cache: TTLCache,
|
||||||
|
|||||||
@@ -3,5 +3,5 @@ export {ContextProviderConfig} from "./context-providers/config";
|
|||||||
export {documentLinks} from "./document-links";
|
export {documentLinks} from "./document-links";
|
||||||
export {hover} from "./hover";
|
export {hover} from "./hover";
|
||||||
export {Logger, LogLevel, registerLogger, setLogLevel} from "./log";
|
export {Logger, LogLevel, registerLogger, setLogLevel} from "./log";
|
||||||
export {validate, ValidationConfig} from "./validate";
|
export {validate, ValidationConfig, ActionsMetadataProvider} from "./validate";
|
||||||
export {ValueProviderConfig, ValueProviderKind} from "./value-providers/config";
|
export {ValueProviderConfig, ValueProviderKind} from "./value-providers/config";
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ export async function validateAction(
|
|||||||
step: Step | undefined,
|
step: Step | undefined,
|
||||||
config: ValidationConfig | undefined
|
config: ValidationConfig | undefined
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
if (!isMapping(stepToken) || !step || !isActionStep(step) || !config?.fetchActionMetadata) {
|
if (!isMapping(stepToken) || !step || !isActionStep(step) || !config?.actionsMetadataProvider) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -23,7 +23,7 @@ export async function validateAction(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const actionMetadata = await config.fetchActionMetadata(action);
|
const actionMetadata = await config.actionsMetadataProvider.fetchActionMetadata(action);
|
||||||
if (actionMetadata === undefined) {
|
if (actionMetadata === undefined) {
|
||||||
diagnostics.push({
|
diagnostics.push({
|
||||||
severity: DiagnosticSeverity.Error,
|
severity: DiagnosticSeverity.Error,
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ beforeEach(() => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const validationConfig: ValidationConfig = {
|
const validationConfig: ValidationConfig = {
|
||||||
|
actionsMetadataProvider: {
|
||||||
fetchActionMetadata: (ref: ActionReference) => {
|
fetchActionMetadata: (ref: ActionReference) => {
|
||||||
let metadata: ActionMetadata | undefined = undefined;
|
let metadata: ActionMetadata | undefined = undefined;
|
||||||
switch (ref.owner + "/" + ref.name + "@" + ref.ref) {
|
switch (ref.owner + "/" + ref.name + "@" + ref.ref) {
|
||||||
@@ -84,6 +85,7 @@ const validationConfig: ValidationConfig = {
|
|||||||
}
|
}
|
||||||
return Promise.resolve(metadata);
|
return Promise.resolve(metadata);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
describe("validate action steps", () => {
|
describe("validate action steps", () => {
|
||||||
@@ -101,6 +103,21 @@ jobs:
|
|||||||
expect(result).toEqual([]);
|
expect(result).toEqual([]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("no actionsMetadataProvider", async () => {
|
||||||
|
const input = `
|
||||||
|
on: push
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/does-not-exist@v3
|
||||||
|
`;
|
||||||
|
const config: ValidationConfig = {};
|
||||||
|
const result = await validate(createDocument("wf.yaml", input), config);
|
||||||
|
|
||||||
|
expect(result).toEqual([]);
|
||||||
|
});
|
||||||
|
|
||||||
it("action does not exist", async () => {
|
it("action does not exist", async () => {
|
||||||
const input = `
|
const input = `
|
||||||
on: push
|
on: push
|
||||||
|
|||||||
@@ -28,10 +28,14 @@ import {defaultValueProviders} from "./value-providers/default";
|
|||||||
export type ValidationConfig = {
|
export type ValidationConfig = {
|
||||||
valueProviderConfig?: ValueProviderConfig;
|
valueProviderConfig?: ValueProviderConfig;
|
||||||
contextProviderConfig?: ContextProviderConfig;
|
contextProviderConfig?: ContextProviderConfig;
|
||||||
fetchActionMetadata?(action: ActionReference): Promise<ActionMetadata | undefined>;
|
actionsMetadataProvider?: ActionsMetadataProvider;
|
||||||
fileProvider?: FileProvider;
|
fileProvider?: FileProvider;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type ActionsMetadataProvider = {
|
||||||
|
fetchActionMetadata(action: ActionReference): Promise<ActionMetadata | undefined>;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validates a workflow file
|
* Validates a workflow file
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user