octocrab 0.54.7

A modern, extensible GitHub API client.
Documentation
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
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
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?apiVersion=2022-11-28
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)
    ///
    /// # Examples
    ///
    /// ```no_run
    /// # async fn run(octocrab: &octocrab::Octocrab) -> octocrab::Result<()> {
    /// let app = octocrab.apps().get().await?;
    /// # Ok(())
    /// # }
    /// ```
    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)
    ///
    /// # Examples
    ///
    /// ```no_run
    /// # async fn run(octocrab: &octocrab::Octocrab) -> octocrab::Result<()> {
    /// let app = octocrab.apps().create_from_manifest("code").await?;
    /// # Ok(())
    /// # }
    /// ```
    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)
    ///
    /// # Examples
    ///
    /// ```no_run
    /// # async fn run(octocrab: &octocrab::Octocrab) -> octocrab::Result<()> {
    /// let requests = octocrab.apps().installation_requests().send().await?;
    /// # Ok(())
    /// # }
    /// ```
    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)
    ///
    /// # Examples
    ///
    /// ```no_run
    /// # async fn run(octocrab: &octocrab::Octocrab) -> octocrab::Result<()> {
    /// use octocrab::models::InstallationId;
    ///
    /// octocrab.apps().delete_installation(InstallationId(1)).await?;
    /// # Ok(())
    /// # }
    /// ```
    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)
    ///
    /// # Examples
    ///
    /// ```no_run
    /// # async fn run(octocrab: &octocrab::Octocrab) -> octocrab::Result<()> {
    /// use octocrab::models::apps::CreateInstallationAccessToken;
    /// use octocrab::models::InstallationId;
    ///
    /// let token = octocrab
    ///     .apps()
    ///     .create_installation_access_token(
    ///         InstallationId(1),
    ///         &CreateInstallationAccessToken::default(),
    ///     )
    ///     .await?;
    /// # Ok(())
    /// # }
    /// ```
    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)
    ///
    /// # Examples
    ///
    /// ```no_run
    /// # async fn run(octocrab: &octocrab::Octocrab) -> octocrab::Result<()> {
    /// use octocrab::models::InstallationId;
    ///
    /// octocrab.apps().suspend_installation(InstallationId(1)).await?;
    /// # Ok(())
    /// # }
    /// ```
    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)
    ///
    /// # Examples
    ///
    /// ```no_run
    /// # async fn run(octocrab: &octocrab::Octocrab) -> octocrab::Result<()> {
    /// use octocrab::models::InstallationId;
    ///
    /// octocrab.apps().unsuspend_installation(InstallationId(1)).await?;
    /// # Ok(())
    /// # }
    /// ```
    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)
    ///
    /// # Examples
    ///
    /// ```no_run
    /// # async fn run(octocrab: &octocrab::Octocrab) -> octocrab::Result<()> {
    /// let installation = octocrab.apps().get_user_installation("username").await?;
    /// # Ok(())
    /// # }
    /// ```
    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)
    ///
    /// # Examples
    ///
    /// ```no_run
    /// # async fn run(octocrab: &octocrab::Octocrab) -> octocrab::Result<()> {
    /// let repos = octocrab.apps().installation_repositories().send().await?;
    /// # Ok(())
    /// # }
    /// ```
    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)
    ///
    /// # Examples
    ///
    /// ```no_run
    /// # async fn run(octocrab: &octocrab::Octocrab) -> octocrab::Result<()> {
    /// octocrab.apps().revoke_installation_token().await?;
    /// # Ok(())
    /// # }
    /// ```
    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.
    ///
    /// # Examples
    ///
    /// ```no_run
    /// # async fn run(octocrab: &octocrab::Octocrab) -> octocrab::Result<()> {
    /// let config = octocrab.apps().webhook().get_config().await?;
    /// # Ok(())
    /// # }
    /// ```
    pub fn webhook(&self) -> AppWebhookHandler<'octo> {
        AppWebhookHandler::new(self.crab)
    }

    /// Gets the webhook configuration for the authenticated app.
    ///
    /// # Examples
    ///
    /// ```no_run
    /// # async fn run(octocrab: &octocrab::Octocrab) -> octocrab::Result<()> {
    /// let config = octocrab.apps().webhook_config().await?;
    /// # Ok(())
    /// # }
    /// ```
    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.
    ///
    /// # Examples
    ///
    /// ```no_run
    /// # async fn run(octocrab: &octocrab::Octocrab) -> octocrab::Result<()> {
    /// use octocrab::models::apps::UpdateWebhookConfig;
    ///
    /// let config = UpdateWebhookConfig::default();
    /// let updated = octocrab.apps().update_webhook_config(&config).await?;
    /// # Ok(())
    /// # }
    /// ```
    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.
    ///
    /// # Examples
    ///
    /// ```no_run
    /// # async fn run(octocrab: &octocrab::Octocrab) -> octocrab::Result<()> {
    /// let deliveries = octocrab.apps().webhook_deliveries().send().await?;
    /// # Ok(())
    /// # }
    /// ```
    pub fn webhook_deliveries(&self) -> ListAppWebhookDeliveriesBuilder<'octo> {
        self.webhook().deliveries()
    }

    /// Gets a specific delivery for the authenticated app's webhook.
    ///
    /// # Examples
    ///
    /// ```no_run
    /// # async fn run(octocrab: &octocrab::Octocrab) -> octocrab::Result<()> {
    /// use octocrab::models::HookDeliveryId;
    ///
    /// let delivery = octocrab.apps().get_webhook_delivery(HookDeliveryId(1)).await?;
    /// # Ok(())
    /// # }
    /// ```
    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.
    ///
    /// # Examples
    ///
    /// ```no_run
    /// # async fn run(octocrab: &octocrab::Octocrab) -> octocrab::Result<()> {
    /// use octocrab::models::HookDeliveryId;
    ///
    /// octocrab.apps().redeliver_webhook_delivery(HookDeliveryId(1)).await?;
    /// # Ok(())
    /// # }
    /// ```
    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.
    ///
    /// # Examples
    ///
    /// ```no_run
    /// # async fn run(octocrab: &octocrab::Octocrab) -> octocrab::Result<()> {
    /// let app = octocrab.apps().application("client_id");
    /// # Ok(())
    /// # }
    /// ```
    pub fn application(&self, client_id: impl Into<String>) -> ApplicationHandler<'octo> {
        ApplicationHandler::new(self.crab, client_id.into())
    }

    /// Access GitHub Marketplace operations.
    ///
    /// # Examples
    ///
    /// ```no_run
    /// # async fn run(octocrab: &octocrab::Octocrab) -> octocrab::Result<()> {
    /// let plans = octocrab.apps().marketplace().list_plans().send().await?;
    /// # Ok(())
    /// # }
    /// ```
    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.
    ///
    /// # Examples
    ///
    /// ```no_run
    /// # async fn run(octocrab: &octocrab::Octocrab) -> octocrab::Result<()> {
    /// let installation = octocrab.apps().get_repository_installation("owner", "repo").await?;
    /// # Ok(())
    /// # }
    /// ```
    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.
    ///
    /// # Examples
    ///
    /// ```no_run
    /// # async fn run(octocrab: &octocrab::Octocrab) -> octocrab::Result<()> {
    /// let installation = octocrab.apps().get_org_installation("org").await?;
    /// # Ok(())
    /// # }
    /// ```
    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.
    ///
    /// # Examples
    ///
    /// ```no_run
    /// # async fn run(octocrab: &octocrab::Octocrab) -> octocrab::Result<()> {
    /// let app = octocrab.apps().get_app("my-app").await?;
    /// # Ok(())
    /// # }
    /// ```
    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
    }
}