@@ -404,6 +404,36 @@ function labelsIncludeTrigger(labels: JsonValue | undefined, policy: JsonObject)
404404 return false ;
405405}
406406
407+ function issueAssignedToBot ( issue : JsonObject , policy : JsonObject ) : boolean {
408+ const wanted = new Set ( ( ( policy . bot_usernames as JsonValue [ ] ) || [ ] ) . map ( ( username ) => String ( username ) . toLowerCase ( ) ) ) ;
409+ if ( wanted . size === 0 ) {
410+ return false ;
411+ }
412+ const assignees : JsonValue [ ] = [ ] ;
413+ if ( issue . assignee ) {
414+ assignees . push ( issue . assignee ) ;
415+ }
416+ if ( Array . isArray ( issue . assignees ) ) {
417+ assignees . push ( ...issue . assignees ) ;
418+ }
419+ for ( const assignee of assignees ) {
420+ const login = typeof assignee === "object" && assignee !== null && ! Array . isArray ( assignee )
421+ ? String ( ( assignee as JsonObject ) . login || "" )
422+ : String ( assignee ) ;
423+ if ( wanted . has ( login . toLowerCase ( ) ) ) {
424+ return true ;
425+ }
426+ }
427+ return false ;
428+ }
429+
430+ function triggerEnabled ( policy : JsonObject , trigger : string ) : boolean {
431+ if ( policy . enabled_triggers === undefined ) {
432+ return true ;
433+ }
434+ return new Set ( ( ( policy . enabled_triggers as JsonValue [ ] ) || [ ] ) . map ( ( value ) => String ( value ) ) ) . has ( trigger ) ;
435+ }
436+
407437export function buildTaskFromEvent (
408438 eventName : string ,
409439 deliveryId : string ,
@@ -437,6 +467,12 @@ export function buildTaskFromEvent(
437467 if ( eventName === "issue_comment" ) {
438468 const issue = ( payload . issue as JsonObject | undefined ) || { } ;
439469 const comment = ( payload . comment as JsonObject | undefined ) || { } ;
470+ if ( payload . action !== "created" ) {
471+ return ignored ( base , "unsupported_issue_comment_action" ) ;
472+ }
473+ if ( ! triggerEnabled ( policy , "issue_comment.created" ) ) {
474+ return ignored ( base , "issue_comment_not_enabled" ) ;
475+ }
440476 if ( ! mentioned ( comment . body , policy ) ) {
441477 return ignored ( base , "issue_comment_without_mention" ) ;
442478 }
@@ -468,6 +504,12 @@ export function buildTaskFromEvent(
468504 if ( eventName === "pull_request_review_comment" ) {
469505 const comment = ( payload . comment as JsonObject | undefined ) || { } ;
470506 const pullRequest = ( payload . pull_request as JsonObject | undefined ) || { } ;
507+ if ( payload . action !== "created" ) {
508+ return ignored ( base , "unsupported_pr_review_comment_action" ) ;
509+ }
510+ if ( ! triggerEnabled ( policy , "pull_request_review_comment.created" ) ) {
511+ return ignored ( base , "pr_review_comment_not_enabled" ) ;
512+ }
471513 if ( ! mentioned ( comment . body , policy ) ) {
472514 return ignored ( base , "pr_review_comment_without_mention" ) ;
473515 }
@@ -492,14 +534,23 @@ export function buildTaskFromEvent(
492534 if ( eventName === "issues" ) {
493535 const issue = ( payload . issue as JsonObject | undefined ) || { } ;
494536 const action = payload . action ;
495- if ( action !== "assigned" && action !== "labeled" && action !== "opened" ) {
537+ if ( action !== "assigned" && action !== "labeled" ) {
496538 return ignored ( base , "unsupported_issue_action" ) ;
497539 }
540+ if ( action === "assigned" && ! triggerEnabled ( policy , "issues.assigned" ) ) {
541+ return ignored ( base , "issue_assigned_not_enabled" ) ;
542+ }
543+ if ( action === "assigned" && ! issueAssignedToBot ( issue , policy ) ) {
544+ return ignored ( base , "issue_assigned_to_unmanaged_user" ) ;
545+ }
546+ if ( action === "labeled" && ! triggerEnabled ( policy , "issues.labeled" ) ) {
547+ return ignored ( base , "issue_label_not_enabled" ) ;
548+ }
498549 if ( action === "labeled" && ! labelsIncludeTrigger ( issue . labels , policy ) ) {
499550 return ignored ( base , "issue_label_not_enabled" ) ;
500551 }
501552 Object . assign ( base , {
502- trigger : action === "assigned" ? " issue_assigned" : "issue_mention ",
553+ trigger : " issue_assigned",
503554 task : {
504555 kind : "fix_issue" ,
505556 issue_number : Number ( issue . number || 0 ) ,
0 commit comments