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 DeleteFromWorkspaceError {
22 UnknownValue(serde_json::Value),
23}
24
25#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum ExportInstallationError {
29 UnknownValue(serde_json::Value),
30}
31
32#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum GetGhesConfigError {
36 UnknownValue(serde_json::Value),
37}
38
39#[derive(Debug, Clone, Serialize, Deserialize)]
41#[serde(untagged)]
42pub enum GetGlobalConnectedRepositoriesError {
43 UnknownValue(serde_json::Value),
44}
45
46#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum GhesInstallationCallbackError {
50 UnknownValue(serde_json::Value),
51}
52
53#[derive(Debug, Clone, Serialize, Deserialize)]
55#[serde(untagged)]
56pub enum ImportInstallationError {
57 UnknownValue(serde_json::Value),
58}
59
60#[derive(Debug, Clone, Serialize, Deserialize)]
62#[serde(untagged)]
63pub enum InstallFromWorkspaceError {
64 UnknownValue(serde_json::Value),
65}
66
67
68pub async fn delete_from_workspace(configuration: &configuration::Configuration, workspace: &str, installation_id: i64) -> Result<(), Error<DeleteFromWorkspaceError>> {
70 let local_var_configuration = configuration;
71
72 let local_var_client = &local_var_configuration.client;
73
74 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);
75 let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
76
77 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
78 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
79 }
80 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
81 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
82 };
83
84 let local_var_req = local_var_req_builder.build()?;
85 let local_var_resp = local_var_client.execute(local_var_req).await?;
86
87 let local_var_status = local_var_resp.status();
88 let local_var_content = local_var_resp.text().await?;
89
90 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
91 Ok(())
92 } else {
93 let local_var_entity: Option<DeleteFromWorkspaceError> = crate::from_str_patched(&local_var_content).ok();
94 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
95 Err(Error::ResponseError(local_var_error))
96 }
97}
98
99pub async fn export_installation(configuration: &configuration::Configuration, workspace: &str, installation_id: i32) -> Result<models::ExportInstallation200Response, Error<ExportInstallationError>> {
101 let local_var_configuration = configuration;
102
103 let local_var_client = &local_var_configuration.client;
104
105 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);
106 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
107
108 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
109 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
110 }
111 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
112 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
113 };
114
115 let local_var_req = local_var_req_builder.build()?;
116 let local_var_resp = local_var_client.execute(local_var_req).await?;
117
118 let local_var_status = local_var_resp.status();
119 let local_var_content = local_var_resp.text().await?;
120
121 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
122 crate::from_str_patched(&local_var_content).map_err(Error::from)
123 } else {
124 let local_var_entity: Option<ExportInstallationError> = crate::from_str_patched(&local_var_content).ok();
125 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
126 Err(Error::ResponseError(local_var_error))
127 }
128}
129
130pub async fn get_ghes_config(configuration: &configuration::Configuration, ) -> Result<models::GetGhesConfig200Response, Error<GetGhesConfigError>> {
132 let local_var_configuration = configuration;
133
134 let local_var_client = &local_var_configuration.client;
135
136 let local_var_uri_str = format!("{}/github_app/ghes_config", local_var_configuration.base_path);
137 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
138
139 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
140 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
141 }
142 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
143 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
144 };
145
146 let local_var_req = local_var_req_builder.build()?;
147 let local_var_resp = local_var_client.execute(local_var_req).await?;
148
149 let local_var_status = local_var_resp.status();
150 let local_var_content = local_var_resp.text().await?;
151
152 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
153 crate::from_str_patched(&local_var_content).map_err(Error::from)
154 } else {
155 let local_var_entity: Option<GetGhesConfigError> = crate::from_str_patched(&local_var_content).ok();
156 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
157 Err(Error::ResponseError(local_var_error))
158 }
159}
160
161pub async fn get_global_connected_repositories(configuration: &configuration::Configuration, page: Option<i32>) -> Result<Vec<models::GithubInstallationsInner>, Error<GetGlobalConnectedRepositoriesError>> {
162 let local_var_configuration = configuration;
163
164 let local_var_client = &local_var_configuration.client;
165
166 let local_var_uri_str = format!("{}/github_app/connected_repositories", local_var_configuration.base_path);
167 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
168
169 if let Some(ref local_var_str) = page {
170 local_var_req_builder = local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
171 }
172 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
173 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
174 }
175 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
176 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
177 };
178
179 let local_var_req = local_var_req_builder.build()?;
180 let local_var_resp = local_var_client.execute(local_var_req).await?;
181
182 let local_var_status = local_var_resp.status();
183 let local_var_content = local_var_resp.text().await?;
184
185 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
186 crate::from_str_patched(&local_var_content).map_err(Error::from)
187 } else {
188 let local_var_entity: Option<GetGlobalConnectedRepositoriesError> = crate::from_str_patched(&local_var_content).ok();
189 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
190 Err(Error::ResponseError(local_var_error))
191 }
192}
193
194pub async fn ghes_installation_callback(configuration: &configuration::Configuration, workspace: &str, ghes_installation_callback_request: models::GhesInstallationCallbackRequest) -> Result<(), Error<GhesInstallationCallbackError>> {
196 let local_var_configuration = configuration;
197
198 let local_var_client = &local_var_configuration.client;
199
200 let local_var_uri_str = format!("{}/w/{workspace}/github_app/ghes_installation_callback", local_var_configuration.base_path, workspace=crate::apis::urlencode(workspace));
201 let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
202
203 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
204 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
205 }
206 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
207 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
208 };
209 local_var_req_builder = local_var_req_builder.json(&ghes_installation_callback_request);
210
211 let local_var_req = local_var_req_builder.build()?;
212 let local_var_resp = local_var_client.execute(local_var_req).await?;
213
214 let local_var_status = local_var_resp.status();
215 let local_var_content = local_var_resp.text().await?;
216
217 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
218 Ok(())
219 } else {
220 let local_var_entity: Option<GhesInstallationCallbackError> = crate::from_str_patched(&local_var_content).ok();
221 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
222 Err(Error::ResponseError(local_var_error))
223 }
224}
225
226pub async fn import_installation(configuration: &configuration::Configuration, workspace: &str, import_installation_request: models::ImportInstallationRequest) -> Result<(), Error<ImportInstallationError>> {
228 let local_var_configuration = configuration;
229
230 let local_var_client = &local_var_configuration.client;
231
232 let local_var_uri_str = format!("{}/w/{workspace}/github_app/import", local_var_configuration.base_path, workspace=crate::apis::urlencode(workspace));
233 let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
234
235 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
236 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
237 }
238 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
239 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
240 };
241 local_var_req_builder = local_var_req_builder.json(&import_installation_request);
242
243 let local_var_req = local_var_req_builder.build()?;
244 let local_var_resp = local_var_client.execute(local_var_req).await?;
245
246 let local_var_status = local_var_resp.status();
247 let local_var_content = local_var_resp.text().await?;
248
249 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
250 Ok(())
251 } else {
252 let local_var_entity: Option<ImportInstallationError> = crate::from_str_patched(&local_var_content).ok();
253 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
254 Err(Error::ResponseError(local_var_error))
255 }
256}
257
258pub async fn install_from_workspace(configuration: &configuration::Configuration, workspace: &str, install_from_workspace_request: models::InstallFromWorkspaceRequest) -> Result<(), Error<InstallFromWorkspaceError>> {
259 let local_var_configuration = configuration;
260
261 let local_var_client = &local_var_configuration.client;
262
263 let local_var_uri_str = format!("{}/w/{workspace}/github_app/install_from_workspace", local_var_configuration.base_path, workspace=crate::apis::urlencode(workspace));
264 let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
265
266 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
267 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
268 }
269 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
270 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
271 };
272 local_var_req_builder = local_var_req_builder.json(&install_from_workspace_request);
273
274 let local_var_req = local_var_req_builder.build()?;
275 let local_var_resp = local_var_client.execute(local_var_req).await?;
276
277 let local_var_status = local_var_resp.status();
278 let local_var_content = local_var_resp.text().await?;
279
280 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
281 Ok(())
282 } else {
283 let local_var_entity: Option<InstallFromWorkspaceError> = crate::from_str_patched(&local_var_content).ok();
284 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
285 Err(Error::ResponseError(local_var_error))
286 }
287}
288