1
+ const {
2
+ PR_ACTION ,
3
+ PR_AUTHOR ,
4
+ PR_BODY ,
5
+ PR_NUMBER ,
6
+ IGNORE_AUTHORS ,
7
+ BLOCK_LABEL ,
8
+ BLOCK_REASON_LABEL
9
+ } = require ( "./constants" )
10
+
1
11
module . exports = async ( { github, context, core} ) => {
2
- const prBody = process . env . PR_BODY ;
3
- const prNumber = process . env . PR_NUMBER ;
4
- const blockLabel = process . env . BLOCK_LABEL ;
5
- const blockReasonLabel = process . env . BLOCK_REASON_LABEL ;
12
+ core . debug ( `Number: ${ PR_BODY } ` ) ;
13
+ core . debug ( `Action: ${ PR_ACTION } ` ) ;
14
+ core . debug ( `Author: ${ PR_AUTHOR } ` ) ;
15
+ core . debug ( `Body: ${ PR_BODY } ` ) ;
6
16
7
- const RELATED_ISSUE_REGEX = / I s s u e n u m b e r : [ ^ \d \r \n ] + (?< issue > \d + ) / ;
17
+ if ( IGNORE_AUTHORS . includes ( PR_AUTHOR ) ) {
18
+ return core . notice ( "Author in IGNORE_AUTHORS list; skipping..." )
19
+ }
8
20
9
- const isMatch = RELATED_ISSUE_REGEX . exec ( prBody ) ;
21
+ if ( PR_ACTION != "opened" ) {
22
+ return core . notice ( "Only newly open PRs are labelled to avoid spam; skipping" )
23
+ }
24
+
25
+ const RELATED_ISSUE_REGEX = / I s s u e n u m b e r : [ ^ \d \r \n ] + (?< issue > \d + ) / ;
26
+ const isMatch = RELATED_ISSUE_REGEX . exec ( PR_BODY ) ;
10
27
if ( isMatch == null ) {
11
28
core . info ( `No related issue found, maybe the author didn't use the template but there is one.` )
12
29
@@ -15,14 +32,14 @@ module.exports = async ({github, context, core}) => {
15
32
owner : context . repo . owner ,
16
33
repo : context . repo . repo ,
17
34
body : msg ,
18
- issue_number : prNumber ,
35
+ issue_number : PR_NUMBER ,
19
36
} ) ;
20
37
21
38
return await github . rest . issues . addLabels ( {
22
- issue_number : prNumber ,
39
+ issue_number : PR_NUMBER ,
23
40
owner : context . repo . owner ,
24
41
repo : context . repo . repo ,
25
- labels : [ blockLabel , blockReasonLabel ]
42
+ labels : [ BLOCK_LABEL , BLOCK_REASON_LABEL ]
26
43
} )
27
44
}
28
45
}
0 commit comments