Updates will be applied on October 27th between 12pm - 12:45pm EDT (UTC-0400). Gitlab may be slow during the maintenance window.

Commit 91f1ee0b authored by Ben Boeckel's avatar Ben Boeckel
Browse files

api/projects: support unlabeling a merge request

parent 98a3e64c
......@@ -13,6 +13,8 @@
options).
* The `api::projects::pipelines::PipelineVariables` endpoint is now pageable.
* All `EnableState` fields may now be set using `bool` values.
* The `api::projects::merge_requests::EditMergeRequest` endpoint now supports
unlabeling a merge request.
## Fixes
......
......@@ -15,6 +15,21 @@ use crate::api::endpoint_prelude::*;
use crate::api::projects::merge_requests::create::Assignee;
use crate::api::ParamValue;
#[derive(Debug, Clone)]
enum MergeRequestLabels<'a> {
Unlabeled,
Labeled(BTreeSet<Cow<'a, str>>),
}
impl<'a, 'b: 'a> ParamValue<'a> for &'b MergeRequestLabels<'a> {
fn as_value(self) -> Cow<'a, str> {
match self {
MergeRequestLabels::Unlabeled => "".into(),
MergeRequestLabels::Labeled(labels) => format!("{}", labels.iter().format(",")).into(),
}
}
}
/// States an issue may be set to.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum MergeRequestStateEvent {
......@@ -63,7 +78,7 @@ pub struct EditMergeRequest<'a> {
milestone_id: Option<u64>,
/// Labels to add to the merge request.
#[builder(setter(name = "_labels"), default, private)]
labels: BTreeSet<Cow<'a, str>>,
labels: Option<MergeRequestLabels<'a>>,
/// The description of the merge request.
#[builder(setter(into), default)]
description: Option<Cow<'a, str>>,
......@@ -140,14 +155,27 @@ impl<'a> EditMergeRequestBuilder<'a> {
self
}
/// Clear all labels
pub fn remove_labels(&mut self) -> &mut Self {
self.labels = Some(Some(MergeRequestLabels::Unlabeled));
self
}
/// Add a label.
pub fn label<L>(&mut self, label: L) -> &mut Self
where
L: Into<Cow<'a, str>>,
{
self.labels
.get_or_insert_with(BTreeSet::new)
.insert(label.into());
let label = label.into();
let labels = if let Some(Some(MergeRequestLabels::Labeled(mut set))) = self.labels.take() {
set.insert(label);
set
} else {
let mut set = BTreeSet::new();
set.insert(label);
set
};
self.labels = Some(Some(MergeRequestLabels::Labeled(labels)));
self
}
......@@ -157,9 +185,14 @@ impl<'a> EditMergeRequestBuilder<'a> {
I: Iterator<Item = L>,
L: Into<Cow<'a, str>>,
{
self.labels
.get_or_insert_with(BTreeSet::new)
.extend(iter.map(Into::into));
let iter = iter.map(Into::into);
let labels = if let Some(Some(MergeRequestLabels::Labeled(mut set))) = self.labels.take() {
set.extend(iter);
set
} else {
iter.collect()
};
self.labels = Some(Some(MergeRequestLabels::Labeled(labels)));
self
}
}
......@@ -184,6 +217,7 @@ impl<'a> Endpoint for EditMergeRequest<'a> {
.push_opt("target_branch", self.target_branch.as_ref())
.push_opt("title", self.title.as_ref())
.push_opt("milestone_id", self.milestone_id)
.push_opt("labels", self.labels.as_ref())
.push_opt("description", self.description.as_ref())
.push_opt("state_event", self.state_event)
.push_opt("remove_source_branch", self.remove_source_branch)
......@@ -191,9 +225,6 @@ impl<'a> Endpoint for EditMergeRequest<'a> {
.push_opt("discussion_locked", self.discussion_locked)
.push_opt("allow_collaboration", self.allow_collaboration);
if !self.labels.is_empty() {
params.push("labels", format!("{}", self.labels.iter().format(",")));
}
if let Some(assignee) = self.assignee.as_ref() {
assignee.add_params(&mut params);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment