Skip to main content

mesa_dev_oapi/apis/
commits_api.rs

1/*
2 * Depot API
3 *
4 * Depot HTTP API v1
5 *
6 * The version of the OpenAPI document: 1.0.0
7 * 
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18/// struct for typed errors of method [`get_by_org_by_repo_commits`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum GetByOrgByRepoCommitsError {
22    Status400(models::PostByOrgApiKeys400Response),
23    Status401(models::PostByOrgApiKeys400Response),
24    Status403(models::PostByOrgApiKeys400Response),
25    Status404(models::PostByOrgApiKeys400Response),
26    Status406(models::PostByOrgApiKeys400Response),
27    Status409(models::PostByOrgApiKeys400Response),
28    Status500(models::PostByOrgApiKeys400Response),
29    UnknownValue(serde_json::Value),
30}
31
32/// struct for typed errors of method [`get_by_org_by_repo_commits_by_sha`]
33#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum GetByOrgByRepoCommitsByShaError {
36    Status400(models::PostByOrgApiKeys400Response),
37    Status401(models::PostByOrgApiKeys400Response),
38    Status403(models::PostByOrgApiKeys400Response),
39    Status404(models::PostByOrgApiKeys400Response),
40    Status406(models::PostByOrgApiKeys400Response),
41    Status409(models::PostByOrgApiKeys400Response),
42    Status500(models::PostByOrgApiKeys400Response),
43    UnknownValue(serde_json::Value),
44}
45
46/// struct for typed errors of method [`post_by_org_by_repo_commits`]
47#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum PostByOrgByRepoCommitsError {
50    Status400(models::PostByOrgApiKeys400Response),
51    Status401(models::PostByOrgApiKeys400Response),
52    Status403(models::PostByOrgApiKeys400Response),
53    Status404(models::PostByOrgApiKeys400Response),
54    Status406(models::PostByOrgApiKeys400Response),
55    Status409(models::PostByOrgApiKeys400Response),
56    Status500(models::PostByOrgApiKeys400Response),
57    UnknownValue(serde_json::Value),
58}
59
60
61/// List commits for a repository from a specific ref
62pub async fn get_by_org_by_repo_commits(configuration: &configuration::Configuration, org: &str, repo: &str, cursor: Option<&str>, limit: Option<u8>, r#ref: Option<&str>) -> Result<models::GetByOrgByRepoCommits200Response, Error<GetByOrgByRepoCommitsError>> {
63    // add a prefix to parameters to efficiently prevent name collisions
64    let p_path_org = org;
65    let p_path_repo = repo;
66    let p_query_cursor = cursor;
67    let p_query_limit = limit;
68    let p_query_ref = r#ref;
69
70    let uri_str = format!("{}/{org}/{repo}/commits", configuration.base_path, org=crate::apis::urlencode(p_path_org), repo=crate::apis::urlencode(p_path_repo));
71    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
72
73    if let Some(ref param_value) = p_query_cursor {
74        req_builder = req_builder.query(&[("cursor", &param_value.to_string())]);
75    }
76    if let Some(ref param_value) = p_query_limit {
77        req_builder = req_builder.query(&[("limit", &param_value.to_string())]);
78    }
79    if let Some(ref param_value) = p_query_ref {
80        req_builder = req_builder.query(&[("ref", &param_value.to_string())]);
81    }
82    if let Some(ref user_agent) = configuration.user_agent {
83        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
84    }
85    if let Some(ref token) = configuration.bearer_access_token {
86        req_builder = req_builder.bearer_auth(token.to_owned());
87    };
88
89    let req = req_builder.build()?;
90    let resp = configuration.client.execute(req).await?;
91
92    let status = resp.status();
93    let content_type = resp
94        .headers()
95        .get("content-type")
96        .and_then(|v| v.to_str().ok())
97        .unwrap_or("application/octet-stream");
98    let content_type = super::ContentType::from(content_type);
99
100    if !status.is_client_error() && !status.is_server_error() {
101        let content = resp.text().await?;
102        match content_type {
103            ContentType::Json => serde_path_to_error::deserialize(&mut serde_json::Deserializer::from_str(&content)).map_err(Error::from),
104            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetByOrgByRepoCommits200Response`"))),
105            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::GetByOrgByRepoCommits200Response`")))),
106        }
107    } else {
108        let content = resp.text().await?;
109        let entity: Option<GetByOrgByRepoCommitsError> = serde_json::from_str(&content).ok();
110        Err(Error::ResponseError(ResponseContent { status, content, entity }))
111    }
112}
113
114/// Retrieve a specific commit by its SHA
115pub async fn get_by_org_by_repo_commits_by_sha(configuration: &configuration::Configuration, org: &str, repo: &str, sha: Option<&str>) -> Result<models::GetByOrgByRepoCommitsBySha200Response, Error<GetByOrgByRepoCommitsByShaError>> {
116    // add a prefix to parameters to efficiently prevent name collisions
117    let p_path_org = org;
118    let p_path_repo = repo;
119    let p_path_sha = sha;
120
121    let uri_str = format!("{}/{org}/{repo}/commits/{sha}", configuration.base_path, org=crate::apis::urlencode(p_path_org), repo=crate::apis::urlencode(p_path_repo), sha=crate::apis::urlencode(p_path_sha.unwrap()));
122    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
123
124    if let Some(ref user_agent) = configuration.user_agent {
125        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
126    }
127    if let Some(ref token) = configuration.bearer_access_token {
128        req_builder = req_builder.bearer_auth(token.to_owned());
129    };
130
131    let req = req_builder.build()?;
132    let resp = configuration.client.execute(req).await?;
133
134    let status = resp.status();
135    let content_type = resp
136        .headers()
137        .get("content-type")
138        .and_then(|v| v.to_str().ok())
139        .unwrap_or("application/octet-stream");
140    let content_type = super::ContentType::from(content_type);
141
142    if !status.is_client_error() && !status.is_server_error() {
143        let content = resp.text().await?;
144        match content_type {
145            ContentType::Json => serde_path_to_error::deserialize(&mut serde_json::Deserializer::from_str(&content)).map_err(Error::from),
146            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetByOrgByRepoCommitsBySha200Response`"))),
147            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::GetByOrgByRepoCommitsBySha200Response`")))),
148        }
149    } else {
150        let content = resp.text().await?;
151        let entity: Option<GetByOrgByRepoCommitsByShaError> = serde_json::from_str(&content).ok();
152        Err(Error::ResponseError(ResponseContent { status, content, entity }))
153    }
154}
155
156/// Programmatically create a commit with file edits
157pub async fn post_by_org_by_repo_commits(configuration: &configuration::Configuration, org: &str, repo: &str, post_by_org_by_repo_commits_request: Option<models::PostByOrgByRepoCommitsRequest>) -> Result<models::PostByOrgByRepoCommits201Response, Error<PostByOrgByRepoCommitsError>> {
158    // add a prefix to parameters to efficiently prevent name collisions
159    let p_path_org = org;
160    let p_path_repo = repo;
161    let p_body_post_by_org_by_repo_commits_request = post_by_org_by_repo_commits_request;
162
163    let uri_str = format!("{}/{org}/{repo}/commits", configuration.base_path, org=crate::apis::urlencode(p_path_org), repo=crate::apis::urlencode(p_path_repo));
164    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
165
166    if let Some(ref user_agent) = configuration.user_agent {
167        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
168    }
169    if let Some(ref token) = configuration.bearer_access_token {
170        req_builder = req_builder.bearer_auth(token.to_owned());
171    };
172    req_builder = req_builder.json(&p_body_post_by_org_by_repo_commits_request);
173
174    let req = req_builder.build()?;
175    let resp = configuration.client.execute(req).await?;
176
177    let status = resp.status();
178    let content_type = resp
179        .headers()
180        .get("content-type")
181        .and_then(|v| v.to_str().ok())
182        .unwrap_or("application/octet-stream");
183    let content_type = super::ContentType::from(content_type);
184
185    if !status.is_client_error() && !status.is_server_error() {
186        let content = resp.text().await?;
187        match content_type {
188            ContentType::Json => serde_path_to_error::deserialize(&mut serde_json::Deserializer::from_str(&content)).map_err(Error::from),
189            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::PostByOrgByRepoCommits201Response`"))),
190            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::PostByOrgByRepoCommits201Response`")))),
191        }
192    } else {
193        let content = resp.text().await?;
194        let entity: Option<PostByOrgByRepoCommitsError> = serde_json::from_str(&content).ok();
195        Err(Error::ResponseError(ResponseContent { status, content, entity }))
196    }
197}
198