forked from tim-actions/get-pr-commits
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
30 lines (23 loc) · 744 Bytes
/
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
const core = require('@actions/core')
const github = require('@actions/github')
const validEvent = ['pull_request', 'pull_request_target', 'push']
async function main() {
try {
const { eventName, payload: {repository: repo, pull_request: pr} } = github.context
if (validEvent.indexOf(eventName) < 0) {
core.error(`Invalid event: ${eventName}`)
return
}
const token = core.getInput('token')
const octokit = new github.GitHub(token)
const commits = await octokit.pulls.listCommits({
owner: repo.owner.login,
repo: repo.name,
pull_number: pr.number,
})
core.setOutput('commits', JSON.stringify(commits.data))
} catch (error) {
core.setFailed(error.message)
}
}
main()