Skip to content

Commit

Permalink
Merge pull request #237 from ubiquity-os/development
Browse files Browse the repository at this point in the history
Merge development into main
  • Loading branch information
gentlementlegen authored Jan 21, 2025
2 parents 74136a1 + cacf27f commit 9147d15
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 32 deletions.
Binary file modified bun.lockb
Binary file not shown.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
"console-log-level": "^1.4.1",
"dotenv": "16.4.5",
"hono": "^4.6.12",
"js-yaml": "^4.1.0",
"openai": "^4.70.2",
"typebox-validators": "0.3.5",
"yaml": "^2.7.0"
Expand All @@ -87,6 +88,7 @@
"@swc/jest": "0.2.36",
"@types/console-log-level": "^1.4.5",
"@types/jest": "29.5.12",
"@types/js-yaml": "^4.0.9",
"@types/node": "20.14.10",
"@types/node-rsa": "^1.1.4",
"azure-functions-core-tools": "^4.0.6610",
Expand Down
4 changes: 2 additions & 2 deletions src/github/handlers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,14 @@ async function handleEvent(event: EmitterWebhookEvent, eventHandler: InstanceTyp
try {
console.log(`Dispatching event for ${JSON.stringify(plugin)}`);
if (!isGithubPluginObject) {
await dispatchWorker(plugin, await inputs.getWorkerInputs());
await dispatchWorker(plugin, await inputs.getInputs());
} else {
await dispatchWorkflow(context, {
owner: plugin.owner,
repository: plugin.repo,
workflowId: plugin.workflowId,
ref: plugin.ref,
inputs: await inputs.getWorkflowInputs(),
inputs: await inputs.getInputs(),
});
}
console.log(`Event dispatched for ${JSON.stringify(plugin)}`);
Expand Down
4 changes: 2 additions & 2 deletions src/github/handlers/issue-comment-created.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,14 +195,14 @@ The input will include the following fields:

try {
if (!isGithubPluginObject) {
await dispatchWorker(plugin, await inputs.getWorkerInputs());
await dispatchWorker(plugin, await inputs.getInputs());
} else {
await dispatchWorkflow(context, {
owner: plugin.owner,
repository: plugin.repo,
workflowId: plugin.workflowId,
ref: ref,
inputs: await inputs.getWorkflowInputs(),
inputs: await inputs.getInputs(),
});
}
} catch (e) {
Expand Down
4 changes: 2 additions & 2 deletions src/github/handlers/repository-dispatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ export async function repositoryDispatch(context: GitHubContext<"repository_disp
repository: nextPlugin.plugin.repo,
ref: nextPlugin.plugin.ref,
workflowId: nextPlugin.plugin.workflowId,
inputs: await inputs.getWorkflowInputs(),
inputs: await inputs.getInputs(),
});
} else {
await dispatchWorker(nextPlugin.plugin, await inputs.getWorkerInputs());
await dispatchWorker(nextPlugin.plugin, await inputs.getInputs());
}
}

Expand Down
19 changes: 1 addition & 18 deletions src/github/types/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export class PluginInput<T extends EmitterWebhookEventName = EmitterWebhookEvent
this.command = command;
}

public async getWorkflowInputs() {
public async getInputs() {
const inputs = {
stateId: this.stateId,
eventName: this.eventName,
Expand All @@ -60,23 +60,6 @@ export class PluginInput<T extends EmitterWebhookEventName = EmitterWebhookEvent
signature,
};
}

public async getWorkerInputs() {
const inputs = {
stateId: this.stateId,
eventName: this.eventName,
eventPayload: this.eventPayload,
settings: this.settings,
authToken: this.authToken,
ref: this.ref,
command: this.command,
};
const signature = await this.eventHandler.signPayload(JSON.stringify(inputs));
return {
...inputs,
signature,
};
}
}

export type PluginChainState<T extends EmitterWebhookEventName = EmitterWebhookEventName> = {
Expand Down
6 changes: 3 additions & 3 deletions src/github/utils/config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { TransformDecodeCheckError, Value, ValueError } from "@sinclair/typebox/value";
import YAML, { YAMLError } from "yaml";
import { YAMLError } from "yaml";
import YAML from "js-yaml";
import { GitHubContext } from "../github-context";
import { expressionRegex } from "../types/plugin";
import { configSchema, configSchemaValidator, PluginConfiguration } from "../types/plugin-configuration";
Expand Down Expand Up @@ -186,8 +187,7 @@ export function parseYaml(data: null | string) {
console.log("Will attempt to parse YAML data:", data);
try {
if (data) {
console.log("Before parsing", data);
const parsedData = YAML.parse(data);
const parsedData = YAML.load(data);
console.log("Parsed YAML data", parsedData);
return { yaml: parsedData ?? null, errors: null };
}
Expand Down
1 change: 0 additions & 1 deletion src/github/utils/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { Value } from "@sinclair/typebox/value";
const _manifestCache: Record<string, Manifest> = {};

export function getPluginsForEvent(plugins: PluginConfiguration["plugins"], event: EmitterWebhookEventName) {
console.log("getPluginsForEvent", plugins, event);
return plugins.filter((plugin) => {
return plugin.uses?.[0].runsOn?.includes(event);
});
Expand Down
8 changes: 4 additions & 4 deletions tests/dispatch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ jest.mock("../src/github/types/plugin", () => {
return {
...originalModule,
PluginInput: class extends originalModule.PluginInput {
async getWorkerInputs() {
async getInputs() {
return {
stateId: this.stateId,
eventName: this.eventName,
eventPayload: this.eventPayload,
settings: this.settings,
eventPayload: JSON.stringify(this.eventPayload),
settings: JSON.stringify(this.settings),
authToken: this.authToken,
ref: this.ref,
signature: "",
command: this.command,
command: JSON.stringify(this.command),
};
}
},
Expand Down

0 comments on commit 9147d15

Please sign in to comment.