@@ -3,30 +3,35 @@ const github = require('@actions/github');
3
3
4
4
const main = async ( ) => {
5
5
try {
6
- const owner = core . getInput ( 'paths ' , { required : true } ) ;
6
+ const path = core . getInput ( 'path ' , { required : true } ) ;
7
7
const token = core . getInput ( 'token' , { required : true } ) ;
8
+ const regExp = RegExp ( path )
8
9
const octokit = new github . getOctokit ( token ) ;
9
10
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 )
30
35
31
36
} catch ( error ) {
32
37
core . setFailed ( error . message ) ;
0 commit comments