gitea_sdk/api/repos/contents/
delete_file.rs

1use build_it::Builder;
2use serde::{Deserialize, Serialize};
3
4use crate::{
5    model::repos::{CommitDateOptions, EntryMutation, Identity},
6    Result,
7};
8
9#[derive(Debug, Serialize, Deserialize, Builder)]
10#[build_it(into)]
11pub struct DeleteFileRepoBuilder {
12    /// The owner of the repository.
13    #[skip]
14    #[serde(skip)]
15    owner: String,
16    /// The name of the repository.
17    #[skip]
18    #[serde(skip)]
19    repo: String,
20    /// Path of the file to delete.
21    #[skip]
22    #[serde(skip)]
23    filepath: String,
24    /// Identity for a person's identity like an author or committer.
25    #[serde(skip_serializing_if = "Option::is_none")]
26    author: Option<Identity>,
27    /// Branch (optional) to base this file from. if not given, the default branch is used.
28    #[serde(skip_serializing_if = "Option::is_none")]
29    branch: Option<String>,
30    // Identity for a person's identity like an author or committer
31    #[serde(skip_serializing_if = "Option::is_none")]
32    committer: Option<Identity>,
33    /// CommitDateOptions store dates for GIT_AUTHOR_DATE and GIT_COMMITTER_DATE
34    dates: Option<CommitDateOptions>,
35    /// Message (optional) for the commit of this file. if not supplied, a default message will be used
36    message: Option<String>,
37    /// new_branch (optional) will make a new branch from branch before creating the file
38    new_branch: Option<String>,
39    /// sha is the SHA for the file that already exists
40    #[skip]
41    sha: String,
42    /// Add a Signed-off-by trailer by the committer at the end of the commit log message.
43    signoff: Option<bool>,
44}
45
46impl DeleteFileRepoBuilder {
47    pub fn new(
48        owner: impl ToString,
49        repo: impl ToString,
50        filepath: impl ToString,
51        sha: impl ToString,
52    ) -> Self {
53        Self {
54            owner: owner.to_string(),
55            repo: repo.to_string(),
56            filepath: filepath.to_string(),
57            author: None,
58            branch: None,
59            committer: None,
60            dates: None,
61            message: None,
62            new_branch: None,
63            sha: sha.to_string(),
64            signoff: None,
65        }
66    }
67
68    /// Send the request to delete file from given repository.
69    pub async fn send(&self, client: &crate::Client) -> Result<EntryMutation> {
70        let owner = &self.owner;
71        let repo = &self.repo;
72        let filepath = &self.filepath;
73
74        let req = client
75            .delete(format!("repos/{owner}/{repo}/contents/{filepath}"))
76            .json(self)
77            .build()?;
78
79        let res = client.make_request(req).await?;
80
81        client.parse_response(res).await
82    }
83}