@@ -10,30 +10,39 @@ const getPullRequestChanges = async () => {
10
10
return [ ] ;
11
11
}
12
12
13
- console . log ( 'pull_request' , github . context . payload . pull_request ) ;
14
-
15
- // This should be a token with access to your repository scoped in as a secret.
16
- // The YML workflow will need to set myToken with the GitHub Secret Token
17
- // myToken: ${{ secrets.GITHUB_TOKEN }}
18
- // https://help.github.com/en/actions/automating-your-workflow-with-github-actions/authenticating-with-the-github_token#about-the-github_token-secret
19
- const myToken = core . getInput ( 'myToken' ) ;
20
- console . log ( 'myToken' , `${ myToken } ` . length ) ;
21
-
22
- // const octokit = github.getOctokit(myToken);
23
-
24
- // // You can also pass in additional options as a second parameter to getOctokit
25
- // // const octokit = github.getOctokit(myToken, {userAgent: "MyActionVersion1"});
26
-
27
- // const { data } = await octokit.rest.pulls.get({
28
- // owner: 'octokit',
29
- // repo: 'rest.js',
30
- // pull_number: 123,
31
- // mediaType: {
32
- // format: 'diff'
33
- // }
34
- // });
35
-
36
- // return data;
13
+ // console.log('pull_request', github.context.payload.pull_request);
14
+
15
+ /**
16
+ * env:
17
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
18
+ */
19
+
20
+ const octokit = github . getOctokit ( process . env . GITHUB_TOKEN ) ;
21
+ const prNumber = github . context . payload . pull_request . number ;
22
+ core . startGroup ( `Fetching list of changed files for PR#${ prNumber } from Github API` ) ;
23
+
24
+ const iterator = octokit . paginate . iterator (
25
+ octokit . rest . pulls . listFiles , {
26
+ owner : github . context . repo . owner ,
27
+ repo : github . context . repo . repo ,
28
+ pull_number : prNumber ,
29
+ per_page : 100
30
+ }
31
+ ) ;
32
+
33
+ const files = [ ] ;
34
+ for await ( const response of iterator ) {
35
+ core . info ( `Received ${ response . data . length } items` ) ;
36
+
37
+ for ( const file of response . data ) {
38
+ core . debug ( `[${ file . status } ] ${ file . filename } ` ) ;
39
+ if ( [ 'added' , 'modified' ] . includes ( file . status ) ) {
40
+ files . push ( file . filename ) ;
41
+ }
42
+ }
43
+ }
44
+
45
+ return files ;
37
46
} ;
38
47
39
48
@@ -72,12 +81,15 @@ const test = async () => {
72
81
73
82
outputDir : './docs/pr' ,
74
83
75
- sourceFilter : {
76
- '**/src/**' : true
77
- } ,
78
-
79
- onEnd : ( coverageResults ) => {
80
-
84
+ sourceFilter : ( sourcePath ) => {
85
+ if ( prChanges . length ) {
86
+ for ( const file of prChanges ) {
87
+ if ( sourcePath . includes ( file ) ) {
88
+ return true ;
89
+ }
90
+ }
91
+ }
92
+ return false ;
81
93
}
82
94
} ;
83
95
0 commit comments