@@ -255,53 +255,41 @@ pub(crate) struct RelabelConfig {
255255 pub ( crate ) allow_unauthenticated : Vec < String > ,
256256 // alias identifier -> labels
257257 #[ serde( flatten) ]
258- pub ( crate ) configs : Option < HashMap < String , RelabelRuleConfig > > ,
258+ pub ( crate ) aliases : HashMap < String , RelabelAliasConfig > ,
259259}
260260
261261impl RelabelConfig {
262262 pub ( crate ) fn retrieve_command_from_alias ( & self , input : RelabelCommand ) -> RelabelCommand {
263263 let mut deltas = vec ! [ ] ;
264- match & self . configs {
265- Some ( configs) => {
266- // parse all tokens: if one matches an alias, extract the labels
267- // else, it will assumed to be a valid label
268- if input. 0 . len ( ) > 0 {
269- for tk in input. 0 . iter ( ) {
270- let name = tk. label ( ) . as_str ( ) ;
271- if configs. contains_key ( name) {
272- if let Some ( ( _, cfg) ) = configs. get_key_value ( name) {
273- let cmd = cfg. to_command ( ) ;
274- for d in cmd. 0 {
275- deltas. push ( d) ;
276- }
277- }
278- } else {
279- deltas. push ( tk. clone ( ) ) ;
280- }
281- }
264+ if self . aliases . is_empty ( ) {
265+ // parse all tokens: if one matches an alias, extract the labels
266+ // else, it will assumed to be a valid label
267+ for tk in input. 0 . into_iter ( ) {
268+ let name = tk. label ( ) . as_str ( ) ;
269+ if let Some ( alias) = self . aliases . get ( name) {
270+ let cmd = alias. to_command ( ) ;
271+ deltas. extend ( cmd. 0 ) ;
272+ } else {
273+ deltas. push ( tk) ;
282274 }
283275 }
284- None => {
285- // nothing to do, return the original command
286- return input;
287- }
288- } ;
276+ }
289277 RelabelCommand ( deltas)
290278 }
291279}
292280
293281#[ derive( Default , PartialEq , Eq , Debug , serde:: Deserialize ) ]
294282#[ serde( rename_all = "kebab-case" ) ]
295283#[ serde( deny_unknown_fields) ]
296- pub ( crate ) struct RelabelRuleConfig {
284+ pub ( crate ) struct RelabelAliasConfig {
297285 /// Labels to be added
298286 pub ( crate ) add_labels : Vec < String > ,
299287 /// Labels to be removed
300288 pub ( crate ) rem_labels : Vec < String > ,
301289}
302290
303- impl RelabelRuleConfig {
304- /// Translate a RelabelRuleConfig into a RelabelCommand for GitHub consumption
291+ impl RelabelAliasConfig {
292+ /// Translate a RelabelAliasConfig into a RelabelCommand for GitHub consumption
305293 pub fn to_command ( & self ) -> RelabelCommand {
306294 let mut deltas = Vec :: new ( ) ;
307295 for l in self . add_labels . iter ( ) {
@@ -887,7 +875,7 @@ mod tests {
887875 Config {
888876 relabel: Some ( RelabelConfig {
889877 allow_unauthenticated: vec![ "C-*" . into( ) ] ,
890- configs : Some ( HashMap :: new( ) )
878+ aliases : HashMap :: new( )
891879 } ) ,
892880 assign: Some ( AssignConfig {
893881 warn_non_default_branch: WarnNonDefaultBranchConfig :: Simple ( false ) ,
@@ -1098,7 +1086,7 @@ mod tests {
10981086 let mut relabel_configs = HashMap :: new ( ) ;
10991087 relabel_configs. insert (
11001088 "to-stable" . into ( ) ,
1101- RelabelRuleConfig {
1089+ RelabelAliasConfig {
11021090 add_labels : vec ! [ "regression-from-stable-to-stable" . to_string( ) ] ,
11031091 rem_labels : vec ! [
11041092 "regression-from-stable-to-beta" . to_string( ) ,
@@ -1109,7 +1097,7 @@ mod tests {
11091097
11101098 let expected_cfg = RelabelConfig {
11111099 allow_unauthenticated : vec ! [ ] ,
1112- configs : Some ( relabel_configs) ,
1100+ aliases : relabel_configs,
11131101 } ;
11141102
11151103 assert_eq ! ( config. relabel, Some ( expected_cfg) ) ;
0 commit comments