Support client_payload for repository_dispatch events
This commit is contained in:
@@ -89,17 +89,26 @@ function getEventContext(workflowContext: WorkflowContext): ExpressionData {
|
||||
for (const e of events) {
|
||||
const payload = eventPayloads[e];
|
||||
if (payload) {
|
||||
merge(d, payload);
|
||||
const anyKeys = ANY_KEYS[e] || [];
|
||||
merge(d, payload, anyKeys);
|
||||
}
|
||||
}
|
||||
|
||||
return d;
|
||||
}
|
||||
|
||||
function merge(d: data.Dictionary, toAdd: Object): data.Dictionary {
|
||||
// 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 {
|
||||
for (const [key, value] of Object.entries(toAdd)) {
|
||||
if (value && typeof value === "object" && !d.get(key)) {
|
||||
d.add(key, merge(new data.Dictionary(), value));
|
||||
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, []));
|
||||
} else {
|
||||
d.add(key, new data.Null());
|
||||
}
|
||||
|
||||
@@ -1236,5 +1236,23 @@ jobs:
|
||||
}
|
||||
]);
|
||||
});
|
||||
|
||||
it("allows any property in client_payload", async () => {
|
||||
const input = `
|
||||
on:
|
||||
repository_dispatch:
|
||||
types: [test]
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- run: echo \${{ github.event.client_payload.anything }}
|
||||
- run: echo \${{ github.event.client_payload.branch }}`
|
||||
|
||||
const result = await validate(createDocument("wf.yaml", input));
|
||||
|
||||
expect(result).toEqual([]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user