gitbundle_sdk/apis/
webhooks_api.rs

1/*
2 * GitBundle API
3 *
4 * GitBundle API documentation.
5 *
6 * The version of the OpenAPI document: 3.0.0
7 *
8 * Generated by: https://openapi-generator.tech
9 */
10
11use reqwest;
12use serde::{de::Error as _, Deserialize, Serialize};
13
14use super::{configuration, ContentType, Error};
15use crate::{apis::ResponseContent, models};
16
17/// struct for typed errors of method [`delete_webhook`]
18#[derive(Debug, Clone, Serialize, Deserialize)]
19#[serde(untagged)]
20pub enum DeleteWebhookError {
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/// struct for typed errors of method [`get_execution`]
32#[derive(Debug, Clone, Serialize, Deserialize)]
33#[serde(untagged)]
34pub enum GetExecutionError {
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/// struct for typed errors of method [`get_executions`]
46#[derive(Debug, Clone, Serialize, Deserialize)]
47#[serde(untagged)]
48pub enum GetExecutionsError {
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
59/// struct for typed errors of method [`get_webhook`]
60#[derive(Debug, Clone, Serialize, Deserialize)]
61#[serde(untagged)]
62pub enum GetWebhookError {
63    Status400(models::JsonErrorResponseNull),
64    Status401(models::JsonErrorResponseNull),
65    Status403(models::JsonErrorResponseNull),
66    Status404(models::JsonErrorResponseNull),
67    Status409(models::JsonErrorResponseNull),
68    Status429(models::JsonErrorResponseNull),
69    Status500(models::JsonErrorResponseNull),
70    UnknownValue(serde_json::Value),
71}
72
73/// struct for typed errors of method [`get_webhooks`]
74#[derive(Debug, Clone, Serialize, Deserialize)]
75#[serde(untagged)]
76pub enum GetWebhooksError {
77    Status400(models::JsonErrorResponseNull),
78    Status401(models::JsonErrorResponseNull),
79    Status403(models::JsonErrorResponseNull),
80    Status404(models::JsonErrorResponseNull),
81    Status409(models::JsonErrorResponseNull),
82    Status429(models::JsonErrorResponseNull),
83    Status500(models::JsonErrorResponseNull),
84    UnknownValue(serde_json::Value),
85}
86
87/// struct for typed errors of method [`patch_webhook`]
88#[derive(Debug, Clone, Serialize, Deserialize)]
89#[serde(untagged)]
90pub enum PatchWebhookError {
91    Status400(models::JsonErrorResponseNull),
92    Status401(models::JsonErrorResponseNull),
93    Status403(models::JsonErrorResponseNull),
94    Status404(models::JsonErrorResponseNull),
95    Status409(models::JsonErrorResponseNull),
96    Status429(models::JsonErrorResponseNull),
97    Status500(models::JsonErrorResponseNull),
98    UnknownValue(serde_json::Value),
99}
100
101/// struct for typed errors of method [`post_retrigger`]
102#[derive(Debug, Clone, Serialize, Deserialize)]
103#[serde(untagged)]
104pub enum PostRetriggerError {
105    Status400(models::JsonErrorResponseNull),
106    Status401(models::JsonErrorResponseNull),
107    Status403(models::JsonErrorResponseNull),
108    Status404(models::JsonErrorResponseNull),
109    Status409(models::JsonErrorResponseNull),
110    Status429(models::JsonErrorResponseNull),
111    Status500(models::JsonErrorResponseNull),
112    UnknownValue(serde_json::Value),
113}
114
115/// struct for typed errors of method [`post_webhook`]
116#[derive(Debug, Clone, Serialize, Deserialize)]
117#[serde(untagged)]
118pub enum PostWebhookError {
119    Status400(models::JsonErrorResponseNull),
120    Status401(models::JsonErrorResponseNull),
121    Status403(models::JsonErrorResponseNull),
122    Status404(models::JsonErrorResponseNull),
123    Status409(models::JsonErrorResponseNull),
124    Status429(models::JsonErrorResponseNull),
125    Status500(models::JsonErrorResponseNull),
126    UnknownValue(serde_json::Value),
127}
128
129pub async fn delete_webhook(
130    configuration: &configuration::Configuration,
131    repo_ref: &str,
132    webhook_identifier: &str,
133) -> Result<(), Error<DeleteWebhookError>> {
134    // add a prefix to parameters to efficiently prevent name collisions
135    let p_path_repo_ref = repo_ref;
136    let p_path_webhook_identifier = webhook_identifier;
137
138    let uri_str = format!(
139        "{}/repos/{repo_ref}/+/webhooks/{webhook_identifier}",
140        configuration.base_path,
141        repo_ref = crate::apis::urlencode(p_path_repo_ref),
142        webhook_identifier = crate::apis::urlencode(p_path_webhook_identifier)
143    );
144    let mut req_builder = configuration
145        .client
146        .request(reqwest::Method::DELETE, &uri_str);
147
148    if let Some(ref apikey) = configuration.api_key {
149        let key = apikey.key.clone();
150        let value = match apikey.prefix {
151            Some(ref prefix) => format!("{} {}", prefix, key),
152            None => key,
153        };
154        req_builder = req_builder.query(&[("access_token", value)]);
155    }
156    if let Some(ref user_agent) = configuration.user_agent {
157        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
158    }
159    if let Some(ref auth_conf) = configuration.basic_auth {
160        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
161    };
162    if let Some(ref token) = configuration.bearer_access_token {
163        req_builder = req_builder.bearer_auth(token.to_owned());
164    };
165
166    let req = req_builder.build()?;
167    let resp = configuration.client.execute(req).await?;
168
169    let status = resp.status();
170
171    if !status.is_client_error() && !status.is_server_error() {
172        Ok(())
173    } else {
174        let content = resp.text().await?;
175        let entity: Option<DeleteWebhookError> = serde_json::from_str(&content).ok();
176        Err(Error::ResponseError(ResponseContent {
177            status,
178            content,
179            entity,
180        }))
181    }
182}
183
184pub async fn get_execution(
185    configuration: &configuration::Configuration,
186    repo_ref: &str,
187    webhook_identifier: &str,
188    webhook_execution_id: i64,
189) -> Result<models::WebhookExecutionModel, Error<GetExecutionError>> {
190    // add a prefix to parameters to efficiently prevent name collisions
191    let p_path_repo_ref = repo_ref;
192    let p_path_webhook_identifier = webhook_identifier;
193    let p_path_webhook_execution_id = webhook_execution_id;
194
195    let uri_str = format!(
196        "{}/repos/{repo_ref}/+/webhooks/{webhook_identifier}/executions/{webhook_execution_id}",
197        configuration.base_path,
198        repo_ref = crate::apis::urlencode(p_path_repo_ref),
199        webhook_identifier = crate::apis::urlencode(p_path_webhook_identifier),
200        webhook_execution_id = p_path_webhook_execution_id
201    );
202    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
203
204    if let Some(ref apikey) = configuration.api_key {
205        let key = apikey.key.clone();
206        let value = match apikey.prefix {
207            Some(ref prefix) => format!("{} {}", prefix, key),
208            None => key,
209        };
210        req_builder = req_builder.query(&[("access_token", value)]);
211    }
212    if let Some(ref user_agent) = configuration.user_agent {
213        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
214    }
215    if let Some(ref auth_conf) = configuration.basic_auth {
216        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
217    };
218    if let Some(ref token) = configuration.bearer_access_token {
219        req_builder = req_builder.bearer_auth(token.to_owned());
220    };
221
222    let req = req_builder.build()?;
223    let resp = configuration.client.execute(req).await?;
224
225    let status = resp.status();
226    let content_type = resp
227        .headers()
228        .get("content-type")
229        .and_then(|v| v.to_str().ok())
230        .unwrap_or("application/octet-stream");
231    let content_type = super::ContentType::from(content_type);
232
233    if !status.is_client_error() && !status.is_server_error() {
234        let content = resp.text().await?;
235        match content_type {
236            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
237            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::WebhookExecutionModel`"))),
238            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::WebhookExecutionModel`")))),
239        }
240    } else {
241        let content = resp.text().await?;
242        let entity: Option<GetExecutionError> = serde_json::from_str(&content).ok();
243        Err(Error::ResponseError(ResponseContent {
244            status,
245            content,
246            entity,
247        }))
248    }
249}
250
251pub async fn get_executions(
252    configuration: &configuration::Configuration,
253    repo_ref: &str,
254    webhook_identifier: &str,
255) -> Result<Vec<models::WebhookExecutionModel>, Error<GetExecutionsError>> {
256    // add a prefix to parameters to efficiently prevent name collisions
257    let p_path_repo_ref = repo_ref;
258    let p_path_webhook_identifier = webhook_identifier;
259
260    let uri_str = format!(
261        "{}/repos/{repo_ref}/+/webhooks/{webhook_identifier}/executions",
262        configuration.base_path,
263        repo_ref = crate::apis::urlencode(p_path_repo_ref),
264        webhook_identifier = crate::apis::urlencode(p_path_webhook_identifier)
265    );
266    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
267
268    if let Some(ref apikey) = configuration.api_key {
269        let key = apikey.key.clone();
270        let value = match apikey.prefix {
271            Some(ref prefix) => format!("{} {}", prefix, key),
272            None => key,
273        };
274        req_builder = req_builder.query(&[("access_token", value)]);
275    }
276    if let Some(ref user_agent) = configuration.user_agent {
277        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
278    }
279    if let Some(ref auth_conf) = configuration.basic_auth {
280        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
281    };
282    if let Some(ref token) = configuration.bearer_access_token {
283        req_builder = req_builder.bearer_auth(token.to_owned());
284    };
285
286    let req = req_builder.build()?;
287    let resp = configuration.client.execute(req).await?;
288
289    let status = resp.status();
290    let content_type = resp
291        .headers()
292        .get("content-type")
293        .and_then(|v| v.to_str().ok())
294        .unwrap_or("application/octet-stream");
295    let content_type = super::ContentType::from(content_type);
296
297    if !status.is_client_error() && !status.is_server_error() {
298        let content = resp.text().await?;
299        match content_type {
300            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
301            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec&lt;models::WebhookExecutionModel&gt;`"))),
302            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `Vec&lt;models::WebhookExecutionModel&gt;`")))),
303        }
304    } else {
305        let content = resp.text().await?;
306        let entity: Option<GetExecutionsError> = serde_json::from_str(&content).ok();
307        Err(Error::ResponseError(ResponseContent {
308            status,
309            content,
310            entity,
311        }))
312    }
313}
314
315pub async fn get_webhook(
316    configuration: &configuration::Configuration,
317    repo_ref: &str,
318    webhook_identifier: &str,
319) -> Result<models::WebhookModel, Error<GetWebhookError>> {
320    // add a prefix to parameters to efficiently prevent name collisions
321    let p_path_repo_ref = repo_ref;
322    let p_path_webhook_identifier = webhook_identifier;
323
324    let uri_str = format!(
325        "{}/repos/{repo_ref}/+/webhooks/{webhook_identifier}",
326        configuration.base_path,
327        repo_ref = crate::apis::urlencode(p_path_repo_ref),
328        webhook_identifier = crate::apis::urlencode(p_path_webhook_identifier)
329    );
330    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
331
332    if let Some(ref apikey) = configuration.api_key {
333        let key = apikey.key.clone();
334        let value = match apikey.prefix {
335            Some(ref prefix) => format!("{} {}", prefix, key),
336            None => key,
337        };
338        req_builder = req_builder.query(&[("access_token", value)]);
339    }
340    if let Some(ref user_agent) = configuration.user_agent {
341        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
342    }
343    if let Some(ref auth_conf) = configuration.basic_auth {
344        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
345    };
346    if let Some(ref token) = configuration.bearer_access_token {
347        req_builder = req_builder.bearer_auth(token.to_owned());
348    };
349
350    let req = req_builder.build()?;
351    let resp = configuration.client.execute(req).await?;
352
353    let status = resp.status();
354    let content_type = resp
355        .headers()
356        .get("content-type")
357        .and_then(|v| v.to_str().ok())
358        .unwrap_or("application/octet-stream");
359    let content_type = super::ContentType::from(content_type);
360
361    if !status.is_client_error() && !status.is_server_error() {
362        let content = resp.text().await?;
363        match content_type {
364            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
365            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::WebhookModel`"))),
366            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::WebhookModel`")))),
367        }
368    } else {
369        let content = resp.text().await?;
370        let entity: Option<GetWebhookError> = serde_json::from_str(&content).ok();
371        Err(Error::ResponseError(ResponseContent {
372            status,
373            content,
374            entity,
375        }))
376    }
377}
378
379pub async fn get_webhooks(
380    configuration: &configuration::Configuration,
381    repo_ref: &str,
382    page: Option<i64>,
383    size: Option<i64>,
384    query: Option<&str>,
385    sort: Option<models::WebhookSort>,
386    order: Option<models::OrderOption>,
387) -> Result<Vec<models::WebhookModel>, Error<GetWebhooksError>> {
388    // add a prefix to parameters to efficiently prevent name collisions
389    let p_path_repo_ref = repo_ref;
390    let p_query_page = page;
391    let p_query_size = size;
392    let p_query_query = query;
393    let p_query_sort = sort;
394    let p_query_order = order;
395
396    let uri_str = format!(
397        "{}/repos/{repo_ref}/+/webhooks",
398        configuration.base_path,
399        repo_ref = crate::apis::urlencode(p_path_repo_ref)
400    );
401    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
402
403    if let Some(ref param_value) = p_query_page {
404        req_builder = req_builder.query(&[("page", &param_value.to_string())]);
405    }
406    if let Some(ref param_value) = p_query_size {
407        req_builder = req_builder.query(&[("size", &param_value.to_string())]);
408    }
409    if let Some(ref param_value) = p_query_query {
410        req_builder = req_builder.query(&[("query", &param_value.to_string())]);
411    }
412    if let Some(ref param_value) = p_query_sort {
413        req_builder = req_builder.query(&[("sort", &param_value.to_string())]);
414    }
415    if let Some(ref param_value) = p_query_order {
416        req_builder = req_builder.query(&[("order", &param_value.to_string())]);
417    }
418    if let Some(ref apikey) = configuration.api_key {
419        let key = apikey.key.clone();
420        let value = match apikey.prefix {
421            Some(ref prefix) => format!("{} {}", prefix, key),
422            None => key,
423        };
424        req_builder = req_builder.query(&[("access_token", value)]);
425    }
426    if let Some(ref user_agent) = configuration.user_agent {
427        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
428    }
429    if let Some(ref auth_conf) = configuration.basic_auth {
430        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
431    };
432    if let Some(ref token) = configuration.bearer_access_token {
433        req_builder = req_builder.bearer_auth(token.to_owned());
434    };
435
436    let req = req_builder.build()?;
437    let resp = configuration.client.execute(req).await?;
438
439    let status = resp.status();
440    let content_type = resp
441        .headers()
442        .get("content-type")
443        .and_then(|v| v.to_str().ok())
444        .unwrap_or("application/octet-stream");
445    let content_type = super::ContentType::from(content_type);
446
447    if !status.is_client_error() && !status.is_server_error() {
448        let content = resp.text().await?;
449        match content_type {
450            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
451            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec&lt;models::WebhookModel&gt;`"))),
452            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `Vec&lt;models::WebhookModel&gt;`")))),
453        }
454    } else {
455        let content = resp.text().await?;
456        let entity: Option<GetWebhooksError> = serde_json::from_str(&content).ok();
457        Err(Error::ResponseError(ResponseContent {
458            status,
459            content,
460            entity,
461        }))
462    }
463}
464
465pub async fn patch_webhook(
466    configuration: &configuration::Configuration,
467    repo_ref: &str,
468    webhook_identifier: &str,
469    webhook_patch_input: models::WebhookPatchInput,
470) -> Result<models::WebhookModel, Error<PatchWebhookError>> {
471    // add a prefix to parameters to efficiently prevent name collisions
472    let p_path_repo_ref = repo_ref;
473    let p_path_webhook_identifier = webhook_identifier;
474    let p_body_webhook_patch_input = webhook_patch_input;
475
476    let uri_str = format!(
477        "{}/repos/{repo_ref}/+/webhooks/{webhook_identifier}",
478        configuration.base_path,
479        repo_ref = crate::apis::urlencode(p_path_repo_ref),
480        webhook_identifier = crate::apis::urlencode(p_path_webhook_identifier)
481    );
482    let mut req_builder = configuration
483        .client
484        .request(reqwest::Method::PATCH, &uri_str);
485
486    if let Some(ref apikey) = configuration.api_key {
487        let key = apikey.key.clone();
488        let value = match apikey.prefix {
489            Some(ref prefix) => format!("{} {}", prefix, key),
490            None => key,
491        };
492        req_builder = req_builder.query(&[("access_token", value)]);
493    }
494    if let Some(ref user_agent) = configuration.user_agent {
495        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
496    }
497    if let Some(ref auth_conf) = configuration.basic_auth {
498        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
499    };
500    if let Some(ref token) = configuration.bearer_access_token {
501        req_builder = req_builder.bearer_auth(token.to_owned());
502    };
503    req_builder = req_builder.json(&p_body_webhook_patch_input);
504
505    let req = req_builder.build()?;
506    let resp = configuration.client.execute(req).await?;
507
508    let status = resp.status();
509    let content_type = resp
510        .headers()
511        .get("content-type")
512        .and_then(|v| v.to_str().ok())
513        .unwrap_or("application/octet-stream");
514    let content_type = super::ContentType::from(content_type);
515
516    if !status.is_client_error() && !status.is_server_error() {
517        let content = resp.text().await?;
518        match content_type {
519            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
520            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::WebhookModel`"))),
521            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::WebhookModel`")))),
522        }
523    } else {
524        let content = resp.text().await?;
525        let entity: Option<PatchWebhookError> = serde_json::from_str(&content).ok();
526        Err(Error::ResponseError(ResponseContent {
527            status,
528            content,
529            entity,
530        }))
531    }
532}
533
534pub async fn post_retrigger(
535    configuration: &configuration::Configuration,
536    repo_ref: &str,
537    webhook_identifier: &str,
538    webhook_execution_id: i64,
539) -> Result<models::WebhookExecutionModel, Error<PostRetriggerError>> {
540    // add a prefix to parameters to efficiently prevent name collisions
541    let p_path_repo_ref = repo_ref;
542    let p_path_webhook_identifier = webhook_identifier;
543    let p_path_webhook_execution_id = webhook_execution_id;
544
545    let uri_str = format!("{}/repos/{repo_ref}/+/webhooks/{webhook_identifier}/executions/{webhook_execution_id}/retrigger", configuration.base_path, repo_ref=crate::apis::urlencode(p_path_repo_ref), webhook_identifier=crate::apis::urlencode(p_path_webhook_identifier), webhook_execution_id=p_path_webhook_execution_id);
546    let mut req_builder = configuration
547        .client
548        .request(reqwest::Method::POST, &uri_str);
549
550    if let Some(ref apikey) = configuration.api_key {
551        let key = apikey.key.clone();
552        let value = match apikey.prefix {
553            Some(ref prefix) => format!("{} {}", prefix, key),
554            None => key,
555        };
556        req_builder = req_builder.query(&[("access_token", value)]);
557    }
558    if let Some(ref user_agent) = configuration.user_agent {
559        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
560    }
561    if let Some(ref auth_conf) = configuration.basic_auth {
562        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
563    };
564    if let Some(ref token) = configuration.bearer_access_token {
565        req_builder = req_builder.bearer_auth(token.to_owned());
566    };
567
568    let req = req_builder.build()?;
569    let resp = configuration.client.execute(req).await?;
570
571    let status = resp.status();
572    let content_type = resp
573        .headers()
574        .get("content-type")
575        .and_then(|v| v.to_str().ok())
576        .unwrap_or("application/octet-stream");
577    let content_type = super::ContentType::from(content_type);
578
579    if !status.is_client_error() && !status.is_server_error() {
580        let content = resp.text().await?;
581        match content_type {
582            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
583            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::WebhookExecutionModel`"))),
584            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::WebhookExecutionModel`")))),
585        }
586    } else {
587        let content = resp.text().await?;
588        let entity: Option<PostRetriggerError> = serde_json::from_str(&content).ok();
589        Err(Error::ResponseError(ResponseContent {
590            status,
591            content,
592            entity,
593        }))
594    }
595}
596
597pub async fn post_webhook(
598    configuration: &configuration::Configuration,
599    repo_ref: &str,
600    webhook_create_input: models::WebhookCreateInput,
601) -> Result<models::WebhookModel, Error<PostWebhookError>> {
602    // add a prefix to parameters to efficiently prevent name collisions
603    let p_path_repo_ref = repo_ref;
604    let p_body_webhook_create_input = webhook_create_input;
605
606    let uri_str = format!(
607        "{}/repos/{repo_ref}/+/webhooks",
608        configuration.base_path,
609        repo_ref = crate::apis::urlencode(p_path_repo_ref)
610    );
611    let mut req_builder = configuration
612        .client
613        .request(reqwest::Method::POST, &uri_str);
614
615    if let Some(ref apikey) = configuration.api_key {
616        let key = apikey.key.clone();
617        let value = match apikey.prefix {
618            Some(ref prefix) => format!("{} {}", prefix, key),
619            None => key,
620        };
621        req_builder = req_builder.query(&[("access_token", value)]);
622    }
623    if let Some(ref user_agent) = configuration.user_agent {
624        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
625    }
626    if let Some(ref auth_conf) = configuration.basic_auth {
627        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
628    };
629    if let Some(ref token) = configuration.bearer_access_token {
630        req_builder = req_builder.bearer_auth(token.to_owned());
631    };
632    req_builder = req_builder.json(&p_body_webhook_create_input);
633
634    let req = req_builder.build()?;
635    let resp = configuration.client.execute(req).await?;
636
637    let status = resp.status();
638    let content_type = resp
639        .headers()
640        .get("content-type")
641        .and_then(|v| v.to_str().ok())
642        .unwrap_or("application/octet-stream");
643    let content_type = super::ContentType::from(content_type);
644
645    if !status.is_client_error() && !status.is_server_error() {
646        let content = resp.text().await?;
647        match content_type {
648            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
649            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::WebhookModel`"))),
650            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::WebhookModel`")))),
651        }
652    } else {
653        let content = resp.text().await?;
654        let entity: Option<PostWebhookError> = serde_json::from_str(&content).ok();
655        Err(Error::ResponseError(ResponseContent {
656            status,
657            content,
658            entity,
659        }))
660    }
661}