1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
use crate::{models::InstallationId, Octocrab};
use http::request::Builder;
use http::Method;
mod application;
mod installation_repositories;
mod installation_requests;
mod installations;
mod webhook;
pub use self::{
application::ApplicationHandler,
installation_repositories::ListInstallationRepositoriesBuilder,
installation_requests::InstallationRequestsBuilder,
installations::InstallationsRequestBuilder,
webhook::{AppWebhookHandler, ListAppWebhookDeliveriesBuilder},
};
/// Type alias for [`AppsRequestHandler`].
pub type AppsHandler<'octo> = AppsRequestHandler<'octo>;
/// A client to [GitHub's apps API][apps-api].
///
/// Created with [`Octocrab::apps`].
///
/// [apps-api]: https://docs.github.com/en/rest/apps
pub struct AppsRequestHandler<'octo> {
crab: &'octo Octocrab,
}
impl<'octo> AppsRequestHandler<'octo> {
pub(crate) fn new(crab: &'octo Octocrab) -> Self {
Self { crab }
}
/// Gets the authenticated GitHub App.
///
/// See: [GitHub API Documentation](https://docs.github.com/en/rest/apps/apps?apiVersion=2022-11-28#get-the-authenticated-app)
pub async fn get(&self) -> crate::Result<crate::models::apps::App> {
self.crab.get("/app", None::<&()>).await
}
/// Creates a GitHub App from a manifest code conversion.
///
/// See: [GitHub API Documentation](https://docs.github.com/en/rest/apps/apps?apiVersion=2022-11-28#create-a-github-app-from-a-manifest)
pub async fn create_from_manifest(
&self,
code: impl AsRef<str>,
) -> crate::Result<crate::models::apps::App> {
let route = format!("/app-manifests/{}/conversions", code.as_ref());
self.crab.post(route, None::<&()>).await
}
/// Get an installation for the authenticated app.
///
/// ```no_run
/// # async fn run(octocrab: &octocrab::Octocrab) -> octocrab::Result<()> {
/// use octocrab::models::InstallationId;
///
/// let installation = octocrab
/// .apps()
/// .installation(InstallationId(1))
/// .await?;
/// # Ok(())
/// # }
/// ```
pub async fn installation(
&self,
installation_id: impl Into<InstallationId>,
) -> crate::Result<crate::models::Installation> {
let route = format!("/app/installations/{}", installation_id.into());
self.crab.get(&route, None::<&()>).await
}
/// Creates a new `InstallationsBuilder` that can be configured to filter
/// listing installations.
///
/// ```no_run
/// # async fn run(octocrab: &octocrab::Octocrab) -> octocrab::Result<()> {
/// use octocrab::params;
///
/// let page = octocrab
/// .apps()
/// .installations()
/// // Optional Parameters
/// .since(chrono::Utc::now() - chrono::Duration::days(1))
/// .per_page(100)
/// .page(5u32)
/// // Send the request
/// .send()
/// .await?;
/// # Ok(())
/// # }
/// ```
pub fn installations(&self) -> installations::InstallationsRequestBuilder<'_, '_> {
installations::InstallationsRequestBuilder::new(self)
}
/// Lists pending installation requests for the authenticated app.
///
/// See: [GitHub API Documentation](https://docs.github.com/en/rest/apps/apps?apiVersion=2022-11-28#list-installation-requests-for-the-authenticated-app)
pub fn installation_requests(&self) -> InstallationRequestsBuilder<'octo> {
InstallationRequestsBuilder::new(self.crab)
}
/// Deletes an installation for the authenticated app.
///
/// See: [GitHub API Documentation](https://docs.github.com/en/rest/apps/apps?apiVersion=2022-11-28#delete-an-installation-for-the-authenticated-app)
pub async fn delete_installation(
&self,
installation_id: impl Into<InstallationId>,
) -> crate::Result<()> {
let route = format!("/app/installations/{}", installation_id.into());
let resp = self.crab._delete(route, None::<&()>).await?;
crate::map_github_error(resp).await?;
Ok(())
}
/// Creates an installation access token for an app.
///
/// See: [GitHub API Documentation](https://docs.github.com/en/rest/apps/apps?apiVersion=2022-11-28#create-an-installation-access-token-for-an-app)
pub async fn create_installation_access_token(
&self,
installation_id: impl Into<InstallationId>,
body: &crate::models::apps::CreateInstallationAccessToken,
) -> crate::Result<crate::models::InstallationToken> {
let route = format!(
"/app/installations/{}/access_tokens",
installation_id.into()
);
self.crab.post(route, Some(body)).await
}
/// Suspends an app installation.
///
/// See: [GitHub API Documentation](https://docs.github.com/en/rest/apps/apps?apiVersion=2022-11-28#suspend-an-app-installation)
pub async fn suspend_installation(
&self,
installation_id: impl Into<InstallationId>,
) -> crate::Result<()> {
let route = format!("/app/installations/{}/suspended", installation_id.into());
let resp = self.crab._put(route, None::<&()>).await?;
crate::map_github_error(resp).await?;
Ok(())
}
/// Unsuspends an app installation.
///
/// See: [GitHub API Documentation](https://docs.github.com/en/rest/apps/apps?apiVersion=2022-11-28#unsuspend-an-app-installation)
pub async fn unsuspend_installation(
&self,
installation_id: impl Into<InstallationId>,
) -> crate::Result<()> {
let route = format!("/app/installations/{}/suspended", installation_id.into());
let resp = self.crab._delete(route, None::<&()>).await?;
crate::map_github_error(resp).await?;
Ok(())
}
/// Gets a user installation for the authenticated app.
///
/// See: [GitHub API Documentation](https://docs.github.com/en/rest/apps/apps?apiVersion=2022-11-28#get-a-user-installation-for-the-authenticated-app)
pub async fn get_user_installation(
&self,
username: impl AsRef<str>,
) -> crate::Result<crate::models::Installation> {
let route = format!("/users/{}/installation", username.as_ref());
self.crab.get(&route, None::<&()>).await
}
/// Lists repositories accessible to the app installation.
///
/// See: [GitHub API Documentation](https://docs.github.com/en/rest/apps/installations?apiVersion=2022-11-28#list-repositories-accessible-to-the-app-installation)
pub fn installation_repositories(&self) -> ListInstallationRepositoriesBuilder<'octo> {
ListInstallationRepositoriesBuilder::new(self.crab)
}
/// Revokes an installation access token.
///
/// See: [GitHub API Documentation](https://docs.github.com/en/rest/apps/installations?apiVersion=2022-11-28#revoke-an-installation-access-token)
pub async fn revoke_installation_token(&self) -> crate::Result<()> {
let resp = self
.crab
._delete("/installation/token", None::<&()>)
.await?;
crate::map_github_error(resp).await?;
Ok(())
}
/// Access webhook operations for the authenticated GitHub App.
pub fn webhook(&self) -> AppWebhookHandler<'octo> {
AppWebhookHandler::new(self.crab)
}
/// Gets the webhook configuration for the authenticated app.
pub async fn webhook_config(&self) -> crate::Result<crate::models::hooks::Config> {
self.webhook().get_config().await
}
/// Updates the webhook configuration for the authenticated app.
pub async fn update_webhook_config(
&self,
config: &crate::models::apps::UpdateWebhookConfig,
) -> crate::Result<crate::models::hooks::Config> {
self.webhook().update_config(config).await
}
/// Lists deliveries for the authenticated app's webhook.
pub fn webhook_deliveries(&self) -> ListAppWebhookDeliveriesBuilder<'octo> {
self.webhook().deliveries()
}
/// Gets a specific delivery for the authenticated app's webhook.
pub async fn get_webhook_delivery(
&self,
delivery_id: impl Into<crate::models::HookDeliveryId>,
) -> crate::Result<crate::models::hooks::DeliveryDetail> {
self.webhook().delivery(delivery_id).await
}
/// Redelivers a delivery for the authenticated app's webhook.
pub async fn redeliver_webhook_delivery(
&self,
delivery_id: impl Into<crate::models::HookDeliveryId>,
) -> crate::Result<()> {
self.webhook().redeliver(delivery_id).await
}
/// Access OAuth authorization operations for a specific application client ID.
pub fn application(&self, client_id: impl Into<String>) -> ApplicationHandler<'octo> {
ApplicationHandler::new(self.crab, client_id.into())
}
/// Access GitHub Marketplace operations.
pub fn marketplace(&self) -> crate::api::marketplace::MarketplaceHandler<'octo> {
crate::api::marketplace::MarketplaceHandler::new(self.crab)
}
pub(crate) async fn http_get<R, A, P>(
&self,
route: A,
parameters: Option<&P>,
) -> crate::Result<R>
where
A: AsRef<str>,
P: serde::Serialize + ?Sized,
R: crate::FromResponse,
{
let request = Builder::new()
.method(Method::GET)
.uri(self.crab.parameterized_uri(route, parameters)?);
let request = self.crab.build_request(request, None::<&()>)?;
R::from_response(crate::map_github_error(self.crab.execute(request).await?).await?).await
}
/// Get a repository installation for the authenticated app.
pub async fn get_repository_installation(
&self,
owner: impl AsRef<str>,
repo: impl AsRef<str>,
) -> crate::Result<crate::models::Installation> {
let route = format!(
"/repos/{owner}/{repo}/installation",
owner = owner.as_ref(),
repo = repo.as_ref(),
);
self.crab.get(&route, None::<&()>).await
}
/// Get an organization installation for the authenticated app.
pub async fn get_org_installation(
&self,
owner: impl AsRef<str>,
) -> crate::Result<crate::models::Installation> {
let route = format!("/orgs/{owner}/installation", owner = owner.as_ref(),);
self.crab.get(&route, None::<&()>).await
}
/// Get a GitHub App by its slug.
pub async fn get_app(
&self,
app_slug: impl AsRef<str>,
) -> crate::Result<crate::models::apps::App> {
let route = format!("/apps/{app_slug}", app_slug = app_slug.as_ref());
self.crab.get(&route, None::<&()>).await
}
}