Skip to content

Commit

Permalink
api/projects: add endpoint to delete a deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
mathstuf committed Jun 24, 2024
1 parent c0d85c9 commit 35ba98f
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Additions

* Add `api::projects::DeleteProject` endpoint
* Add `api::projects::deployments::DeleteDeployment` endpoint

# v0.1700.1

Expand Down
2 changes: 1 addition & 1 deletion src/api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ These API endpoints have been implemented.
* `PUT /projects/:project/deploy_keys/:deploy_key` `projects/deploy_keys/edit.rs`
* `DELETE /projects/:project/deploy_keys/:deploy_key` `projects/deploy_keys/delete.rs`
* `POST /projects/:project/deploy_keys/:deploy_key/enable` `projects/deploy_keys/enable.rs`
* `DELETE /projects/:project/deployments/:deployment` `projects/deployments/delete.rs`
* `GET /projects/:project/environments` `projects/environments/environments.rs`
* `GET /projects/:project/environments/:environment` `projects/environments/environment.rs`
* `GET /projects/:project/hooks` `projects/hooks/hooks.rs`
Expand Down Expand Up @@ -351,7 +352,6 @@ instead of having to search the page for missing endpoints.
* `POST /projects/:project/deployments` https://gitlab.kitware.com/help/api/deployments.md#create-a-deployment
* `GET /projects/:project/deployments/:deployment` https://gitlab.kitware.com/help/api/deployments.md#get-a-specific-deployment
* `PUT /projects/:project/deployments/:deployment` https://gitlab.kitware.com/help/api/deployments.md#update-a-deployment
* `DELETE /projects/:project/deployments/:deployment` https://gitlab.kitware.com/help/api/deployments.md#delete-a-specific-deployment
* `GET /projects/:project/deployments/:deployment/merge_requests` https://gitlab.kitware.com/help/api/deployments.md#list-of-merge-requests-associated-with-a-deployment
* `POST /projects/:project/deployments/:deployment/approval` https://gitlab.kitware.com/help/api/deployments.md#approve-or-reject-a-blocked-deployment
* `POST /projects/:project/environments` https://gitlab.kitware.com/help/api/environments.md#create-a-new-environment
Expand Down
1 change: 1 addition & 0 deletions src/api/projects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ mod archive;
mod create;
mod delete;
pub mod deploy_keys;
pub mod deployments;
mod edit;
pub mod environments;
pub mod hooks;
Expand Down
15 changes: 15 additions & 0 deletions src/api/projects/deployments.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// 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 deployment API endpoints.
//!
//! These endpoints are used for querying deployments.
mod delete;

pub use self::delete::DeleteDeployment;
pub use self::delete::DeleteDeploymentBuilder;
pub use self::delete::DeleteDeploymentBuilderError;
100 changes: 100 additions & 0 deletions src/api/projects/deployments/delete.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
// 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::*;

/// Delete a deployment for a project.
#[derive(Debug, Builder, Clone)]
pub struct DeleteDeployment<'a> {
/// The project to delete a deployment from.
#[builder(setter(into))]
project: NameOrId<'a>,
/// The ID of the deployment to delete.
deployment_id: u64,
}

impl<'a> DeleteDeployment<'a> {
/// Create a builder for the endpoint.
pub fn builder() -> DeleteDeploymentBuilder<'a> {
DeleteDeploymentBuilder::default()
}
}

impl<'a> Endpoint for DeleteDeployment<'a> {
fn method(&self) -> Method {
Method::DELETE
}

fn endpoint(&self) -> Cow<'static, str> {
format!(
"projects/{}/deployments/{}",
self.project, self.deployment_id,
)
.into()
}
}

#[cfg(test)]
mod tests {
use http::Method;

use crate::api::projects::deployments::{DeleteDeployment, DeleteDeploymentBuilderError};
use crate::api::{self, Query};
use crate::test::client::{ExpectedUrl, SingleTestClient};

#[test]
fn project_and_deployment_id_are_necessary() {
let err = DeleteDeployment::builder().build().unwrap_err();
crate::test::assert_missing_field!(err, DeleteDeploymentBuilderError, "project");
}

#[test]
fn project_is_necessary() {
let err = DeleteDeployment::builder()
.deployment_id(1)
.build()
.unwrap_err();
crate::test::assert_missing_field!(err, DeleteDeploymentBuilderError, "project");
}

#[test]
fn deployment_id_is_necessary() {
let err = DeleteDeployment::builder()
.project("project")
.build()
.unwrap_err();
crate::test::assert_missing_field!(err, DeleteDeploymentBuilderError, "deployment_id");
}

#[test]
fn project_and_deployment_id_are_sufficient() {
DeleteDeployment::builder()
.project("project")
.deployment_id(1)
.build()
.unwrap();
}

#[test]
fn endpoint() {
let endpoint = ExpectedUrl::builder()
.method(Method::DELETE)
.endpoint("projects/simple%2Fproject/deployments/1")
.build()
.unwrap();
let client = SingleTestClient::new_raw(endpoint, "");

let endpoint = DeleteDeployment::builder()
.project("simple/project")
.deployment_id(1)
.build()
.unwrap();
api::ignore(endpoint).query(&client).unwrap();
}
}

0 comments on commit 35ba98f

Please sign in to comment.