-
Notifications
You must be signed in to change notification settings - Fork 674
Expand file tree
/
Copy pathdispatchGitHubEvent.js
More file actions
39 lines (32 loc) · 1.09 KB
/
dispatchGitHubEvent.js
File metadata and controls
39 lines (32 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env node
const { red, cyan, green } = require("chalk");
const argv = require("yargs").argv;
const { Octokit } = require("@octokit/rest");
/**
* A simple script that triggers GitHub workflows.
*/
(async () => {
try {
const owner = "webiny";
const repo = "webiny-js";
const token = argv.token || process.env.GH_TOKEN;
if (!token) {
throw new Error(`GitHub token is missing.`);
}
const octokit = new Octokit({
auth: token
});
console.log(cyan(`Triggering ${green(argv.event)} workflow...`));
await octokit.repos.createDispatchEvent({
owner,
repo,
event_type: argv.event,
client_payload: typeof argv.payload === "string" ? JSON.parse(argv.payload) : {}
});
console.log(green("GitHub workflow successfully triggered."));
console.log(green("See https://github.com/webiny/webiny-js/actions for action details."));
} catch (e) {
console.log(red("Something went wrong:"));
console.log(red(e.message));
}
})();