@@ -265,9 +265,9 @@ impl RelabelConfig {
265265 // parse all tokens: if one matches an alias, extract the labels
266266 // else, it will assumed to be a valid label
267267 for tk in input. 0 . into_iter ( ) {
268- let name = tk. label ( ) . as_str ( ) ;
268+ let name = tk. label ( ) as & str ;
269269 if let Some ( alias) = self . aliases . get ( name) {
270- let cmd = alias. to_command ( ) ;
270+ let cmd = alias. to_command ( matches ! ( tk , LabelDelta :: Remove ( _ ) ) ) ;
271271 deltas. extend ( cmd. 0 ) ;
272272 } else {
273273 deltas. push ( tk) ;
@@ -290,12 +290,20 @@ pub(crate) struct RelabelAliasConfig {
290290
291291impl RelabelAliasConfig {
292292 /// Translate a RelabelAliasConfig into a RelabelCommand for GitHub consumption
293- pub fn to_command ( & self ) -> RelabelCommand {
293+ pub fn to_command ( & self , inverted : bool ) -> RelabelCommand {
294294 let mut deltas = Vec :: new ( ) ;
295- for l in self . add_labels . iter ( ) {
295+ let mut add_labels = & self . add_labels ;
296+ let mut rem_labels = & self . rem_labels ;
297+
298+ // if the polarity of the alias is inverted, swap labels before parsing the command
299+ if inverted {
300+ std:: mem:: swap ( & mut add_labels, & mut rem_labels) ;
301+ }
302+
303+ for l in add_labels. iter ( ) {
296304 deltas. push ( LabelDelta :: Add ( Label ( l. into ( ) ) ) ) ;
297305 }
298- for l in self . rem_labels . iter ( ) {
306+ for l in rem_labels. iter ( ) {
299307 deltas. push ( LabelDelta :: Remove ( Label ( l. into ( ) ) ) ) ;
300308 }
301309 RelabelCommand ( deltas)
@@ -1145,9 +1153,9 @@ mod tests {
11451153 assert_eq ! (
11461154 new_input,
11471155 RelabelCommand ( vec![
1148- LabelDelta :: Remove ( Label ( "Alpha" . into( ) ) ) ,
11491156 LabelDelta :: Add ( Label ( "Bravo" . into( ) ) ) ,
11501157 LabelDelta :: Add ( Label ( "Charlie" . into( ) ) ) ,
1158+ LabelDelta :: Remove ( Label ( "Alpha" . into( ) ) ) ,
11511159 ] )
11521160 ) ;
11531161 }
0 commit comments