Skip to content

Commit

Permalink
Update setting event options
Browse files Browse the repository at this point in the history
Updated the way event data is set for `Act` instance, since `Act` seems to not be consistent in how it expects the data to be provided based on the type of event. This change seems to cover all possibilities. Plus renamed some variables to be compliant with JS convention

See: #13604
  • Loading branch information
radoslawkrzemien committed Jun 30, 2023
1 parent cc59c3b commit 61b8906
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions workflow_tests/utils/utils.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
const yaml = require('yaml');
const fs = require('fs');

const setUpActParams = (act, event = null, event_options = null, secrets = null, github_token = null, env_vars = null) => {
const setUpActParams = (act, event = null, eventOptions = null, secrets = null, githubToken = null, envVars = null) => {
let updated_act = act;

if (event && event_options) {
updated_act = updated_act.setEvent({
[event]: event_options,
});
if (event && eventOptions) {
// according to `Act` docs event data should be under the key with the event name (`[event]: eventOptions`), but
// for some event types this does not work (like `issues`), but providing the data on the JSON top level does,
// hence `...eventOptions` - this seems to cover all options
const eventData = {
[event]: eventOptions,
...eventOptions,
};
updated_act = updated_act.setEvent(eventData);
}

if (secrets) {
Expand All @@ -16,12 +21,12 @@ const setUpActParams = (act, event = null, event_options = null, secrets = null,
}
}

if (github_token) {
updated_act = updated_act.setGithubToken(github_token);
if (githubToken) {
updated_act = updated_act.setGithubToken(githubToken);
}

if (env_vars) {
for (const [key, value] of Object.entries(env_vars)) {
if (envVars) {
for (const [key, value] of Object.entries(envVars)) {
updated_act = updated_act.setEnv(key, value);
}
}
Expand Down

0 comments on commit 61b8906

Please sign in to comment.