Commit 92d0edca authored by Oleg Höfling's avatar Oleg Höfling
Browse files

api/projects/merge_requests: add query for the approval_state endpoint


Signed-off-by: Oleg Höfling's avataroleg.hoefling <oleg.hoefling@gmail.com>
parent 551b283b
......@@ -3,6 +3,8 @@
## Additions
* Added `api::projects::repository::files::FileRaw`
* Added `api::projects::merge_requests::approval_state::MergeRequestApprovalState`
query to access the approval rules state of a particular merge request.
# v0.1306.0
......
......@@ -67,6 +67,7 @@ These API endpoints have been implemented.
https://gitlab.com/gitlab-org/gitlab/-/issues/219324
* `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/approval_state` `projects/merge_requests/approval_state/approval_state.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`
......@@ -247,6 +248,7 @@ instead of having to search the page for missing endpoints.
* `POST /projects/:project/merge_requests/:merge_request/unsubscribe` https://gitlab.kitware.com/help/api/merge_requests.md#unsubscribe-from-a-merge-request
* `GET /projects/:project/merge_requests/:merge_request/versions` https://gitlab.kitware.com/help/api/merge_requests.md#get-mr-diff-versions
* `GET /projects/:project/merge_requests/:merge_request/versions/:version` https://gitlab.kitware.com/help/api/merge_requests.md#get-a-single-mr-diff-version
* `GET /projects/:project/merge_requests/:merge_request/approval_state` https://docs.gitlab.com/ee/api/merge_request_approvals.html#get-the-approval-state-of-merge-requests
* `POST /projects/:project/merge_requests/:merge_request/award_emoji` https://gitlab.kitware.com/help/api/award_emoji.md#award-a-new-emoji
* `GET /projects/:project/merge_requests/:merge_request/award_emoji/:award` https://gitlab.kitware.com/help/api/award_emoji.md#get-single-award-emoji
* `DELETE /projects/:project/merge_requests/:merge_request/award_emoji/:award` https://gitlab.kitware.com/help/api/award_emoji.md#delete-an-award-emoji
......
......@@ -8,6 +8,7 @@
//!
//! These endpoints are used for querying projects merge requests.
pub mod approval_state;
mod approve;
pub mod awards;
mod create;
......
// 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 terms.
//! Project merge request approval rules state API endpoints.
//!
//! These endpoints are used for querying project merge request approval rules state.
//!
//! # Example
//!
//! ```rust,no_run
//! use serde::Deserialize;
//! use gitlab::Gitlab;
//! use gitlab::api::{self, Query};
//! use gitlab::api::projects::merge_requests::approval_state::MergeRequestApprovalState;
//! use gitlab::types::UserBasic;
//!
//! // This enum describes approval rule types.
//! #[derive(Debug, Deserialize, Clone, Copy, PartialEq, Eq)]
//! enum RuleType {
//! // The approval rule gets this type when you press "Add approval rule" in settings.
//! #[serde(rename = "regular")]
//! Regular,
//! // This is the default approval rule when you create a new project.
//! #[serde(rename = "any_approver")]
//! AnyApprover,
//! // This is the approval rule found in Gitlab's code, looks like
//! // it's a dummy value against null dereferencing. Nevertheless, better have it than not.
//! #[serde(rename = "fallback")]
//! Fallback,
//! }
//!
//! // Approval rule as returned by Gitlab REST API.
//! // This is only a partial representation of the full approval rule in a response, for the sake of example.
//! #[derive(Debug, Deserialize)]
//! struct ApprovalRule {
//! name: String,
//! rule_type: RuleType,
//! eligible_approvers: Vec<UserBasic>,
//! users: Vec<UserBasic>,
//! approvals_required: u32,
//! contains_hidden_groups: bool,
//! approved: bool,
//! }
//!
//! // Approval state as returned by Gitlab REST API.
//! // See https://docs.gitlab.com/ee/api/merge_request_approvals.html#get-the-approval-state-of-merge-requests.
//! #[derive(Debug, Deserialize)]
//! struct ApprovalState {
//! approval_rules_overwritten: bool,
//! rules: Vec<ApprovalRule>,
//! }
//!
//! // Create the client.
//! let client = Gitlab::new("gitlab.com", "private-token").unwrap();
//! // Create the endpoint for the merge request 34 in project 12.
//! let endpoint = MergeRequestApprovalState::builder()
//! .project(12)
//! .merge_request(34)
//! .build()
//! .unwrap();
//! // Get the approval rules state for the merge request.
//! let approvals: ApprovalState = endpoint.query(&client).unwrap();
//! ```
mod approval_state;
pub use self::approval_state::MergeRequestApprovalState;
pub use self::approval_state::MergeRequestApprovalStateBuilder;
// 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 terms.
use derive_builder::Builder;
use crate::api::common::NameOrId;
use crate::api::endpoint_prelude::*;
/// Query for approval state of a merge request.
#[derive(Debug, Builder)]
pub struct MergeRequestApprovalState<'a> {
/// The project to query for approval state.
#[builder(setter(into))]
project: NameOrId<'a>,
/// The internal ID of the merge request.
merge_request: u64,
}
impl<'a> MergeRequestApprovalState<'a> {
/// Create a builder for the endpoint.
pub fn builder() -> MergeRequestApprovalStateBuilder<'a> {
MergeRequestApprovalStateBuilder::default()
}
}
impl<'a> Endpoint for MergeRequestApprovalState<'a> {
fn method(&self) -> Method {
Method::GET
}
fn endpoint(&self) -> Cow<'static, str> {
format!(
"projects/{}/merge_requests/{}/approval_state",
self.project, self.merge_request,
)
.into()
}
}
#[cfg(test)]
mod tests {
use crate::api::projects::merge_requests::approval_state::MergeRequestApprovalState;
use crate::api::{self, Query};
use crate::test::client::{ExpectedUrl, SingleTestClient};
#[test]
fn project_and_merge_request_are_needed() {
let err = MergeRequestApprovalState::builder().build().unwrap_err();
assert_eq!(err, "`project` must be initialized");
}
#[test]
fn project_is_needed() {
let err = MergeRequestApprovalState::builder()
.merge_request(1)
.build()
.unwrap_err();
assert_eq!(err, "`project` must be initialized");
}
#[test]
fn merge_request_is_needed() {
let err = MergeRequestApprovalState::builder()
.project(1)
.build()
.unwrap_err();
assert_eq!(err, "`merge_request` must be initialized");
}
#[test]
fn project_and_merge_request_are_sufficient() {
MergeRequestApprovalState::builder()
.project(1)
.merge_request(1)
.build()
.unwrap();
}
#[test]
fn endpoint() {
let endpoint = ExpectedUrl::builder()
.endpoint("projects/simple%2Fproject/merge_requests/1/approval_state")
.build()
.unwrap();
let client = SingleTestClient::new_raw(endpoint, "");
let endpoint = MergeRequestApprovalState::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