Skip to content

Commit b69d426

Browse files
committed
refactor: Update main file
1 parent 3b758c7 commit b69d426

File tree

2 files changed

+27
-22
lines changed

2 files changed

+27
-22
lines changed

action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: 'PR Metadata Action'
22
description: 'Adds pull request file changes as a comment to a newly opened PR'
33
inputs:
4-
paths:
4+
path:
55
description: 'Paths list'
66
required: false
77
default: "."

index.js

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,35 @@ const github = require('@actions/github');
33

44
const main = async () => {
55
try {
6-
const owner = core.getInput('paths', { required: true });
6+
const path = core.getInput('path', { required: true });
77
const token = core.getInput('token', { required: true });
8+
const regExp = RegExp(path)
89
const octokit = new github.getOctokit(token);
910

10-
const { data: changedFiles } = await octokit.rest.pulls.listFiles({
11-
owner,
12-
repo,
13-
pull_number: pr_number,
14-
});
15-
16-
let diffData = {
17-
additions: 0,
18-
deletions: 0,
19-
changes: 0
20-
};
21-
22-
diffData = changedFiles.reduce((acc, file) => {
23-
acc.additions += file.additions;
24-
acc.deletions += file.deletions;
25-
acc.changes += file.changes;
26-
return acc;
27-
}, diffData);
28-
29-
console.log(changedFiles);
11+
const response = await octokit.rest.repos.compareCommits({
12+
owner: github.context.repo.owner,
13+
repo: github.context.repo.repo,
14+
base: "HEAD^",
15+
head: "HEAD"
16+
})
17+
18+
const filteredFiles = (response.data.files || []).filter(file => {
19+
let isMatch = regExp.test(file.filename)
20+
console.log(`[${isMatch && '[** match **]'} ${file.filename}`)
21+
console.log(`##Path: ${file.filename} matches`)
22+
return isMatch
23+
})
24+
25+
if(filteredFiles.length === 0){
26+
console.log("No matchs found.")
27+
console.log(`Raw input: ${directory}`)
28+
console.log(`Regex: ${regExp.toString()}`)
29+
core.setOutput("hasChanges", false)
30+
}
31+
32+
console.log(`Found a total of ${filteredFiles.length} matches`)
33+
34+
core.setOutput("hasChanges", true)
3035

3136
} catch (error) {
3237
core.setFailed(error.message);

0 commit comments

Comments
 (0)