windmill_api/apis/
git_sync_api.rs

1/*
2 * Windmill API
3 *
4 * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
5 *
6 * The version of the OpenAPI document: 1.575.4
7 * Contact: contact@windmill.dev
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13use serde::{Deserialize, Serialize};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration};
16
17
18/// struct for typed errors of method [`delete_from_workspace`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum DeleteFromWorkspaceError {
22    UnknownValue(serde_json::Value),
23}
24
25/// struct for typed errors of method [`export_installation`]
26#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum ExportInstallationError {
29    UnknownValue(serde_json::Value),
30}
31
32/// struct for typed errors of method [`get_global_connected_repositories`]
33#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum GetGlobalConnectedRepositoriesError {
36    UnknownValue(serde_json::Value),
37}
38
39/// struct for typed errors of method [`import_installation`]
40#[derive(Debug, Clone, Serialize, Deserialize)]
41#[serde(untagged)]
42pub enum ImportInstallationError {
43    UnknownValue(serde_json::Value),
44}
45
46/// struct for typed errors of method [`install_from_workspace`]
47#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum InstallFromWorkspaceError {
50    UnknownValue(serde_json::Value),
51}
52
53
54/// Removes a GitHub installation from the specified workspace. Requires admin privileges.
55pub async fn delete_from_workspace(configuration: &configuration::Configuration, workspace: &str, installation_id: i64) -> Result<(), Error<DeleteFromWorkspaceError>> {
56    let local_var_configuration = configuration;
57
58    let local_var_client = &local_var_configuration.client;
59
60    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);
61    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
62
63    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
64        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
65    }
66    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
67        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
68    };
69
70    let local_var_req = local_var_req_builder.build()?;
71    let local_var_resp = local_var_client.execute(local_var_req).await?;
72
73    let local_var_status = local_var_resp.status();
74    let local_var_content = local_var_resp.text().await?;
75
76    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
77        Ok(())
78    } else {
79        let local_var_entity: Option<DeleteFromWorkspaceError> = crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).ok();
80        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
81        Err(Error::ResponseError(local_var_error))
82    }
83}
84
85/// Exports the JWT token for a specific GitHub installation in the workspace
86pub async fn export_installation(configuration: &configuration::Configuration, workspace: &str, installation_id: i32) -> Result<models::ExportInstallation200Response, Error<ExportInstallationError>> {
87    let local_var_configuration = configuration;
88
89    let local_var_client = &local_var_configuration.client;
90
91    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);
92    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
93
94    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
95        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
96    }
97    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
98        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
99    };
100
101    let local_var_req = local_var_req_builder.build()?;
102    let local_var_resp = local_var_client.execute(local_var_req).await?;
103
104    let local_var_status = local_var_resp.status();
105    let local_var_content = local_var_resp.text().await?;
106
107    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
108        crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).map_err(Error::from)
109    } else {
110        let local_var_entity: Option<ExportInstallationError> = crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).ok();
111        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
112        Err(Error::ResponseError(local_var_error))
113    }
114}
115
116pub async fn get_global_connected_repositories(configuration: &configuration::Configuration, page: Option<i32>) -> Result<Vec<models::GithubInstallationsInner>, Error<GetGlobalConnectedRepositoriesError>> {
117    let local_var_configuration = configuration;
118
119    let local_var_client = &local_var_configuration.client;
120
121    let local_var_uri_str = format!("{}/github_app/connected_repositories", local_var_configuration.base_path);
122    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
123
124    if let Some(ref local_var_str) = page {
125        local_var_req_builder = local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
126    }
127    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
128        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
129    }
130    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
131        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
132    };
133
134    let local_var_req = local_var_req_builder.build()?;
135    let local_var_resp = local_var_client.execute(local_var_req).await?;
136
137    let local_var_status = local_var_resp.status();
138    let local_var_content = local_var_resp.text().await?;
139
140    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
141        crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).map_err(Error::from)
142    } else {
143        let local_var_entity: Option<GetGlobalConnectedRepositoriesError> = crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).ok();
144        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
145        Err(Error::ResponseError(local_var_error))
146    }
147}
148
149/// Imports a GitHub installation from a JWT token exported from another instance
150pub async fn import_installation(configuration: &configuration::Configuration, workspace: &str, import_installation_request: models::ImportInstallationRequest) -> Result<(), Error<ImportInstallationError>> {
151    let local_var_configuration = configuration;
152
153    let local_var_client = &local_var_configuration.client;
154
155    let local_var_uri_str = format!("{}/w/{workspace}/github_app/import", local_var_configuration.base_path, workspace=crate::apis::urlencode(workspace));
156    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
157
158    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
159        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
160    }
161    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
162        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
163    };
164    local_var_req_builder = local_var_req_builder.json(&import_installation_request);
165
166    let local_var_req = local_var_req_builder.build()?;
167    let local_var_resp = local_var_client.execute(local_var_req).await?;
168
169    let local_var_status = local_var_resp.status();
170    let local_var_content = local_var_resp.text().await?;
171
172    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
173        Ok(())
174    } else {
175        let local_var_entity: Option<ImportInstallationError> = crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).ok();
176        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
177        Err(Error::ResponseError(local_var_error))
178    }
179}
180
181pub async fn install_from_workspace(configuration: &configuration::Configuration, workspace: &str, install_from_workspace_request: models::InstallFromWorkspaceRequest) -> Result<(), Error<InstallFromWorkspaceError>> {
182    let local_var_configuration = configuration;
183
184    let local_var_client = &local_var_configuration.client;
185
186    let local_var_uri_str = format!("{}/w/{workspace}/github_app/install_from_workspace", local_var_configuration.base_path, workspace=crate::apis::urlencode(workspace));
187    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
188
189    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
190        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
191    }
192    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
193        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
194    };
195    local_var_req_builder = local_var_req_builder.json(&install_from_workspace_request);
196
197    let local_var_req = local_var_req_builder.build()?;
198    let local_var_resp = local_var_client.execute(local_var_req).await?;
199
200    let local_var_status = local_var_resp.status();
201    let local_var_content = local_var_resp.text().await?;
202
203    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
204        Ok(())
205    } else {
206        let local_var_entity: Option<InstallFromWorkspaceError> = crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).ok();
207        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
208        Err(Error::ResponseError(local_var_error))
209    }
210}
211