Skip to content

Commit

Permalink
chore: fix types
Browse files Browse the repository at this point in the history
  • Loading branch information
gentlementlegen committed Sep 21, 2024
1 parent fa0a7ad commit 0722881
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/github/handlers/push-event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { CONFIG_FULL_PATH, getConfigurationFromRepo } from "../utils/config";
import YAML, { LineCounter, Node, YAMLError } from "yaml";
import { ValueError } from "typebox-validators";
import { dispatchWorker, dispatchWorkflow, getDefaultBranch } from "../utils/workflow-dispatch";
import { PluginInput, PluginOutput, pluginOutputSchema } from "../types/plugin";
import { PluginChainState, PluginInput, PluginOutput, pluginOutputSchema } from "../types/plugin";
import { isGithubPlugin, PluginConfiguration } from "../types/plugin-configuration";
import { Value, ValueErrorType } from "@sinclair/typebox/value";
import { StateValidation, stateValidationSchema } from "../types/state-validation-payload";
import { pluginValidationResponseSchema, StateValidation, stateValidationSchema } from "../types/state-validation-payload";

function constructErrorBody(
errors: Iterable<ValueError> | (YAML.YAMLError | ValueError)[],
Expand Down Expand Up @@ -60,7 +60,7 @@ export async function handleActionValidationWorkflowCompleted(context: GitHubCon
throw error;
}

const state = await context.eventHandler.pluginChainState.get(pluginOutput.state_id);
const state = (await context.eventHandler.pluginChainState.get(pluginOutput.state_id)) as PluginChainState<"push">;

if (!state) {
console.error(`[handleActionValidationWorkflowCompleted]: No state found for plugin chain ${pluginOutput.state_id}`);
Expand All @@ -83,7 +83,7 @@ export async function handleActionValidationWorkflowCompleted(context: GitHubCon

const { rawData, path } = stateValidation;
try {
if (errors.length) {
if (errors.length && state.eventPayload.repository.owner) {
const body = [];
body.push(`@${state.eventPayload.sender?.login} Configuration is invalid.\n`);
if (errors.length) {
Expand Down Expand Up @@ -125,8 +125,9 @@ async function checkPluginConfigurations(context: GitHubContext<"push">, config:
if (!isGithubPluginObject) {
try {
const response = await dispatchWorker(`${plugin}/manifest`, await inputs.getWorkerInputs());
if (response.errors) {
errors.push(...response.errors.map((err) => ({ ...err, path: `plugins/${i}/uses/${j}/with${err.path}` })));
const decodedResponse = Value.Decode(pluginValidationResponseSchema, response);
if (decodedResponse.errors) {
errors.push(...decodedResponse.errors.map((err) => ({ ...err, path: `plugins/${i}/uses/${j}/with${err.path}` })));
}
} catch (e) {
errors.push({
Expand Down
13 changes: 13 additions & 0 deletions src/github/types/state-validation-payload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,17 @@ export const stateValidationSchema = Type.Object({
path: Type.String(),
});

const validationErrorSchema = Type.Object({
path: Type.String(),
message: Type.String(),
type: Type.Number(),
value: Type.Any(),
schema: Type.Any(),
});

export const pluginValidationResponseSchema = Type.Object({
message: Type.String(),
errors: Type.Array(validationErrorSchema),
});

export type StateValidation = StaticDecode<typeof stateValidationSchema>;

0 comments on commit 0722881

Please sign in to comment.