@@ -15,17 +15,33 @@ const UNASSIGNED_GFI_SEARCH_URL =
1515 * Optionally preceded or followed by whitespace
1616 */
1717function commentRequestsAssignment ( body ) {
18- return typeof body === 'string' &&
18+ const matches =
19+ typeof body === 'string' &&
1920 / ( ^ | \n ) \s * \/ a s s i g n ( \s | $ ) / i. test ( body ) ;
21+
22+ console . log ( '[gfi-assign] commentRequestsAssignment:' , {
23+ body,
24+ matches,
25+ } ) ;
26+
27+ return matches ;
2028}
2129
2230/**
2331 * Returns true if the issue has the good first issue label.
2432 */
2533function issueIsGoodFirstIssue ( issue ) {
26- return issue ?. labels ?. some ( label => label . name === GOOD_FIRST_ISSUE_LABEL ) ;
27- }
34+ const labels = issue ?. labels ?. map ( label => label . name ) ?? [ ] ;
35+ const isGfi = labels . includes ( GOOD_FIRST_ISSUE_LABEL ) ;
2836
37+ console . log ( '[gfi-assign] issueIsGoodFirstIssue:' , {
38+ labels,
39+ expected : GOOD_FIRST_ISSUE_LABEL ,
40+ isGfi,
41+ } ) ;
42+
43+ return isGfi ;
44+ }
2945/// HELPERS FOR COMMENTING ///
3046
3147/**
@@ -54,38 +70,78 @@ Once you find one you like, comment \`/assign\` to get started.`
5470
5571/// START OF SCRIPT ///
5672module . exports = async ( { github, context } ) => {
73+
5774 const { issue, comment } = context . payload ;
5875 const { owner, repo } = context . repo ;
5976
77+ console . log ( '[gfi-assign] Payload snapshot:' , {
78+ issueNumber : issue ?. number ,
79+ commenter : comment ?. user ?. login ,
80+ commenterType : comment ?. user ?. type ,
81+ commentBody : comment ?. body ,
82+ } ) ;
83+
6084 // Reject if issue, comment or comment user is missing, reject bots, or if no /assign message
61- if (
62- ! issue ?. number ||
63- ! comment ?. body ||
64- ! comment ?. user ?. login ||
65- comment . user . type === 'Bot' ||
66- ! commentRequestsAssignment ( comment . body )
67- ) {
85+ if ( ! issue ?. number ) {
86+ console . log ( '[gfi-assign] Exit: missing issue number' ) ;
87+ return ;
88+ }
89+
90+ if ( ! comment ?. body ) {
91+ console . log ( '[gfi-assign] Exit: missing comment body' ) ;
92+ return ;
93+ }
94+
95+ if ( ! comment ?. user ?. login ) {
96+ console . log ( '[gfi-assign] Exit: missing comment user login' ) ;
6897 return ;
6998 }
99+
100+ if ( comment . user . type === 'Bot' ) {
101+ console . log ( '[gfi-assign] Exit: comment authored by bot' ) ;
102+ return ;
103+ }
104+
105+ if ( ! commentRequestsAssignment ( comment . body ) ) {
106+ console . log ( '[gfi-assign] Exit: comment does not request assignment' ) ;
107+ return ;
108+ }
109+
110+ console . log ( '[gfi-assign] Assignment command detected' ) ;
111+
70112 // Reject if issue is not a Good First Issue
71- if ( ! issueIsGoodFirstIssue ( issue ) ) return ;
113+ if ( ! issueIsGoodFirstIssue ( issue ) ) {
114+ console . log ( '[gfi-assign] Exit: issue is not a Good First Issue' ) ;
115+ return ;
116+ }
117+
118+ console . log ( '[gfi-assign] Issue is labeled Good First Issue' ) ;
72119
73120 // Get requester username and issue number to enable comments and assignments
74121 const requesterUsername = comment . user . login ;
75122 const issueNumber = issue . number ;
76123
124+ console . log ( '[gfi-assign] Requester:' , requesterUsername ) ;
125+ console . log ( '[gfi-assign] Current assignees:' , issue . assignees ?. map ( a => a . login ) ) ;
126+
77127 // Reject if issue is already assigned
78128 // Comment failure to the requester
79129 if ( issue . assignees ?. length > 0 ) {
130+ console . log ( '[gfi-assign] Exit: issue already assigned' ) ;
131+
80132 await github . rest . issues . createComment ( {
81133 owner,
82134 repo,
83135 issue_number : issueNumber ,
84136 body : commentAlreadyAssigned ( requesterUsername , issue ) ,
85137 } ) ;
138+
139+ console . log ( '[gfi-assign] Posted already-assigned comment' ) ;
86140 return ;
87141 }
88142
143+ console . log ( '[gfi-assign] Assigning issue to requester' ) ;
144+
89145 // All validations passed and user has requested assignment on a GFI
90146 // Assign the issue to the requester
91147 // Do not comment on success
@@ -95,4 +151,6 @@ module.exports = async ({ github, context }) => {
95151 issue_number : issueNumber ,
96152 assignees : [ requesterUsername ] ,
97153 } ) ;
98- } ;
154+
155+ console . log ( '[gfi-assign] Assignment completed successfully' ) ;
156+ } ;
0 commit comments