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

add RebaseMergeRequest

parent 567f5bd7
......@@ -12,7 +12,9 @@
* Added the `api::projects::labels::PromoteLabel` endpoint to promote a project
label to a group label.
* Added the `api::projects:merge_requests::MergeMergeRequest` endpoint to
merge open merge requests
merge open merge requests.
* Added the `api::projects:merge_requests::RebaseMergeRequest` endpoint to
rebase open merge requests when using the fast-forward merge model.
# v0.1301.1
......
......@@ -59,6 +59,7 @@ These API endpoints have been implemented.
* `GET /projects/:project/merge_requests/:merge_request` `projects/merge_requests/merge_request.rs`
* `PUT /projects/:project/merge_requests/:merge_request` `projects/merge_requests/edit.rs`
* `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`
* `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`
......@@ -228,7 +229,6 @@ instead of having to search the page for missing endpoints.
* `GET /projects/:project/merge_requests/:merge_request/participants` https://gitlab.kitware.com/help/api/merge_requests.md#get-single-mr-participants
* `GET /projects/:project/merge_requests/:merge_request/pipelines` https://gitlab.kitware.com/help/api/merge_requests.md#list-mr-pipelines
* `POST /projects/:project/merge_requests/:merge_request/pipelines` https://gitlab.kitware.com/help/api/merge_requests.md#create-mr-pipeline
* `PUT /projects/:project/merge_requests/:merge_request/rebase` https://gitlab.kitware.com/help/api/merge_requests.md#rebase-a-merge-request
This should be a `POST` action.
https://gitlab.com/gitlab-org/gitlab/-/issues/219324
* `POST /projects/:project/merge_requests/:merge_request/reset_spent_time` https://gitlab.kitware.com/help/api/merge_requests.md#reset-spent-time-for-a-merge-request
......
......@@ -17,6 +17,7 @@ mod merge;
mod merge_request;
mod merge_requests;
pub mod notes;
mod rebase;
mod resource_label_events;
pub use self::create::CreateMergeRequest;
......@@ -32,6 +33,9 @@ pub use self::issues_closed_by::IssuesClosedByBuilder;
pub use self::merge_request::MergeRequest;
pub use self::merge_request::MergeRequestBuilder;
pub use self::rebase::RebaseMergeRequest;
pub use self::rebase::RebaseMergeRequestBuilder;
pub use self::merge::MergeMergeRequest;
pub use self::merge::MergeMergeRequestBuilder;
......
// 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.
//! This module implements the server-side rebasing endpoint, which is only relevant if you've set
//! your repository's merge model to __fast forward__ merging.
use derive_builder::Builder;
use crate::api::common::NameOrId;
use crate::api::endpoint_prelude::*;
/// Rebase a merge request.
#[derive(Debug, Builder)]
#[builder(setter(strip_option))]
pub struct RebaseMergeRequest<'a> {
/// The project with the merge request.
#[builder(setter(into))]
project: NameOrId<'a>,
/// The ID of the merge request.
merge_request: u64,
/// Skip CI on rebase?
#[builder(default)]
skip_ci: Option<bool>,
}
impl<'a> RebaseMergeRequest<'a> {
/// Create a builder for the endpoint.
pub fn builder() -> RebaseMergeRequestBuilder<'a> {
RebaseMergeRequestBuilder::default()
}
}
impl<'a> Endpoint for RebaseMergeRequest<'a> {
fn method(&self) -> Method {
Method::PUT
}
fn endpoint(&self) -> Cow<'static, str> {
format!(
"projects/{}/merge_requests/{}/rebase",
self.project, self.merge_request,
)
.into()
}
fn body(&self) -> Result<Option<(&'static str, Vec<u8>)>, BodyError> {
let mut params = FormParams::default();
params.push_opt("skip_ci", self.skip_ci);
params.into_body()
}
}
#[cfg(test)]
mod tests {
use http::Method;
use crate::api::projects::merge_requests::RebaseMergeRequest;
use crate::api::{self, Query};
use crate::test::client::{ExpectedUrl, SingleTestClient};
#[test]
fn project_and_merge_request_are_needed() {
let err = RebaseMergeRequest::builder().build().unwrap_err();
assert_eq!(err, "`project` must be initialized");
}
#[test]
fn project_is_needed() {
let err = RebaseMergeRequest::builder()
.merge_request(1)
.build()
.unwrap_err();
assert_eq!(err, "`project` must be initialized");
}
#[test]
fn merge_request_is_needed() {
let err = RebaseMergeRequest::builder()
.project(1)
.build()
.unwrap_err();
assert_eq!(err, "`merge_request` must be initialized");
}
#[test]
fn project_and_merge_request_are_sufficient() {
RebaseMergeRequest::builder()
.project(1)
.merge_request(1)
.build()
.unwrap();
}
#[test]
fn endpoint() {
let endpoint = ExpectedUrl::builder()
.method(Method::PUT)
.endpoint("projects/simple%2Fproject/merge_requests/1/rebase")
.content_type("application/x-www-form-urlencoded")
.body_str("")
.build()
.unwrap();
let client = SingleTestClient::new_raw(endpoint, "");
let endpoint = RebaseMergeRequest::builder()
.project("simple/project")
.merge_request(1)
.build()
.unwrap();
api::ignore(endpoint).query(&client).unwrap();
}
#[test]
fn endpoint_skip_ci() {
let endpoint = ExpectedUrl::builder()
.method(Method::PUT)
.endpoint("projects/simple%2Fproject/merge_requests/1/rebase")
.content_type("application/x-www-form-urlencoded")
.body_str("skip_ci=true")
.build()
.unwrap();
let client = SingleTestClient::new_raw(endpoint, "");
let endpoint = RebaseMergeRequest::builder()
.project("simple/project")
.merge_request(1)
.skip_ci(true)
.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