-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathindex.js
41 lines (32 loc) · 1.07 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
const core = require('@actions/core')
const github = require('@actions/github')
const validEvent = ['pull_request', 'merge_group']
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 filterOutPattern = core.getInput('filter_out_pattern')
const filterOutFlags = core.getInput('filter_out_flags')
const octokit = new github.GitHub(token)
const commitsListed = await octokit.pulls.listCommits({
owner: repo.owner.login,
repo: repo.name,
pull_number: pr.number,
})
let commits = commitsListed.data
if (filterOutPattern) {
const regex = new RegExp(filterOutPattern, filterOutFlags)
commits = commits.filter(({commit}) => {
return !regex.test(commit.message)
})
}
core.setOutput('commits', JSON.stringify(commits))
} catch (error) {
core.setFailed(error.message)
}
}
main()