-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
47 lines (37 loc) · 1.6 KB
/
index.js
File metadata and controls
47 lines (37 loc) · 1.6 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
40
41
42
43
44
45
46
47
const core = require('@actions/core')
const github = require('@actions/github')
const YAML = require('yaml')
try {
(async () => {
const token = core.getInput('github_token')
const destinationRepo = core.getInput('destination_repository')
const eventType = core.getInput('event_type')
const event = core.getInput('event') !== null ? JSON.loads(core.getInput('event')) : null
const jsonPayload = core.getInput('extra_payload_json') !== null ? JSON.loads(core.getInput('extra_payload_json')) : null
const yamlPayload = core.getInput('extra_payload_yaml') !== null ? YAML.loads(core.getInput('extra_payload_yaml')) : null
const extraPayload = {
...jsonPayload,
...yamlPayload,
}
const [owner,repo] = destinationRepo.split('/')
const { context, eventName } = github
const ref_prefix = eventName === 'pull_request' ? 'refs/heads/' : ''
const { ref } = context.payload.pull_request.head || context.payload
const clientPayload = {
origin_context: context,
origin_eventName: eventName,
event: event || context,
extraPayload: extraPayload,
token: token,
repository: `${owner}/${repo}`,
ref: `${ref_prefix}${ref}`,
}
const octokit = new github.GitHub(token)
await octokit.repos.createDispatchEvent({
owner: owner,
repo: repo,
client_payload: clientPayload,
event_type: eventType,
})
})()
} catch (error) { core.setFailed(error.message) }