Skip to content

Commit dd6aa17

Browse files
authored
Merge pull request #5 from tim-actions/feature-filter-out
Add feature "filter out by pattern"
2 parents 55b867b + fafc652 commit dd6aa17

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

action.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ inputs:
44
token:
55
description: 'A token with access to your repository scoped in as a secret'
66
required: true
7+
filter_out_pattern:
8+
description: 'A regex pattern to check if a commit should be filtered out, empty for disable'
9+
required: false
10+
default: ""
11+
filter_out_flags:
12+
description: 'Regex flags of input filter_out_pattern'
13+
required: false
14+
default: ''
715
outputs:
816
commits:
917
description: 'commits in pr'

index.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,26 @@ async function main() {
1313
}
1414

1515
const token = core.getInput('token')
16+
const filterOutPattern = core.getInput('filter_out_pattern')
17+
const filterOutFlags = core.getInput('filter_out_flags')
1618
const octokit = new github.GitHub(token)
1719

18-
const commits = await octokit.pulls.listCommits({
20+
const commitsListed = await octokit.pulls.listCommits({
1921
owner: repo.owner.login,
2022
repo: repo.name,
2123
pull_number: pr.number,
2224
})
2325

24-
core.setOutput('commits', JSON.stringify(commits.data))
26+
let commits = commitsListed.data
27+
28+
if (filterOutPattern) {
29+
const regex = new RegExp(filterOutPattern, filterOutFlags)
30+
commits = commits.filter(({commit}) => {
31+
return !regex.test(commit.message)
32+
})
33+
}
34+
35+
core.setOutput('commits', JSON.stringify(commits))
2536
} catch (error) {
2637
core.setFailed(error.message)
2738
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "get-pr-commits",
3-
"version": "1.0.0",
3+
"version": "1.1.0",
44
"description": "",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)