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.500.2
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, ) -> 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_user_agent) = local_var_configuration.user_agent {
125        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
126    }
127    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
128        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
129    };
130
131    let local_var_req = local_var_req_builder.build()?;
132    let local_var_resp = local_var_client.execute(local_var_req).await?;
133
134    let local_var_status = local_var_resp.status();
135    let local_var_content = local_var_resp.text().await?;
136
137    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
138        crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).map_err(Error::from)
139    } else {
140        let local_var_entity: Option<GetGlobalConnectedRepositoriesError> = crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).ok();
141        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
142        Err(Error::ResponseError(local_var_error))
143    }
144}
145
146/// Imports a GitHub installation from a JWT token exported from another instance
147pub async fn import_installation(configuration: &configuration::Configuration, workspace: &str, import_installation_request: models::ImportInstallationRequest) -> Result<(), Error<ImportInstallationError>> {
148    let local_var_configuration = configuration;
149
150    let local_var_client = &local_var_configuration.client;
151
152    let local_var_uri_str = format!("{}/w/{workspace}/github_app/import", local_var_configuration.base_path, workspace=crate::apis::urlencode(workspace));
153    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
154
155    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
156        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
157    }
158    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
159        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
160    };
161    local_var_req_builder = local_var_req_builder.json(&import_installation_request);
162
163    let local_var_req = local_var_req_builder.build()?;
164    let local_var_resp = local_var_client.execute(local_var_req).await?;
165
166    let local_var_status = local_var_resp.status();
167    let local_var_content = local_var_resp.text().await?;
168
169    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
170        Ok(())
171    } else {
172        let local_var_entity: Option<ImportInstallationError> = crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).ok();
173        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
174        Err(Error::ResponseError(local_var_error))
175    }
176}
177
178pub async fn install_from_workspace(configuration: &configuration::Configuration, workspace: &str, install_from_workspace_request: models::InstallFromWorkspaceRequest) -> Result<(), Error<InstallFromWorkspaceError>> {
179    let local_var_configuration = configuration;
180
181    let local_var_client = &local_var_configuration.client;
182
183    let local_var_uri_str = format!("{}/w/{workspace}/github_app/install_from_workspace", local_var_configuration.base_path, workspace=crate::apis::urlencode(workspace));
184    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
185
186    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
187        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
188    }
189    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
190        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
191    };
192    local_var_req_builder = local_var_req_builder.json(&install_from_workspace_request);
193
194    let local_var_req = local_var_req_builder.build()?;
195    let local_var_resp = local_var_client.execute(local_var_req).await?;
196
197    let local_var_status = local_var_resp.status();
198    let local_var_content = local_var_resp.text().await?;
199
200    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
201        Ok(())
202    } else {
203        let local_var_entity: Option<InstallFromWorkspaceError> = crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).ok();
204        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
205        Err(Error::ResponseError(local_var_error))
206    }
207}
208