Allow {} to represent any value in event payloads
This commit is contained in:
@@ -1,10 +1,7 @@
|
||||
{
|
||||
"action": "on-demand-test",
|
||||
"branch": "master",
|
||||
"client_payload": {
|
||||
"unit": false,
|
||||
"integration": true
|
||||
},
|
||||
"client_payload": {},
|
||||
"repository": {
|
||||
"id": 17273051,
|
||||
"node_id": "MDEwOlJlcG9zaXRvcnkxNzI3MzA1MQ==",
|
||||
|
||||
@@ -89,26 +89,24 @@ function getEventContext(workflowContext: WorkflowContext): ExpressionData {
|
||||
for (const e of events) {
|
||||
const payload = eventPayloads[e];
|
||||
if (payload) {
|
||||
const anyKeys = ANY_KEYS[e] || [];
|
||||
merge(d, payload, anyKeys);
|
||||
merge(d, payload);
|
||||
}
|
||||
}
|
||||
|
||||
return d;
|
||||
}
|
||||
|
||||
// These events have a top-level object that can be any type
|
||||
const ANY_KEYS: Record<string, string[]> = {
|
||||
repository_dispatch: ["client_payload"]
|
||||
};
|
||||
|
||||
function merge(d: data.Dictionary, toAdd: Object, anyKeys: string[]): data.Dictionary {
|
||||
function merge(d: data.Dictionary, toAdd: Object): data.Dictionary {
|
||||
for (const [key, value] of Object.entries(toAdd)) {
|
||||
if (anyKeys.includes(key)) {
|
||||
d.add(key, new data.Null());
|
||||
} else if (value && typeof value === "object" && !d.get(key)) {
|
||||
// Only use anyKeys for the top-level object
|
||||
d.add(key, merge(new data.Dictionary(), value, []));
|
||||
if (value && typeof value === "object" && !d.get(key)) {
|
||||
|
||||
if (!Array.isArray(value) && Object.entries(value).length === 0) {
|
||||
// Allow an empty object to be any value
|
||||
d.add(key, new data.Null());
|
||||
continue;
|
||||
}
|
||||
|
||||
d.add(key, merge(new data.Dictionary(), value));
|
||||
} else {
|
||||
d.add(key, new data.Null());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user