@@ -16,104 +16,104 @@ pub(super) async fn parse_input(
1616 event : & IssuesEvent ,
1717 config : Option < & AutolabelConfig > ,
1818) -> Result < Option < AutolabelInput > , String > {
19+ let config = match config {
20+ Some ( config) => config,
21+ None => return Ok ( None ) ,
22+ } ;
1923 // On opening a new PR or sync'ing the branch, look at the diff and try to
2024 // add any appropriate labels.
2125 //
2226 // FIXME: This will re-apply labels after a push that the user had tried to
2327 // remove. Not much can be done about that currently; the before/after on
2428 // synchronize may be straddling a rebase, which will break diff generation.
25- if let Some ( config) = config {
26- if event. action == IssuesAction :: Opened || event. action == IssuesAction :: Synchronize {
27- if let Some ( diff) = event
28- . issue
29- . diff ( & ctx. github )
30- . await
31- . map_err ( |e| {
32- log:: error!( "failed to fetch diff: {:?}" , e) ;
33- } )
34- . unwrap_or_default ( )
35- {
36- let files = files_changed ( & diff) ;
37- let mut autolabels = Vec :: new ( ) ;
38- ' outer: for ( label, cfg) in config. labels . iter ( ) {
39- if cfg
40- . trigger_files
29+ if event. action == IssuesAction :: Opened || event. action == IssuesAction :: Synchronize {
30+ if let Some ( diff) = event
31+ . issue
32+ . diff ( & ctx. github )
33+ . await
34+ . map_err ( |e| {
35+ log:: error!( "failed to fetch diff: {:?}" , e) ;
36+ } )
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 ( ) {
42+ if cfg
43+ . trigger_files
44+ . iter ( )
45+ . any ( |f| files. iter ( ) . any ( |diff_file| diff_file. starts_with ( f) ) )
46+ {
47+ let exclude_patterns: Vec < glob:: Pattern > = cfg
48+ . exclude_labels
4149 . iter ( )
42- . any ( |f| files. iter ( ) . any ( |diff_file| diff_file. starts_with ( f) ) )
43- {
44- let exclude_patterns: Vec < glob:: Pattern > = cfg
45- . exclude_labels
46- . iter ( )
47- . filter_map ( |label| match glob:: Pattern :: new ( label) {
48- Ok ( exclude_glob) => Some ( exclude_glob) ,
49- Err ( error) => {
50- log:: error!( "Invalid glob pattern: {}" , error) ;
51- None
52- }
53- } )
54- . collect ( ) ;
55- for label in event. issue . labels ( ) {
56- for pat in & exclude_patterns {
57- if pat. matches ( & label. name ) {
58- // If we hit an excluded label, ignore this autolabel and check the next
59- continue ' outer;
60- }
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;
6163 }
6264 }
63-
64- autolabels. push ( Label {
65- name : label. to_owned ( ) ,
66- } ) ;
6765 }
66+
67+ autolabels. push ( Label {
68+ name : label. to_owned ( ) ,
69+ } ) ;
6870 }
69- if !autolabels . is_empty ( ) {
70- return Ok ( Some ( AutolabelInput {
71- add : autolabels ,
72- remove : vec ! [ ] ,
73- } ) ) ;
74- }
71+ }
72+ if !autolabels . is_empty ( ) {
73+ return Ok ( Some ( AutolabelInput {
74+ add : autolabels ,
75+ remove : vec ! [ ] ,
76+ } ) ) ;
7577 }
7678 }
7779 }
7880
7981 if event. action == IssuesAction :: Labeled {
80- if let Some ( config) = config {
81- let mut autolabels = Vec :: new ( ) ;
82- let applied_label = & event. label . as_ref ( ) . expect ( "label" ) . name ;
82+ let mut autolabels = Vec :: new ( ) ;
83+ let applied_label = & event. label . as_ref ( ) . expect ( "label" ) . name ;
8384
84- ' outer: for ( label, config) in config. get_by_trigger ( applied_label) {
85- let exclude_patterns: Vec < glob:: Pattern > = config
86- . exclude_labels
87- . iter ( )
88- . filter_map ( |label| match glob:: Pattern :: new ( label) {
89- Ok ( exclude_glob) => Some ( exclude_glob) ,
90- Err ( error) => {
91- log:: error!( "Invalid glob pattern: {}" , error) ;
92- None
93- }
94- } )
95- . collect ( ) ;
85+ ' outer: for ( label, config) in config. get_by_trigger ( applied_label) {
86+ let exclude_patterns: Vec < glob:: Pattern > = config
87+ . exclude_labels
88+ . iter ( )
89+ . filter_map ( |label| match glob:: Pattern :: new ( label) {
90+ Ok ( exclude_glob) => Some ( exclude_glob) ,
91+ Err ( error) => {
92+ log:: error!( "Invalid glob pattern: {}" , error) ;
93+ None
94+ }
95+ } )
96+ . collect ( ) ;
9697
97- for label in event. issue . labels ( ) {
98- for pat in & exclude_patterns {
99- if pat. matches ( & label. name ) {
100- // If we hit an excluded label, ignore this autolabel and check the next
101- continue ' outer;
102- }
98+ for label in event. issue . labels ( ) {
99+ for pat in & exclude_patterns {
100+ if pat. matches ( & label. name ) {
101+ // If we hit an excluded label, ignore this autolabel and check the next
102+ continue ' outer;
103103 }
104104 }
105-
106- // If we reach here, no excluded labels were found, so we should apply the autolabel.
107- autolabels. push ( Label {
108- name : label. to_owned ( ) ,
109- } ) ;
110- }
111- if !autolabels. is_empty ( ) {
112- return Ok ( Some ( AutolabelInput {
113- add : autolabels,
114- remove : vec ! [ ] ,
115- } ) ) ;
116105 }
106+
107+ // If we reach here, no excluded labels were found, so we should apply the autolabel.
108+ autolabels. push ( Label {
109+ name : label. to_owned ( ) ,
110+ } ) ;
111+ }
112+ if !autolabels. is_empty ( ) {
113+ return Ok ( Some ( AutolabelInput {
114+ add : autolabels,
115+ remove : vec ! [ ] ,
116+ } ) ) ;
117117 }
118118 }
119119 Ok ( None )
0 commit comments