Commit d33f8dc6 authored by Bradley Wood's avatar Bradley Wood
Browse files

add UnapproveMergeRequest

parent 297fb723
......@@ -17,6 +17,8 @@
rebase open merge requests when using the fast-forward merge model.
* Added the `api::projects:merge_requests::ApproveMergeRequest` endpoint to
approve open merge requests.
* Added the `api::projects:merge_requests::UnapproveMergeRequest` endpoint to
unapprove approved merge requests.
# v0.1301.1
......
......@@ -61,6 +61,7 @@ These API endpoints have been implemented.
* `PUT /projects/:project/merge_requests/:merge_request/merge` `projects/merge_requests/merge.rs`
* `PUT /projects/:project/merge_requests/:merge_request/rebase` `projects/merge_requests/rebase.rs`
* `POST /projects/:project/merge_requests/:merge_request/approve` `projects/merge_requests/approve.rs`
* `POST /projects/:project/merge_requests/:merge_request/unapprove` `projects/merge_requests/unapprove.rs`
* `GET /projects/:project/merge_requests/:merge_request/award_emoji` `projects/merge_requests/awards/awards.rs`
* `GET /projects/:project/merge_requests/:merge_request/closes_issues` `projects/merge_requests/issues_closed_by.rs`
* `GET /projects/:project/merge_requests/:merge_request/discussions` `projects/merge_requests/discussions/discussions.rs`
......
......@@ -20,6 +20,7 @@ mod merge_requests;
pub mod notes;
mod rebase;
mod resource_label_events;
mod unapprove;
pub use self::create::CreateMergeRequest;
pub use self::create::CreateMergeRequestBuilder;
......@@ -42,6 +43,8 @@ pub use self::merge::MergeMergeRequestBuilder;
pub use self::approve::ApproveMergeRequest;
pub use self::approve::ApproveMergeRequestBuilder;
pub use self::unapprove::UnapproveMergeRequest;
pub use self::unapprove::UnapproveMergeRequestBuilder;
pub use self::merge_requests::MergeRequestOrderBy;
pub use self::merge_requests::MergeRequestScope;
......
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those s.
use derive_builder::Builder;
use crate::api::common::NameOrId;
use crate::api::endpoint_prelude::*;
/// Unapprove a merge request.
#[derive(Debug, Builder)]
#[builder(setter(strip_option))]
pub struct UnapproveMergeRequest<'a> {
/// The project with the merge request.
#[builder(setter(into))]
project: NameOrId<'a>,
/// The ID of the merge request.
merge_request: u64,
}
impl<'a> UnapproveMergeRequest<'a> {
/// Create a builder for the endpoint.
pub fn builder() -> UnapproveMergeRequestBuilder<'a> {
UnapproveMergeRequestBuilder::default()
}
}
impl<'a> Endpoint for UnapproveMergeRequest<'a> {
fn method(&self) -> Method {
Method::POST
}
fn endpoint(&self) -> Cow<'static, str> {
format!(
"projects/{}/merge_requests/{}/unapprove",
self.project, self.merge_request,
)
.into()
}
fn body(&self) -> Result<Option<(&'static str, Vec<u8>)>, BodyError> {
let params = FormParams::default();
params.into_body()
}
}
#[cfg(test)]
mod tests {
use http::Method;
use crate::api::projects::merge_requests::UnapproveMergeRequest;
use crate::api::{self, Query};
use crate::test::client::{ExpectedUrl, SingleTestClient};
#[test]
fn project_and_merge_request_are_needed() {
let err = UnapproveMergeRequest::builder().build().unwrap_err();
assert_eq!(err, "`project` must be initialized");
}
#[test]
fn project_is_needed() {
let err = UnapproveMergeRequest::builder()
.merge_request(1)
.build()
.unwrap_err();
assert_eq!(err, "`project` must be initialized");
}
#[test]
fn merge_request_is_needed() {
let err = UnapproveMergeRequest::builder()
.project(1)
.build()
.unwrap_err();
assert_eq!(err, "`merge_request` must be initialized");
}
#[test]
fn project_and_merge_request_are_sufficient() {
UnapproveMergeRequest::builder()
.project(1)
.merge_request(1)
.build()
.unwrap();
}
#[test]
fn endpoint() {
let endpoint = ExpectedUrl::builder()
.method(Method::POST)
.endpoint("projects/simple%2Fproject/merge_requests/1/unapprove")
.content_type("application/x-www-form-urlencoded")
.body_str("")
.build()
.unwrap();
let client = SingleTestClient::new_raw(endpoint, "");
let endpoint = UnapproveMergeRequest::builder()
.project("simple/project")
.merge_request(1)
.build()
.unwrap();
api::ignore(endpoint).query(&client).unwrap();
}
}
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