-
Notifications
You must be signed in to change notification settings - Fork 97
Add alias for compound labels #2172
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,9 +24,16 @@ pub(super) async fn handle_command( | |
event: &Event, | ||
input: RelabelCommand, | ||
) -> anyhow::Result<()> { | ||
let mut results = vec![]; | ||
let mut to_rem = vec![]; | ||
let mut to_add = vec![]; | ||
for delta in &input.0 { | ||
|
||
// If the input matches a valid alias, read the [relabel] config. | ||
// if any alias matches, extract the alias config (RelabelRuleConfig) and build a new RelabelCommand. | ||
// Discard anything after the alias. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we should discard anything, at least not silently. In my opinion we should simply expand all the aliases, and if someone does There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When I implemented this patch I thought about allowing both labels and aliases but ultimately discarded the option. My reasoning was that it would open up to contradicting labelling cases:
I think a user should either send ONE command alias or a set of labels, not both. If a user wants to send many labels, they can configure an alias. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We already have the issue when someone does IMO the behavior should be made consistent by using the precedence, from left to right, so in either case (your example and mine) But whatever the behavior I don't this issue as being big enough compare to not allow regular labels and labels to be mixed together, which would just looked like an arbitrary limitation. I could very well see my-self wanting to do We could also error out if the alias and labels conflict, it's less pretty but still an option. |
||
let new_input = config.retrieve_command_from_alias(input); | ||
|
||
// Parse input label command, checks permissions, built GitHub commands | ||
for delta in &new_input.0 { | ||
let name = delta.label().as_str(); | ||
let err = match check_filter(name, config, is_member(&event.user(), &ctx.team).await) { | ||
Ok(CheckFilterResult::Allow) => None, | ||
|
@@ -53,14 +60,12 @@ pub(super) async fn handle_command( | |
}); | ||
} | ||
LabelDelta::Remove(label) => { | ||
results.push(( | ||
label, | ||
event.issue().unwrap().remove_label(&ctx.github, &label), | ||
)); | ||
to_rem.push(label); | ||
} | ||
Comment on lines
-56
to
64
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. here I changed a bit the logic: instead of storing the futures I just store the labels to be removed and then execute the futures later. Functionally I think it changes nothing but the original version (introduced in b6ccaa0) created a lifetime error after my my patch. |
||
} | ||
} | ||
|
||
// Add new labels (if needed) | ||
if let Err(e) = event | ||
.issue() | ||
.unwrap() | ||
|
@@ -84,8 +89,14 @@ pub(super) async fn handle_command( | |
return Err(e); | ||
} | ||
|
||
for (label, res) in results { | ||
if let Err(e) = res.await { | ||
// Remove labels (if needed) | ||
for label in to_rem { | ||
if let Err(e) = event | ||
.issue() | ||
.unwrap() | ||
.remove_label(&ctx.github, &label) | ||
.await | ||
{ | ||
tracing::error!( | ||
"failed to remove {:?} from issue {}: {:?}", | ||
label, | ||
|
@@ -124,6 +135,8 @@ enum CheckFilterResult { | |
DenyUnknown, | ||
} | ||
|
||
/// Check if the team member is allowed to apply labels | ||
/// configured in `allow_unauthenticated` | ||
fn check_filter( | ||
label: &str, | ||
config: &RelabelConfig, | ||
|
@@ -220,6 +233,7 @@ mod tests { | |
($($member:ident { $($label:expr => $res:ident,)* })*) => { | ||
let config = RelabelConfig { | ||
allow_unauthenticated: vec!["T-*".into(), "I-*".into(), "!I-*nominated".into()], | ||
configs: None | ||
}; | ||
$($(assert_eq!( | ||
check_filter($label, &config, TeamMembership::$member), | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the reason for only considering the first token as an alias?
I would expect aliases to work at any position.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see previous comment