1
1
const {
2
2
PR_NUMBER ,
3
+ PR_ACTION ,
3
4
PR_AUTHOR ,
4
5
IGNORE_AUTHORS ,
5
6
} = require ( "./constants" )
6
7
7
- module . exports = async ( { github, context, core} ) => {
8
- if ( IGNORE_AUTHORS . includes ( PR_AUTHOR ) ) {
9
- return core . notice ( "Author in IGNORE_AUTHORS list; skipping..." )
10
- }
11
8
9
+ const notifyAuthor = async ( {
10
+ gh_client,
11
+ owner,
12
+ repository,
13
+ } ) => {
12
14
core . info ( `Commenting on PR ${ PR_NUMBER } ` )
13
15
14
16
let msg = `
@@ -17,10 +19,46 @@ module.exports = async ({github, context, core}) => {
17
19
Please consider breaking into smaller PRs to avoid significant review delays. Ignore if this PR has naturally grown to this size after reviews.
18
20
` ;
19
21
20
- await github . rest . issues . createComment ( {
22
+ try {
23
+ await gh_client . rest . issues . createComment ( {
24
+ owner : owner ,
25
+ repo : repository ,
26
+ body : msg ,
27
+ issue_number : PR_NUMBER ,
28
+ } ) ;
29
+ } catch ( error ) {
30
+ core . setFailed ( "Failed to notify PR author to split large PR" ) ;
31
+ console . error ( err ) ;
32
+ }
33
+ }
34
+
35
+ module . exports = async ( { github, context, core} ) => {
36
+ if ( IGNORE_AUTHORS . includes ( PR_AUTHOR ) ) {
37
+ return core . notice ( "Author in IGNORE_AUTHORS list; skipping..." )
38
+ }
39
+
40
+ if ( PR_ACTION != "labeled" ) {
41
+ return core . notice ( "Only run on PRs labeling actions; skipping" )
42
+ }
43
+
44
+
45
+ /** @type {string[] } */
46
+ const labels = await github . rest . issues . listLabelsOnIssue ( {
21
47
owner : context . repo . owner ,
22
48
repo : context . repo . repo ,
23
- body : msg ,
24
49
issue_number : PR_NUMBER ,
25
- } ) ;
50
+ } )
51
+
52
+ // Schema: https://docs.github.com/en/rest/issues/labels#list-labels-for-an-issue
53
+ for ( const label of labels ) {
54
+ core . info ( `Label: ${ label } ` )
55
+ if ( label . name == "size/XXL" ) {
56
+ await notifyAuthor ( {
57
+ gh_client : github ,
58
+ owner : context . repo . owner ,
59
+ repository : context . repo . repo ,
60
+ } )
61
+ break ;
62
+ }
63
+ }
26
64
}
0 commit comments