@@ -27,43 +27,45 @@ pub(super) async fn parse_input(
2727 // remove. Not much can be done about that currently; the before/after on
2828 // synchronize may be straddling a rebase, which will break diff generation.
2929 if event. action == IssuesAction :: Opened || event. action == IssuesAction :: Synchronize {
30- if let Some ( diff) = event
30+ let diff = event
3131 . issue
3232 . diff ( & ctx. github )
3333 . await
3434 . map_err ( |e| {
3535 log:: error!( "failed to fetch diff: {:?}" , e) ;
3636 } )
37- . unwrap_or_default ( )
38- {
39- let files = files_changed ( & diff) ;
40- let mut autolabels = Vec :: new ( ) ;
41- ' outer: for ( label, cfg) in config. labels . iter ( ) {
37+ . unwrap_or_default ( ) ;
38+ let files = diff. as_deref ( ) . map ( files_changed) ;
39+ let mut autolabels = Vec :: new ( ) ;
40+
41+ ' outer: for ( label, cfg) in config. labels . iter ( ) {
42+ let exclude_patterns: Vec < glob:: Pattern > = cfg
43+ . exclude_labels
44+ . iter ( )
45+ . filter_map ( |label| match glob:: Pattern :: new ( label) {
46+ Ok ( exclude_glob) => Some ( exclude_glob) ,
47+ Err ( error) => {
48+ log:: error!( "Invalid glob pattern: {}" , error) ;
49+ None
50+ }
51+ } )
52+ . collect ( ) ;
53+
54+ for label in event. issue . labels ( ) {
55+ for pat in & exclude_patterns {
56+ if pat. matches ( & label. name ) {
57+ // If we hit an excluded label, ignore this autolabel and check the next
58+ continue ' outer;
59+ }
60+ }
61+ }
62+
63+ if let Some ( files) = & files {
4264 if cfg
4365 . trigger_files
4466 . iter ( )
4567 . any ( |f| files. iter ( ) . any ( |diff_file| diff_file. starts_with ( f) ) )
4668 {
47- let exclude_patterns: Vec < glob:: Pattern > = cfg
48- . exclude_labels
49- . iter ( )
50- . filter_map ( |label| match glob:: Pattern :: new ( label) {
51- Ok ( exclude_glob) => Some ( exclude_glob) ,
52- Err ( error) => {
53- log:: error!( "Invalid glob pattern: {}" , error) ;
54- None
55- }
56- } )
57- . collect ( ) ;
58- for label in event. issue . labels ( ) {
59- for pat in & exclude_patterns {
60- if pat. matches ( & label. name ) {
61- // If we hit an excluded label, ignore this autolabel and check the next
62- continue ' outer;
63- }
64- }
65- }
66-
6769 autolabels. push ( Label {
6870 name : label. to_owned ( ) ,
6971 } ) ;
@@ -74,13 +76,23 @@ pub(super) async fn parse_input(
7476 } ) ;
7577 }
7678 }
77- if !autolabels. is_empty ( ) {
78- return Ok ( Some ( AutolabelInput {
79- add : autolabels,
80- remove : vec ! [ ] ,
81- } ) ) ;
79+
80+ if event. issue . pull_request . is_none ( )
81+ && cfg. new_issue
82+ && event. action == IssuesAction :: Opened
83+ {
84+ autolabels. push ( Label {
85+ name : label. to_owned ( ) ,
86+ } ) ;
8287 }
8388 }
89+
90+ if !autolabels. is_empty ( ) {
91+ return Ok ( Some ( AutolabelInput {
92+ add : autolabels,
93+ remove : vec ! [ ] ,
94+ } ) ) ;
95+ }
8496 }
8597
8698 if event. action == IssuesAction :: Labeled {
0 commit comments