Merge pull request #94 from github/joshmgross/client_payload

Allow `{}` to represent any value in event payloads
This commit is contained in:
Josh Gross
2023-01-23 11:41:21 -05:00
committed by GitHub
3 changed files with 26 additions and 4 deletions
@@ -1,10 +1,7 @@
{
"action": "on-demand-test",
"branch": "master",
"client_payload": {
"unit": false,
"integration": true
},
"client_payload": {},
"repository": {
"id": 17273051,
"node_id": "MDEwOlJlcG9zaXRvcnkxNzI3MzA1MQ==",
@@ -99,6 +99,13 @@ function getEventContext(workflowContext: WorkflowContext): ExpressionData {
function merge(d: data.Dictionary, toAdd: Object): data.Dictionary {
for (const [key, value] of Object.entries(toAdd)) {
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());
@@ -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([]);
});
});
});