Commit 91e3a2fc authored by Levente Polyak's avatar Levente Polyak
Browse files

api/projects: add endpoint to query specific proteted_branch

parent 524a9892
......@@ -15,6 +15,8 @@
groups subgroups.
* Added the `api::projects::protected_branches::ProtectedBranches` endpoint
to list a projects protected branches.
* Added the `api::projects::protected_branches::ProtectedBranch` endpoint
to query a projects protected branch.
# v0.1301.0
......
......@@ -76,6 +76,7 @@ These API endpoints have been implemented.
* `POST /projects/:project/protected_branches` `projects/protected_branches/protect.rs`
* `DELETE /projects/:project/protected_branches/*branch` `projects/protected_branches/unprotect.rs`
* `GET /projects/:project/protected_branches` `projects/protected_branches/protected_branches.rs`
* `GET /projects/:project/protected_branches/:branch` `projects/protected_branches/protected_branch.rs`
* `GET /projects/:project/repository/branches` `projects/repository/branches/branches.rs`
* `POST /projects/:project/repository/branches` `projects/repository/branches/create.rs`
* `GET /projects/:project/repository/branches/:branch` `projects/repository/branches/branch.rs`
......
......@@ -9,6 +9,7 @@
//! These endpoints are used for querying a project's protected branches.
mod protect;
mod protected_branch;
mod protected_branches;
mod unprotect;
......@@ -20,5 +21,8 @@ pub use self::protect::ProtectedAccessLevel;
pub use self::unprotect::UnprotectBranch;
pub use self::unprotect::UnprotectBranchBuilder;
pub use self::protected_branch::ProtectedBranch;
pub use self::protected_branch::ProtectedBranchBuilder;
pub use self::protected_branches::ProtectedBranches;
pub use self::protected_branches::ProtectedBranchesBuilder;
// 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::{self, NameOrId};
use crate::api::endpoint_prelude::*;
/// Query a protected branch of a project.
#[derive(Debug, Clone, Builder)]
pub struct ProtectedBranch<'a> {
/// The project to query for the protected branch.
#[builder(setter(into))]
project: NameOrId<'a>,
/// The name of the branch or wildcard.
#[builder(setter(into))]
name: Cow<'a, str>,
}
impl<'a> ProtectedBranch<'a> {
/// Create a builder for the endpoint.
pub fn builder() -> ProtectedBranchBuilder<'a> {
ProtectedBranchBuilder::default()
}
}
impl<'a> Endpoint for ProtectedBranch<'a> {
fn method(&self) -> Method {
Method::GET
}
fn endpoint(&self) -> Cow<'static, str> {
format!(
"projects/{}/protected_branches/{}",
self.project,
common::path_escaped(&self.name)
)
.into()
}
fn parameters(&self) -> QueryParams {
QueryParams::default()
}
}
#[cfg(test)]
mod tests {
use crate::api::projects::protected_branches::ProtectedBranch;
use crate::api::{self, Query};
use crate::test::client::{ExpectedUrl, SingleTestClient};
#[test]
fn project_is_needed() {
let err = ProtectedBranch::builder().build().unwrap_err();
assert_eq!(err, "`project` must be initialized");
}
#[test]
fn name_is_needed() {
let err = ProtectedBranch::builder()
.project("project_name")
.build()
.unwrap_err();
assert_eq!(err, "`name` must be initialized");
}
#[test]
fn project_and_name_are_sufficient() {
ProtectedBranch::builder()
.project(1)
.name("master")
.build()
.unwrap();
}
#[test]
fn endpoint() {
let endpoint = ExpectedUrl::builder()
.endpoint("projects/group%2Fproject/protected_branches/master")
.build()
.unwrap();
let client = SingleTestClient::new_raw(endpoint, "");
let endpoint = ProtectedBranch::builder()
.project("group/project")
.name("master")
.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