1use reqwest;
12use serde::{de::Error as _, Deserialize, Serialize};
13
14use super::{configuration, ContentType, Error};
15use crate::{apis::ResponseContent, models};
16
17#[derive(Debug, Clone, Serialize, Deserialize)]
19#[serde(untagged)]
20pub enum GetChecksError {
21 Status400(models::JsonErrorResponseNull),
22 Status401(models::JsonErrorResponseNull),
23 Status403(models::JsonErrorResponseNull),
24 Status404(models::JsonErrorResponseNull),
25 Status409(models::JsonErrorResponseNull),
26 Status429(models::JsonErrorResponseNull),
27 Status500(models::JsonErrorResponseNull),
28 UnknownValue(serde_json::Value),
29}
30
31#[derive(Debug, Clone, Serialize, Deserialize)]
33#[serde(untagged)]
34pub enum GetRecentError {
35 Status400(models::JsonErrorResponseNull),
36 Status401(models::JsonErrorResponseNull),
37 Status403(models::JsonErrorResponseNull),
38 Status404(models::JsonErrorResponseNull),
39 Status409(models::JsonErrorResponseNull),
40 Status429(models::JsonErrorResponseNull),
41 Status500(models::JsonErrorResponseNull),
42 UnknownValue(serde_json::Value),
43}
44
45#[derive(Debug, Clone, Serialize, Deserialize)]
47#[serde(untagged)]
48pub enum PutCheckReportError {
49 Status400(models::JsonErrorResponseNull),
50 Status401(models::JsonErrorResponseNull),
51 Status403(models::JsonErrorResponseNull),
52 Status404(models::JsonErrorResponseNull),
53 Status409(models::JsonErrorResponseNull),
54 Status429(models::JsonErrorResponseNull),
55 Status500(models::JsonErrorResponseNull),
56 UnknownValue(serde_json::Value),
57}
58
59pub async fn get_checks(
60 configuration: &configuration::Configuration,
61 repo_ref: &str,
62 commit_sha: &str,
63 page: Option<i64>,
64 size: Option<i64>,
65 query: Option<&str>,
66) -> Result<Vec<models::CheckModel>, Error<GetChecksError>> {
67 let p_path_repo_ref = repo_ref;
69 let p_path_commit_sha = commit_sha;
70 let p_query_page = page;
71 let p_query_size = size;
72 let p_query_query = query;
73
74 let uri_str = format!(
75 "{}/repos/{repo_ref}/+/checks/commits/{commit_sha}",
76 configuration.base_path,
77 repo_ref = crate::apis::urlencode(p_path_repo_ref),
78 commit_sha = crate::apis::urlencode(p_path_commit_sha)
79 );
80 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
81
82 if let Some(ref param_value) = p_query_page {
83 req_builder = req_builder.query(&[("page", ¶m_value.to_string())]);
84 }
85 if let Some(ref param_value) = p_query_size {
86 req_builder = req_builder.query(&[("size", ¶m_value.to_string())]);
87 }
88 if let Some(ref param_value) = p_query_query {
89 req_builder = req_builder.query(&[("query", ¶m_value.to_string())]);
90 }
91 if let Some(ref apikey) = configuration.api_key {
92 let key = apikey.key.clone();
93 let value = match apikey.prefix {
94 Some(ref prefix) => format!("{} {}", prefix, key),
95 None => key,
96 };
97 req_builder = req_builder.query(&[("access_token", value)]);
98 }
99 if let Some(ref user_agent) = configuration.user_agent {
100 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
101 }
102 if let Some(ref auth_conf) = configuration.basic_auth {
103 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
104 };
105 if let Some(ref token) = configuration.bearer_access_token {
106 req_builder = req_builder.bearer_auth(token.to_owned());
107 };
108
109 let req = req_builder.build()?;
110 let resp = configuration.client.execute(req).await?;
111
112 let status = resp.status();
113 let content_type = resp
114 .headers()
115 .get("content-type")
116 .and_then(|v| v.to_str().ok())
117 .unwrap_or("application/octet-stream");
118 let content_type = super::ContentType::from(content_type);
119
120 if !status.is_client_error() && !status.is_server_error() {
121 let content = resp.text().await?;
122 match content_type {
123 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
124 ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec<models::CheckModel>`"))),
125 ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `Vec<models::CheckModel>`")))),
126 }
127 } else {
128 let content = resp.text().await?;
129 let entity: Option<GetChecksError> = serde_json::from_str(&content).ok();
130 Err(Error::ResponseError(ResponseContent {
131 status,
132 content,
133 entity,
134 }))
135 }
136}
137
138pub async fn get_recent(
139 configuration: &configuration::Configuration,
140 repo_ref: &str,
141 query: Option<&str>,
142 since: Option<i64>,
143) -> Result<Vec<String>, Error<GetRecentError>> {
144 let p_path_repo_ref = repo_ref;
146 let p_query_query = query;
147 let p_query_since = since;
148
149 let uri_str = format!(
150 "{}/repos/{repo_ref}/+/checks/recent",
151 configuration.base_path,
152 repo_ref = crate::apis::urlencode(p_path_repo_ref)
153 );
154 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
155
156 if let Some(ref param_value) = p_query_query {
157 req_builder = req_builder.query(&[("query", ¶m_value.to_string())]);
158 }
159 if let Some(ref param_value) = p_query_since {
160 req_builder = req_builder.query(&[("since", ¶m_value.to_string())]);
161 }
162 if let Some(ref apikey) = configuration.api_key {
163 let key = apikey.key.clone();
164 let value = match apikey.prefix {
165 Some(ref prefix) => format!("{} {}", prefix, key),
166 None => key,
167 };
168 req_builder = req_builder.query(&[("access_token", value)]);
169 }
170 if let Some(ref user_agent) = configuration.user_agent {
171 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
172 }
173 if let Some(ref auth_conf) = configuration.basic_auth {
174 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
175 };
176 if let Some(ref token) = configuration.bearer_access_token {
177 req_builder = req_builder.bearer_auth(token.to_owned());
178 };
179
180 let req = req_builder.build()?;
181 let resp = configuration.client.execute(req).await?;
182
183 let status = resp.status();
184 let content_type = resp
185 .headers()
186 .get("content-type")
187 .and_then(|v| v.to_str().ok())
188 .unwrap_or("application/octet-stream");
189 let content_type = super::ContentType::from(content_type);
190
191 if !status.is_client_error() && !status.is_server_error() {
192 let content = resp.text().await?;
193 match content_type {
194 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
195 ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec<String>`"))),
196 ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `Vec<String>`")))),
197 }
198 } else {
199 let content = resp.text().await?;
200 let entity: Option<GetRecentError> = serde_json::from_str(&content).ok();
201 Err(Error::ResponseError(ResponseContent {
202 status,
203 content,
204 entity,
205 }))
206 }
207}
208
209pub async fn put_check_report(
210 configuration: &configuration::Configuration,
211 repo_ref: &str,
212 commit_sha: &str,
213 check_report_input: models::CheckReportInput,
214) -> Result<models::CheckModel, Error<PutCheckReportError>> {
215 let p_path_repo_ref = repo_ref;
217 let p_path_commit_sha = commit_sha;
218 let p_body_check_report_input = check_report_input;
219
220 let uri_str = format!(
221 "{}/repos/{repo_ref}/+/checks/commits/{commit_sha}",
222 configuration.base_path,
223 repo_ref = crate::apis::urlencode(p_path_repo_ref),
224 commit_sha = crate::apis::urlencode(p_path_commit_sha)
225 );
226 let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
227
228 if let Some(ref apikey) = configuration.api_key {
229 let key = apikey.key.clone();
230 let value = match apikey.prefix {
231 Some(ref prefix) => format!("{} {}", prefix, key),
232 None => key,
233 };
234 req_builder = req_builder.query(&[("access_token", value)]);
235 }
236 if let Some(ref user_agent) = configuration.user_agent {
237 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
238 }
239 if let Some(ref auth_conf) = configuration.basic_auth {
240 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
241 };
242 if let Some(ref token) = configuration.bearer_access_token {
243 req_builder = req_builder.bearer_auth(token.to_owned());
244 };
245 req_builder = req_builder.json(&p_body_check_report_input);
246
247 let req = req_builder.build()?;
248 let resp = configuration.client.execute(req).await?;
249
250 let status = resp.status();
251 let content_type = resp
252 .headers()
253 .get("content-type")
254 .and_then(|v| v.to_str().ok())
255 .unwrap_or("application/octet-stream");
256 let content_type = super::ContentType::from(content_type);
257
258 if !status.is_client_error() && !status.is_server_error() {
259 let content = resp.text().await?;
260 match content_type {
261 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
262 ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::CheckModel`"))),
263 ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::CheckModel`")))),
264 }
265 } else {
266 let content = resp.text().await?;
267 let entity: Option<PutCheckReportError> = serde_json::from_str(&content).ok();
268 Err(Error::ResponseError(ResponseContent {
269 status,
270 content,
271 entity,
272 }))
273 }
274}