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
47/// List commits for a repository from a specific ref
48pub 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>> {
49    // add a prefix to parameters to efficiently prevent name collisions
50    let p_path_org = org;
51    let p_path_repo = repo;
52    let p_query_cursor = cursor;
53    let p_query_limit = limit;
54    let p_query_ref = r#ref;
55
56    let uri_str = format!("{}/{org}/{repo}/commits", configuration.base_path, org=crate::apis::urlencode(p_path_org), repo=crate::apis::urlencode(p_path_repo));
57    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
58
59    if let Some(ref param_value) = p_query_cursor {
60        req_builder = req_builder.query(&[("cursor", &param_value.to_string())]);
61    }
62    if let Some(ref param_value) = p_query_limit {
63        req_builder = req_builder.query(&[("limit", &param_value.to_string())]);
64    }
65    if let Some(ref param_value) = p_query_ref {
66        req_builder = req_builder.query(&[("ref", &param_value.to_string())]);
67    }
68    if let Some(ref user_agent) = configuration.user_agent {
69        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
70    }
71    if let Some(ref token) = configuration.bearer_access_token {
72        req_builder = req_builder.bearer_auth(token.to_owned());
73    };
74
75    let req = req_builder.build()?;
76    let resp = configuration.client.execute(req).await?;
77
78    let status = resp.status();
79    let content_type = resp
80        .headers()
81        .get("content-type")
82        .and_then(|v| v.to_str().ok())
83        .unwrap_or("application/octet-stream");
84    let content_type = super::ContentType::from(content_type);
85
86    if !status.is_client_error() && !status.is_server_error() {
87        let content = resp.text().await?;
88        match content_type {
89            ContentType::Json => serde_path_to_error::deserialize(&mut serde_json::Deserializer::from_str(&content)).map_err(Error::from),
90            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetByOrgByRepoCommits200Response`"))),
91            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`")))),
92        }
93    } else {
94        let content = resp.text().await?;
95        let entity: Option<GetByOrgByRepoCommitsError> = serde_json::from_str(&content).ok();
96        Err(Error::ResponseError(ResponseContent { status, content, entity }))
97    }
98}
99
100/// Retrieve a specific commit by its SHA
101pub 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>> {
102    // add a prefix to parameters to efficiently prevent name collisions
103    let p_path_org = org;
104    let p_path_repo = repo;
105    let p_path_sha = sha;
106
107    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()));
108    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
109
110    if let Some(ref user_agent) = configuration.user_agent {
111        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
112    }
113    if let Some(ref token) = configuration.bearer_access_token {
114        req_builder = req_builder.bearer_auth(token.to_owned());
115    };
116
117    let req = req_builder.build()?;
118    let resp = configuration.client.execute(req).await?;
119
120    let status = resp.status();
121    let content_type = resp
122        .headers()
123        .get("content-type")
124        .and_then(|v| v.to_str().ok())
125        .unwrap_or("application/octet-stream");
126    let content_type = super::ContentType::from(content_type);
127
128    if !status.is_client_error() && !status.is_server_error() {
129        let content = resp.text().await?;
130        match content_type {
131            ContentType::Json => serde_path_to_error::deserialize(&mut serde_json::Deserializer::from_str(&content)).map_err(Error::from),
132            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetByOrgByRepoCommitsBySha200Response`"))),
133            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`")))),
134        }
135    } else {
136        let content = resp.text().await?;
137        let entity: Option<GetByOrgByRepoCommitsByShaError> = serde_json::from_str(&content).ok();
138        Err(Error::ResponseError(ResponseContent { status, content, entity }))
139    }
140}
141