1use reqwest;
13use serde::{Deserialize, Serialize};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration};
16
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum AssignGhesInstallationError {
22 UnknownValue(serde_json::Value),
23}
24
25#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum DeleteFromWorkspaceError {
29 UnknownValue(serde_json::Value),
30}
31
32#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum DiscoverGhesInstallationsError {
36 UnknownValue(serde_json::Value),
37}
38
39#[derive(Debug, Clone, Serialize, Deserialize)]
41#[serde(untagged)]
42pub enum ExportInstallationError {
43 UnknownValue(serde_json::Value),
44}
45
46#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum GetGhesConfigError {
50 UnknownValue(serde_json::Value),
51}
52
53#[derive(Debug, Clone, Serialize, Deserialize)]
55#[serde(untagged)]
56pub enum GetGlobalConnectedRepositoriesError {
57 UnknownValue(serde_json::Value),
58}
59
60#[derive(Debug, Clone, Serialize, Deserialize)]
62#[serde(untagged)]
63pub enum GhesInstallationCallbackError {
64 UnknownValue(serde_json::Value),
65}
66
67#[derive(Debug, Clone, Serialize, Deserialize)]
69#[serde(untagged)]
70pub enum ImportInstallationError {
71 UnknownValue(serde_json::Value),
72}
73
74#[derive(Debug, Clone, Serialize, Deserialize)]
76#[serde(untagged)]
77pub enum InstallFromWorkspaceError {
78 UnknownValue(serde_json::Value),
79}
80
81#[derive(Debug, Clone, Serialize, Deserialize)]
83#[serde(untagged)]
84pub enum UnassignGhesInstallationError {
85 UnknownValue(serde_json::Value),
86}
87
88
89pub async fn assign_ghes_installation(configuration: &configuration::Configuration, assign_ghes_installation_request: models::AssignGhesInstallationRequest) -> Result<(), Error<AssignGhesInstallationError>> {
91 let local_var_configuration = configuration;
92
93 let local_var_client = &local_var_configuration.client;
94
95 let local_var_uri_str = format!("{}/github_app/ghes/assign", local_var_configuration.base_path);
96 let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
97
98 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
99 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
100 }
101 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
102 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
103 };
104 local_var_req_builder = local_var_req_builder.json(&assign_ghes_installation_request);
105
106 let local_var_req = local_var_req_builder.build()?;
107 let local_var_resp = local_var_client.execute(local_var_req).await?;
108
109 let local_var_status = local_var_resp.status();
110 let local_var_content = local_var_resp.text().await?;
111
112 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
113 Ok(())
114 } else {
115 let local_var_entity: Option<AssignGhesInstallationError> = crate::from_str_patched(&local_var_content).ok();
116 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
117 Err(Error::ResponseError(local_var_error))
118 }
119}
120
121pub async fn delete_from_workspace(configuration: &configuration::Configuration, workspace: &str, installation_id: i64) -> Result<(), Error<DeleteFromWorkspaceError>> {
123 let local_var_configuration = configuration;
124
125 let local_var_client = &local_var_configuration.client;
126
127 let local_var_uri_str = format!("{}/w/{workspace}/github_app/installation/{installation_id}", local_var_configuration.base_path, workspace=crate::apis::urlencode(workspace), installation_id=installation_id);
128 let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
129
130 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
131 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
132 }
133 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
134 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
135 };
136
137 let local_var_req = local_var_req_builder.build()?;
138 let local_var_resp = local_var_client.execute(local_var_req).await?;
139
140 let local_var_status = local_var_resp.status();
141 let local_var_content = local_var_resp.text().await?;
142
143 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
144 Ok(())
145 } else {
146 let local_var_entity: Option<DeleteFromWorkspaceError> = crate::from_str_patched(&local_var_content).ok();
147 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
148 Err(Error::ResponseError(local_var_error))
149 }
150}
151
152pub async fn discover_ghes_installations(configuration: &configuration::Configuration, ) -> Result<Vec<models::DiscoverGhesInstallations200ResponseInner>, Error<DiscoverGhesInstallationsError>> {
154 let local_var_configuration = configuration;
155
156 let local_var_client = &local_var_configuration.client;
157
158 let local_var_uri_str = format!("{}/github_app/ghes/discover", local_var_configuration.base_path);
159 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
160
161 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
162 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
163 }
164 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
165 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
166 };
167
168 let local_var_req = local_var_req_builder.build()?;
169 let local_var_resp = local_var_client.execute(local_var_req).await?;
170
171 let local_var_status = local_var_resp.status();
172 let local_var_content = local_var_resp.text().await?;
173
174 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
175 crate::from_str_patched(&local_var_content).map_err(Error::from)
176 } else {
177 let local_var_entity: Option<DiscoverGhesInstallationsError> = crate::from_str_patched(&local_var_content).ok();
178 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
179 Err(Error::ResponseError(local_var_error))
180 }
181}
182
183pub async fn export_installation(configuration: &configuration::Configuration, workspace: &str, installation_id: i32) -> Result<models::ExportInstallation200Response, Error<ExportInstallationError>> {
185 let local_var_configuration = configuration;
186
187 let local_var_client = &local_var_configuration.client;
188
189 let local_var_uri_str = format!("{}/w/{workspace}/github_app/export/{installationId}", local_var_configuration.base_path, workspace=crate::apis::urlencode(workspace), installationId=installation_id);
190 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
191
192 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
193 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
194 }
195 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
196 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
197 };
198
199 let local_var_req = local_var_req_builder.build()?;
200 let local_var_resp = local_var_client.execute(local_var_req).await?;
201
202 let local_var_status = local_var_resp.status();
203 let local_var_content = local_var_resp.text().await?;
204
205 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
206 crate::from_str_patched(&local_var_content).map_err(Error::from)
207 } else {
208 let local_var_entity: Option<ExportInstallationError> = crate::from_str_patched(&local_var_content).ok();
209 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
210 Err(Error::ResponseError(local_var_error))
211 }
212}
213
214pub async fn get_ghes_config(configuration: &configuration::Configuration, ) -> Result<models::GetGhesConfig200Response, Error<GetGhesConfigError>> {
216 let local_var_configuration = configuration;
217
218 let local_var_client = &local_var_configuration.client;
219
220 let local_var_uri_str = format!("{}/github_app/ghes_config", local_var_configuration.base_path);
221 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
222
223 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
224 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
225 }
226 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
227 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
228 };
229
230 let local_var_req = local_var_req_builder.build()?;
231 let local_var_resp = local_var_client.execute(local_var_req).await?;
232
233 let local_var_status = local_var_resp.status();
234 let local_var_content = local_var_resp.text().await?;
235
236 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
237 crate::from_str_patched(&local_var_content).map_err(Error::from)
238 } else {
239 let local_var_entity: Option<GetGhesConfigError> = crate::from_str_patched(&local_var_content).ok();
240 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
241 Err(Error::ResponseError(local_var_error))
242 }
243}
244
245pub async fn get_global_connected_repositories(configuration: &configuration::Configuration, page: Option<i32>) -> Result<Vec<models::GithubInstallationsInner>, Error<GetGlobalConnectedRepositoriesError>> {
246 let local_var_configuration = configuration;
247
248 let local_var_client = &local_var_configuration.client;
249
250 let local_var_uri_str = format!("{}/github_app/connected_repositories", local_var_configuration.base_path);
251 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
252
253 if let Some(ref local_var_str) = page {
254 local_var_req_builder = local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
255 }
256 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
257 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
258 }
259 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
260 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
261 };
262
263 let local_var_req = local_var_req_builder.build()?;
264 let local_var_resp = local_var_client.execute(local_var_req).await?;
265
266 let local_var_status = local_var_resp.status();
267 let local_var_content = local_var_resp.text().await?;
268
269 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
270 crate::from_str_patched(&local_var_content).map_err(Error::from)
271 } else {
272 let local_var_entity: Option<GetGlobalConnectedRepositoriesError> = crate::from_str_patched(&local_var_content).ok();
273 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
274 Err(Error::ResponseError(local_var_error))
275 }
276}
277
278pub async fn ghes_installation_callback(configuration: &configuration::Configuration, workspace: &str, ghes_installation_callback_request: models::GhesInstallationCallbackRequest) -> Result<(), Error<GhesInstallationCallbackError>> {
280 let local_var_configuration = configuration;
281
282 let local_var_client = &local_var_configuration.client;
283
284 let local_var_uri_str = format!("{}/w/{workspace}/github_app/ghes_installation_callback", local_var_configuration.base_path, workspace=crate::apis::urlencode(workspace));
285 let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
286
287 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
288 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
289 }
290 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
291 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
292 };
293 local_var_req_builder = local_var_req_builder.json(&ghes_installation_callback_request);
294
295 let local_var_req = local_var_req_builder.build()?;
296 let local_var_resp = local_var_client.execute(local_var_req).await?;
297
298 let local_var_status = local_var_resp.status();
299 let local_var_content = local_var_resp.text().await?;
300
301 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
302 Ok(())
303 } else {
304 let local_var_entity: Option<GhesInstallationCallbackError> = crate::from_str_patched(&local_var_content).ok();
305 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
306 Err(Error::ResponseError(local_var_error))
307 }
308}
309
310pub async fn import_installation(configuration: &configuration::Configuration, workspace: &str, import_installation_request: models::ImportInstallationRequest) -> Result<(), Error<ImportInstallationError>> {
312 let local_var_configuration = configuration;
313
314 let local_var_client = &local_var_configuration.client;
315
316 let local_var_uri_str = format!("{}/w/{workspace}/github_app/import", local_var_configuration.base_path, workspace=crate::apis::urlencode(workspace));
317 let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
318
319 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
320 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
321 }
322 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
323 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
324 };
325 local_var_req_builder = local_var_req_builder.json(&import_installation_request);
326
327 let local_var_req = local_var_req_builder.build()?;
328 let local_var_resp = local_var_client.execute(local_var_req).await?;
329
330 let local_var_status = local_var_resp.status();
331 let local_var_content = local_var_resp.text().await?;
332
333 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
334 Ok(())
335 } else {
336 let local_var_entity: Option<ImportInstallationError> = crate::from_str_patched(&local_var_content).ok();
337 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
338 Err(Error::ResponseError(local_var_error))
339 }
340}
341
342pub async fn install_from_workspace(configuration: &configuration::Configuration, workspace: &str, install_from_workspace_request: models::InstallFromWorkspaceRequest) -> Result<(), Error<InstallFromWorkspaceError>> {
343 let local_var_configuration = configuration;
344
345 let local_var_client = &local_var_configuration.client;
346
347 let local_var_uri_str = format!("{}/w/{workspace}/github_app/install_from_workspace", local_var_configuration.base_path, workspace=crate::apis::urlencode(workspace));
348 let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
349
350 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
351 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
352 }
353 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
354 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
355 };
356 local_var_req_builder = local_var_req_builder.json(&install_from_workspace_request);
357
358 let local_var_req = local_var_req_builder.build()?;
359 let local_var_resp = local_var_client.execute(local_var_req).await?;
360
361 let local_var_status = local_var_resp.status();
362 let local_var_content = local_var_resp.text().await?;
363
364 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
365 Ok(())
366 } else {
367 let local_var_entity: Option<InstallFromWorkspaceError> = crate::from_str_patched(&local_var_content).ok();
368 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
369 Err(Error::ResponseError(local_var_error))
370 }
371}
372
373pub async fn unassign_ghes_installation(configuration: &configuration::Configuration, workspace_id: &str, installation_id: i64) -> Result<(), Error<UnassignGhesInstallationError>> {
375 let local_var_configuration = configuration;
376
377 let local_var_client = &local_var_configuration.client;
378
379 let local_var_uri_str = format!("{}/github_app/ghes/assign/{workspace_id}/{installation_id}", local_var_configuration.base_path, workspace_id=crate::apis::urlencode(workspace_id), installation_id=installation_id);
380 let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
381
382 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
383 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
384 }
385 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
386 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
387 };
388
389 let local_var_req = local_var_req_builder.build()?;
390 let local_var_resp = local_var_client.execute(local_var_req).await?;
391
392 let local_var_status = local_var_resp.status();
393 let local_var_content = local_var_resp.text().await?;
394
395 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
396 Ok(())
397 } else {
398 let local_var_entity: Option<UnassignGhesInstallationError> = crate::from_str_patched(&local_var_content).ok();
399 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
400 Err(Error::ResponseError(local_var_error))
401 }
402}
403