@ubiquity-os/plugin-sdk 2.0.1 → 2.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +5 -2
- package/dist/index.d.ts +5 -2
- package/dist/index.js +47 -53
- package/dist/index.mjs +47 -53
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -5,9 +5,9 @@ import { Logs, LogLevel, LogReturn } from '@ubiquity-os/ubiquity-os-logger';
|
|
|
5
5
|
import { customOctokit } from './octokit.mjs';
|
|
6
6
|
import { Manifest } from './manifest.mjs';
|
|
7
7
|
import { TAnySchema } from '@sinclair/typebox';
|
|
8
|
+
import { RestEndpointMethodTypes } from '@octokit/plugin-rest-endpoint-methods';
|
|
8
9
|
import '@octokit/core/dist-types/types';
|
|
9
10
|
import '@octokit/plugin-paginate-graphql';
|
|
10
|
-
import '@octokit/plugin-rest-endpoint-methods';
|
|
11
11
|
import '@octokit/plugin-paginate-rest';
|
|
12
12
|
import '@octokit/request-error';
|
|
13
13
|
import '@octokit/core';
|
|
@@ -48,8 +48,11 @@ interface CommentOptions {
|
|
|
48
48
|
raw?: boolean;
|
|
49
49
|
updateComment?: boolean;
|
|
50
50
|
}
|
|
51
|
+
type WithIssueNumber<T> = T & {
|
|
52
|
+
issueNumber: number;
|
|
53
|
+
};
|
|
51
54
|
type PostComment = {
|
|
52
|
-
(context: Context, message: LogReturn | Error, options?: CommentOptions): Promise<
|
|
55
|
+
(context: Context, message: LogReturn | Error, options?: CommentOptions): Promise<WithIssueNumber<RestEndpointMethodTypes["issues"]["updateComment"]["response"]["data"] | RestEndpointMethodTypes["issues"]["createComment"]["response"]["data"]> | null>;
|
|
53
56
|
lastCommentId?: number;
|
|
54
57
|
};
|
|
55
58
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -5,9 +5,9 @@ import { Logs, LogLevel, LogReturn } from '@ubiquity-os/ubiquity-os-logger';
|
|
|
5
5
|
import { customOctokit } from './octokit.js';
|
|
6
6
|
import { Manifest } from './manifest.js';
|
|
7
7
|
import { TAnySchema } from '@sinclair/typebox';
|
|
8
|
+
import { RestEndpointMethodTypes } from '@octokit/plugin-rest-endpoint-methods';
|
|
8
9
|
import '@octokit/core/dist-types/types';
|
|
9
10
|
import '@octokit/plugin-paginate-graphql';
|
|
10
|
-
import '@octokit/plugin-rest-endpoint-methods';
|
|
11
11
|
import '@octokit/plugin-paginate-rest';
|
|
12
12
|
import '@octokit/request-error';
|
|
13
13
|
import '@octokit/core';
|
|
@@ -48,8 +48,11 @@ interface CommentOptions {
|
|
|
48
48
|
raw?: boolean;
|
|
49
49
|
updateComment?: boolean;
|
|
50
50
|
}
|
|
51
|
+
type WithIssueNumber<T> = T & {
|
|
52
|
+
issueNumber: number;
|
|
53
|
+
};
|
|
51
54
|
type PostComment = {
|
|
52
|
-
(context: Context, message: LogReturn | Error, options?: CommentOptions): Promise<
|
|
55
|
+
(context: Context, message: LogReturn | Error, options?: CommentOptions): Promise<WithIssueNumber<RestEndpointMethodTypes["issues"]["updateComment"]["response"]["data"] | RestEndpointMethodTypes["issues"]["createComment"]["response"]["data"]> | null>;
|
|
53
56
|
lastCommentId?: number;
|
|
54
57
|
};
|
|
55
58
|
/**
|
package/dist/index.js
CHANGED
|
@@ -37,8 +37,7 @@ __export(src_exports, {
|
|
|
37
37
|
module.exports = __toCommonJS(src_exports);
|
|
38
38
|
|
|
39
39
|
// src/server.ts
|
|
40
|
-
var
|
|
41
|
-
var import_value = require("@sinclair/typebox/value");
|
|
40
|
+
var import_value2 = require("@sinclair/typebox/value");
|
|
42
41
|
var import_ubiquity_os_logger2 = require("@ubiquity-os/ubiquity-os-logger");
|
|
43
42
|
var import_hono = require("hono");
|
|
44
43
|
var import_adapter2 = require("hono/adapter");
|
|
@@ -128,17 +127,18 @@ var postComment = async function(context2, message, options = { updateComment: t
|
|
|
128
127
|
issueNumber = context2.payload.discussion.number;
|
|
129
128
|
} else {
|
|
130
129
|
context2.logger.info("Cannot post comment because issue is not found in the payload.");
|
|
131
|
-
return;
|
|
130
|
+
return null;
|
|
132
131
|
}
|
|
133
132
|
if ("repository" in context2.payload && context2.payload.repository?.owner?.login) {
|
|
134
133
|
const body = await createStructuredMetadataWithMessage(context2, message, options);
|
|
135
134
|
if (options.updateComment && postComment.lastCommentId) {
|
|
136
|
-
await context2.octokit.rest.issues.updateComment({
|
|
135
|
+
const commentData = await context2.octokit.rest.issues.updateComment({
|
|
137
136
|
owner: context2.payload.repository.owner.login,
|
|
138
137
|
repo: context2.payload.repository.name,
|
|
139
138
|
comment_id: postComment.lastCommentId,
|
|
140
139
|
body
|
|
141
140
|
});
|
|
141
|
+
return { ...commentData.data, issueNumber };
|
|
142
142
|
} else {
|
|
143
143
|
const commentData = await context2.octokit.rest.issues.createComment({
|
|
144
144
|
owner: context2.payload.repository.owner.login,
|
|
@@ -147,10 +147,12 @@ var postComment = async function(context2, message, options = { updateComment: t
|
|
|
147
147
|
body
|
|
148
148
|
});
|
|
149
149
|
postComment.lastCommentId = commentData.data.id;
|
|
150
|
+
return { ...commentData.data, issueNumber };
|
|
150
151
|
}
|
|
151
152
|
} else {
|
|
152
153
|
context2.logger.info("Cannot post comment because repository is not found in the payload.", { payload: context2.payload });
|
|
153
154
|
}
|
|
155
|
+
return null;
|
|
154
156
|
};
|
|
155
157
|
async function createStructuredMetadataWithMessage(context2, message, options) {
|
|
156
158
|
let logMessage;
|
|
@@ -259,17 +261,36 @@ async function verifySignature(publicKeyPem, inputs, signature) {
|
|
|
259
261
|
}
|
|
260
262
|
}
|
|
261
263
|
|
|
262
|
-
// src/
|
|
263
|
-
var
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
264
|
+
// src/types/input-schema.ts
|
|
265
|
+
var import_typebox3 = require("@sinclair/typebox");
|
|
266
|
+
|
|
267
|
+
// src/types/command.ts
|
|
268
|
+
var import_typebox = require("@sinclair/typebox");
|
|
269
|
+
var commandCallSchema = import_typebox.Type.Union([import_typebox.Type.Null(), import_typebox.Type.Object({ name: import_typebox.Type.String(), parameters: import_typebox.Type.Unknown() })]);
|
|
270
|
+
|
|
271
|
+
// src/types/util.ts
|
|
272
|
+
var import_typebox2 = require("@sinclair/typebox");
|
|
273
|
+
var import_value = require("@sinclair/typebox/value");
|
|
274
|
+
function jsonType(type) {
|
|
275
|
+
return import_typebox2.Type.Transform(import_typebox2.Type.String()).Decode((value) => {
|
|
276
|
+
const parsed = JSON.parse(value);
|
|
277
|
+
return import_value.Value.Decode(type, import_value.Value.Default(type, parsed));
|
|
278
|
+
}).Encode((value) => JSON.stringify(value));
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
// src/types/input-schema.ts
|
|
282
|
+
var inputSchema = import_typebox3.Type.Object({
|
|
283
|
+
stateId: import_typebox3.Type.String(),
|
|
284
|
+
eventName: import_typebox3.Type.String(),
|
|
285
|
+
eventPayload: jsonType(import_typebox3.Type.Record(import_typebox3.Type.String(), import_typebox3.Type.Any())),
|
|
286
|
+
command: jsonType(commandCallSchema),
|
|
287
|
+
authToken: import_typebox3.Type.String(),
|
|
288
|
+
settings: jsonType(import_typebox3.Type.Record(import_typebox3.Type.String(), import_typebox3.Type.Any())),
|
|
289
|
+
ref: import_typebox3.Type.String(),
|
|
290
|
+
signature: import_typebox3.Type.String()
|
|
272
291
|
});
|
|
292
|
+
|
|
293
|
+
// src/server.ts
|
|
273
294
|
function createPlugin(handler, manifest, options) {
|
|
274
295
|
const pluginOptions = getPluginOptions(options);
|
|
275
296
|
const app = new import_hono.Hono();
|
|
@@ -281,22 +302,22 @@ function createPlugin(handler, manifest, options) {
|
|
|
281
302
|
throw new import_http_exception.HTTPException(400, { message: "Content-Type must be application/json" });
|
|
282
303
|
}
|
|
283
304
|
const body = await ctx.req.json();
|
|
284
|
-
const inputSchemaErrors = [...
|
|
305
|
+
const inputSchemaErrors = [...import_value2.Value.Errors(inputSchema, body)];
|
|
285
306
|
if (inputSchemaErrors.length) {
|
|
286
307
|
console.log(inputSchemaErrors, { depth: null });
|
|
287
308
|
throw new import_http_exception.HTTPException(400, { message: "Invalid body" });
|
|
288
309
|
}
|
|
289
|
-
const
|
|
290
|
-
|
|
291
|
-
if (!pluginOptions.bypassSignatureVerification && !await verifySignature(pluginOptions.kernelPublicKey, inputs, signature)) {
|
|
310
|
+
const signature = body.signature;
|
|
311
|
+
if (!pluginOptions.bypassSignatureVerification && !await verifySignature(pluginOptions.kernelPublicKey, body, signature)) {
|
|
292
312
|
throw new import_http_exception.HTTPException(400, { message: "Invalid signature" });
|
|
293
313
|
}
|
|
314
|
+
const inputs = import_value2.Value.Decode(inputSchema, body);
|
|
294
315
|
let config2;
|
|
295
316
|
if (pluginOptions.settingsSchema) {
|
|
296
317
|
try {
|
|
297
|
-
config2 =
|
|
318
|
+
config2 = import_value2.Value.Decode(pluginOptions.settingsSchema, import_value2.Value.Default(pluginOptions.settingsSchema, inputs.settings));
|
|
298
319
|
} catch (e) {
|
|
299
|
-
console.log(...
|
|
320
|
+
console.log(...import_value2.Value.Errors(pluginOptions.settingsSchema, inputs.settings), { depth: null });
|
|
300
321
|
throw e;
|
|
301
322
|
}
|
|
302
323
|
} else {
|
|
@@ -306,9 +327,9 @@ function createPlugin(handler, manifest, options) {
|
|
|
306
327
|
const honoEnvironment = (0, import_adapter2.env)(ctx);
|
|
307
328
|
if (pluginOptions.envSchema) {
|
|
308
329
|
try {
|
|
309
|
-
env =
|
|
330
|
+
env = import_value2.Value.Decode(pluginOptions.envSchema, import_value2.Value.Default(pluginOptions.envSchema, honoEnvironment));
|
|
310
331
|
} catch (e) {
|
|
311
|
-
console.log(...
|
|
332
|
+
console.log(...import_value2.Value.Errors(pluginOptions.envSchema, honoEnvironment), { depth: null });
|
|
312
333
|
throw e;
|
|
313
334
|
}
|
|
314
335
|
} else {
|
|
@@ -319,9 +340,9 @@ function createPlugin(handler, manifest, options) {
|
|
|
319
340
|
let command = null;
|
|
320
341
|
if (inputs.command && pluginOptions.commandSchema) {
|
|
321
342
|
try {
|
|
322
|
-
command =
|
|
343
|
+
command = import_value2.Value.Decode(pluginOptions.commandSchema, import_value2.Value.Default(pluginOptions.commandSchema, inputs.command));
|
|
323
344
|
} catch (e) {
|
|
324
|
-
console.log(...
|
|
345
|
+
console.log(...import_value2.Value.Errors(pluginOptions.commandSchema, inputs.command), { depth: null });
|
|
325
346
|
throw e;
|
|
326
347
|
}
|
|
327
348
|
} else if (inputs.command) {
|
|
@@ -359,37 +380,10 @@ function createPlugin(handler, manifest, options) {
|
|
|
359
380
|
// src/actions.ts
|
|
360
381
|
var core = __toESM(require("@actions/core"));
|
|
361
382
|
var github2 = __toESM(require("@actions/github"));
|
|
362
|
-
var import_typebox4 = require("@sinclair/typebox");
|
|
363
383
|
var import_value3 = require("@sinclair/typebox/value");
|
|
364
384
|
var import_ubiquity_os_logger3 = require("@ubiquity-os/ubiquity-os-logger");
|
|
365
385
|
var import_dotenv = require("dotenv");
|
|
366
|
-
|
|
367
|
-
// src/types/command.ts
|
|
368
|
-
var import_typebox2 = require("@sinclair/typebox");
|
|
369
|
-
var commandCallSchema = import_typebox2.Type.Union([import_typebox2.Type.Null(), import_typebox2.Type.Object({ name: import_typebox2.Type.String(), parameters: import_typebox2.Type.Unknown() })]);
|
|
370
|
-
|
|
371
|
-
// src/types/util.ts
|
|
372
|
-
var import_typebox3 = require("@sinclair/typebox");
|
|
373
|
-
var import_value2 = require("@sinclair/typebox/value");
|
|
374
|
-
function jsonType(type) {
|
|
375
|
-
return import_typebox3.Type.Transform(import_typebox3.Type.String()).Decode((value) => {
|
|
376
|
-
const parsed = JSON.parse(value);
|
|
377
|
-
return import_value2.Value.Decode(type, import_value2.Value.Default(type, parsed));
|
|
378
|
-
}).Encode((value) => JSON.stringify(value));
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
// src/actions.ts
|
|
382
386
|
(0, import_dotenv.config)();
|
|
383
|
-
var inputSchema2 = import_typebox4.Type.Object({
|
|
384
|
-
stateId: import_typebox4.Type.String(),
|
|
385
|
-
eventName: import_typebox4.Type.String(),
|
|
386
|
-
eventPayload: jsonType(import_typebox4.Type.Record(import_typebox4.Type.String(), import_typebox4.Type.Any())),
|
|
387
|
-
command: jsonType(commandCallSchema),
|
|
388
|
-
authToken: import_typebox4.Type.String(),
|
|
389
|
-
settings: jsonType(import_typebox4.Type.Record(import_typebox4.Type.String(), import_typebox4.Type.Any())),
|
|
390
|
-
ref: import_typebox4.Type.String(),
|
|
391
|
-
signature: import_typebox4.Type.String()
|
|
392
|
-
});
|
|
393
387
|
async function createActionsPlugin(handler, options) {
|
|
394
388
|
const pluginOptions = getPluginOptions(options);
|
|
395
389
|
const pluginGithubToken = process.env.PLUGIN_GITHUB_TOKEN;
|
|
@@ -404,13 +398,13 @@ async function createActionsPlugin(handler, options) {
|
|
|
404
398
|
return;
|
|
405
399
|
}
|
|
406
400
|
const inputPayload = github2.context.payload.inputs;
|
|
407
|
-
const inputSchemaErrors = [...import_value3.Value.Errors(
|
|
401
|
+
const inputSchemaErrors = [...import_value3.Value.Errors(inputSchema, inputPayload)];
|
|
408
402
|
if (inputSchemaErrors.length) {
|
|
409
403
|
console.dir(inputSchemaErrors, { depth: null });
|
|
410
404
|
core.setFailed(`Error: Invalid inputs payload: ${inputSchemaErrors.join(",")}`);
|
|
411
405
|
return;
|
|
412
406
|
}
|
|
413
|
-
const inputs = import_value3.Value.Decode(
|
|
407
|
+
const inputs = import_value3.Value.Decode(inputSchema, inputPayload);
|
|
414
408
|
let config2;
|
|
415
409
|
if (pluginOptions.settingsSchema) {
|
|
416
410
|
try {
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
// src/server.ts
|
|
2
|
-
import {
|
|
3
|
-
import { Value } from "@sinclair/typebox/value";
|
|
2
|
+
import { Value as Value2 } from "@sinclair/typebox/value";
|
|
4
3
|
import { LogReturn as LogReturn2, Logs } from "@ubiquity-os/ubiquity-os-logger";
|
|
5
4
|
import { Hono } from "hono";
|
|
6
5
|
import { env as honoEnv } from "hono/adapter";
|
|
@@ -90,17 +89,18 @@ var postComment = async function(context2, message, options = { updateComment: t
|
|
|
90
89
|
issueNumber = context2.payload.discussion.number;
|
|
91
90
|
} else {
|
|
92
91
|
context2.logger.info("Cannot post comment because issue is not found in the payload.");
|
|
93
|
-
return;
|
|
92
|
+
return null;
|
|
94
93
|
}
|
|
95
94
|
if ("repository" in context2.payload && context2.payload.repository?.owner?.login) {
|
|
96
95
|
const body = await createStructuredMetadataWithMessage(context2, message, options);
|
|
97
96
|
if (options.updateComment && postComment.lastCommentId) {
|
|
98
|
-
await context2.octokit.rest.issues.updateComment({
|
|
97
|
+
const commentData = await context2.octokit.rest.issues.updateComment({
|
|
99
98
|
owner: context2.payload.repository.owner.login,
|
|
100
99
|
repo: context2.payload.repository.name,
|
|
101
100
|
comment_id: postComment.lastCommentId,
|
|
102
101
|
body
|
|
103
102
|
});
|
|
103
|
+
return { ...commentData.data, issueNumber };
|
|
104
104
|
} else {
|
|
105
105
|
const commentData = await context2.octokit.rest.issues.createComment({
|
|
106
106
|
owner: context2.payload.repository.owner.login,
|
|
@@ -109,10 +109,12 @@ var postComment = async function(context2, message, options = { updateComment: t
|
|
|
109
109
|
body
|
|
110
110
|
});
|
|
111
111
|
postComment.lastCommentId = commentData.data.id;
|
|
112
|
+
return { ...commentData.data, issueNumber };
|
|
112
113
|
}
|
|
113
114
|
} else {
|
|
114
115
|
context2.logger.info("Cannot post comment because repository is not found in the payload.", { payload: context2.payload });
|
|
115
116
|
}
|
|
117
|
+
return null;
|
|
116
118
|
};
|
|
117
119
|
async function createStructuredMetadataWithMessage(context2, message, options) {
|
|
118
120
|
let logMessage;
|
|
@@ -221,17 +223,36 @@ async function verifySignature(publicKeyPem, inputs, signature) {
|
|
|
221
223
|
}
|
|
222
224
|
}
|
|
223
225
|
|
|
224
|
-
// src/
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
226
|
+
// src/types/input-schema.ts
|
|
227
|
+
import { Type as T2 } from "@sinclair/typebox";
|
|
228
|
+
|
|
229
|
+
// src/types/command.ts
|
|
230
|
+
import { Type as T } from "@sinclair/typebox";
|
|
231
|
+
var commandCallSchema = T.Union([T.Null(), T.Object({ name: T.String(), parameters: T.Unknown() })]);
|
|
232
|
+
|
|
233
|
+
// src/types/util.ts
|
|
234
|
+
import { Type } from "@sinclair/typebox";
|
|
235
|
+
import { Value } from "@sinclair/typebox/value";
|
|
236
|
+
function jsonType(type) {
|
|
237
|
+
return Type.Transform(Type.String()).Decode((value) => {
|
|
238
|
+
const parsed = JSON.parse(value);
|
|
239
|
+
return Value.Decode(type, Value.Default(type, parsed));
|
|
240
|
+
}).Encode((value) => JSON.stringify(value));
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
// src/types/input-schema.ts
|
|
244
|
+
var inputSchema = T2.Object({
|
|
245
|
+
stateId: T2.String(),
|
|
246
|
+
eventName: T2.String(),
|
|
247
|
+
eventPayload: jsonType(T2.Record(T2.String(), T2.Any())),
|
|
248
|
+
command: jsonType(commandCallSchema),
|
|
249
|
+
authToken: T2.String(),
|
|
250
|
+
settings: jsonType(T2.Record(T2.String(), T2.Any())),
|
|
251
|
+
ref: T2.String(),
|
|
252
|
+
signature: T2.String()
|
|
234
253
|
});
|
|
254
|
+
|
|
255
|
+
// src/server.ts
|
|
235
256
|
function createPlugin(handler, manifest, options) {
|
|
236
257
|
const pluginOptions = getPluginOptions(options);
|
|
237
258
|
const app = new Hono();
|
|
@@ -243,22 +264,22 @@ function createPlugin(handler, manifest, options) {
|
|
|
243
264
|
throw new HTTPException(400, { message: "Content-Type must be application/json" });
|
|
244
265
|
}
|
|
245
266
|
const body = await ctx.req.json();
|
|
246
|
-
const inputSchemaErrors = [...
|
|
267
|
+
const inputSchemaErrors = [...Value2.Errors(inputSchema, body)];
|
|
247
268
|
if (inputSchemaErrors.length) {
|
|
248
269
|
console.log(inputSchemaErrors, { depth: null });
|
|
249
270
|
throw new HTTPException(400, { message: "Invalid body" });
|
|
250
271
|
}
|
|
251
|
-
const
|
|
252
|
-
|
|
253
|
-
if (!pluginOptions.bypassSignatureVerification && !await verifySignature(pluginOptions.kernelPublicKey, inputs, signature)) {
|
|
272
|
+
const signature = body.signature;
|
|
273
|
+
if (!pluginOptions.bypassSignatureVerification && !await verifySignature(pluginOptions.kernelPublicKey, body, signature)) {
|
|
254
274
|
throw new HTTPException(400, { message: "Invalid signature" });
|
|
255
275
|
}
|
|
276
|
+
const inputs = Value2.Decode(inputSchema, body);
|
|
256
277
|
let config2;
|
|
257
278
|
if (pluginOptions.settingsSchema) {
|
|
258
279
|
try {
|
|
259
|
-
config2 =
|
|
280
|
+
config2 = Value2.Decode(pluginOptions.settingsSchema, Value2.Default(pluginOptions.settingsSchema, inputs.settings));
|
|
260
281
|
} catch (e) {
|
|
261
|
-
console.log(...
|
|
282
|
+
console.log(...Value2.Errors(pluginOptions.settingsSchema, inputs.settings), { depth: null });
|
|
262
283
|
throw e;
|
|
263
284
|
}
|
|
264
285
|
} else {
|
|
@@ -268,9 +289,9 @@ function createPlugin(handler, manifest, options) {
|
|
|
268
289
|
const honoEnvironment = honoEnv(ctx);
|
|
269
290
|
if (pluginOptions.envSchema) {
|
|
270
291
|
try {
|
|
271
|
-
env =
|
|
292
|
+
env = Value2.Decode(pluginOptions.envSchema, Value2.Default(pluginOptions.envSchema, honoEnvironment));
|
|
272
293
|
} catch (e) {
|
|
273
|
-
console.log(...
|
|
294
|
+
console.log(...Value2.Errors(pluginOptions.envSchema, honoEnvironment), { depth: null });
|
|
274
295
|
throw e;
|
|
275
296
|
}
|
|
276
297
|
} else {
|
|
@@ -281,9 +302,9 @@ function createPlugin(handler, manifest, options) {
|
|
|
281
302
|
let command = null;
|
|
282
303
|
if (inputs.command && pluginOptions.commandSchema) {
|
|
283
304
|
try {
|
|
284
|
-
command =
|
|
305
|
+
command = Value2.Decode(pluginOptions.commandSchema, Value2.Default(pluginOptions.commandSchema, inputs.command));
|
|
285
306
|
} catch (e) {
|
|
286
|
-
console.log(...
|
|
307
|
+
console.log(...Value2.Errors(pluginOptions.commandSchema, inputs.command), { depth: null });
|
|
287
308
|
throw e;
|
|
288
309
|
}
|
|
289
310
|
} else if (inputs.command) {
|
|
@@ -321,37 +342,10 @@ function createPlugin(handler, manifest, options) {
|
|
|
321
342
|
// src/actions.ts
|
|
322
343
|
import * as core from "@actions/core";
|
|
323
344
|
import * as github2 from "@actions/github";
|
|
324
|
-
import { Type as T3 } from "@sinclair/typebox";
|
|
325
345
|
import { Value as Value3 } from "@sinclair/typebox/value";
|
|
326
346
|
import { LogReturn as LogReturn3, Logs as Logs2 } from "@ubiquity-os/ubiquity-os-logger";
|
|
327
347
|
import { config } from "dotenv";
|
|
328
|
-
|
|
329
|
-
// src/types/command.ts
|
|
330
|
-
import { Type as T2 } from "@sinclair/typebox";
|
|
331
|
-
var commandCallSchema = T2.Union([T2.Null(), T2.Object({ name: T2.String(), parameters: T2.Unknown() })]);
|
|
332
|
-
|
|
333
|
-
// src/types/util.ts
|
|
334
|
-
import { Type } from "@sinclair/typebox";
|
|
335
|
-
import { Value as Value2 } from "@sinclair/typebox/value";
|
|
336
|
-
function jsonType(type) {
|
|
337
|
-
return Type.Transform(Type.String()).Decode((value) => {
|
|
338
|
-
const parsed = JSON.parse(value);
|
|
339
|
-
return Value2.Decode(type, Value2.Default(type, parsed));
|
|
340
|
-
}).Encode((value) => JSON.stringify(value));
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
// src/actions.ts
|
|
344
348
|
config();
|
|
345
|
-
var inputSchema2 = T3.Object({
|
|
346
|
-
stateId: T3.String(),
|
|
347
|
-
eventName: T3.String(),
|
|
348
|
-
eventPayload: jsonType(T3.Record(T3.String(), T3.Any())),
|
|
349
|
-
command: jsonType(commandCallSchema),
|
|
350
|
-
authToken: T3.String(),
|
|
351
|
-
settings: jsonType(T3.Record(T3.String(), T3.Any())),
|
|
352
|
-
ref: T3.String(),
|
|
353
|
-
signature: T3.String()
|
|
354
|
-
});
|
|
355
349
|
async function createActionsPlugin(handler, options) {
|
|
356
350
|
const pluginOptions = getPluginOptions(options);
|
|
357
351
|
const pluginGithubToken = process.env.PLUGIN_GITHUB_TOKEN;
|
|
@@ -366,13 +360,13 @@ async function createActionsPlugin(handler, options) {
|
|
|
366
360
|
return;
|
|
367
361
|
}
|
|
368
362
|
const inputPayload = github2.context.payload.inputs;
|
|
369
|
-
const inputSchemaErrors = [...Value3.Errors(
|
|
363
|
+
const inputSchemaErrors = [...Value3.Errors(inputSchema, inputPayload)];
|
|
370
364
|
if (inputSchemaErrors.length) {
|
|
371
365
|
console.dir(inputSchemaErrors, { depth: null });
|
|
372
366
|
core.setFailed(`Error: Invalid inputs payload: ${inputSchemaErrors.join(",")}`);
|
|
373
367
|
return;
|
|
374
368
|
}
|
|
375
|
-
const inputs = Value3.Decode(
|
|
369
|
+
const inputs = Value3.Decode(inputSchema, inputPayload);
|
|
376
370
|
let config2;
|
|
377
371
|
if (pluginOptions.settingsSchema) {
|
|
378
372
|
try {
|