-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
43 lines (34 loc) · 1.16 KB
/
index.js
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
40
41
42
43
const core = require('@actions/core');
const github = require('@actions/github');
const util = require('util');
const sendDispatch = async () => {
const notifyRepo = core.getInput('notifyRepo');
const event_type = core.getInput('eventType');
const token = process.env.GITHUB_TOKEN;
core.setCommandEcho(true);
const context = github.context;
const [owner, repo] = notifyRepo.split('/');
const client_payload = {
repo: `${context.repo.owner}/${context.repo.repo}`,
ref: context.ref,
sha: context.sha,
}
const octokit = github.getOctokit(token);
core.info('Creating ' + event_type + ' respository dispatch for ' + notifyRepo);
core.info(' client_payload: ' + JSON.stringify(client_payload));
await octokit.repos.createDispatchEvent({
owner,
repo,
event_type,
client_payload,
})
}
sendDispatch()
.catch(error => {
core.debug(util.inspect(error));
if (error.status === 404) {
core.setFailed('Repository not found OR token does not have sufficient permission');
} else {
core.setFailed(error.message);
}
});