Skip to content

Commit

Permalink
list installations for user access token (#378)
Browse files Browse the repository at this point in the history
  • Loading branch information
lswith authored Jun 3, 2023
1 parent a5d76ca commit ae2387e
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 1 deletion.
70 changes: 69 additions & 1 deletion src/api/current.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Get data about the currently authenticated user.
use crate::{
models::{self, gists::Gist, orgs::MembershipInvitation, Repository},
models::{self, gists::Gist, orgs::MembershipInvitation, Installation, Repository},
Octocrab, Page, Result,
};
use chrono::{DateTime, Utc};
Expand Down Expand Up @@ -124,6 +124,26 @@ impl<'octo> CurrentAuthHandler<'octo> {
ListStarredGistsBuilder::new(self.crab)
}

/// Lists installations of your GitHub App that the authenticated user has explicit permission (:read, :write, or :admin) to access.
///
/// ```no_run
/// # async fn run() -> octocrab::Result<()> {
/// octocrab::instance()
/// .current()
/// .list_app_installations_accessible_to_user()
/// .send()
/// .await?;
/// # Ok(())
/// # }
/// ```
///
/// [See the GitHub API documentation](https://docs.github.com/en/rest/apps/installations?apiVersion=2022-11-28#list-app-installations-accessible-to-the-user-access-token)
pub fn list_app_installations_accessible_to_user(
&self,
) -> ListAppInstallationsAccessibleToUserBuilder<'octo> {
ListAppInstallationsAccessibleToUserBuilder::new(self.crab)
}

/// Lists organizations that the current authenticated user is a member of.
///
/// ```no_run
Expand Down Expand Up @@ -519,3 +539,51 @@ impl<'octo> ListOrgMembershipsForAuthenticatedUserBuilder<'octo> {
.await
}
}

/// A builder pattern struct for listing the installations accessible to a user access token.
///
/// Created by [`CurrentAuthHandler::list_app_installations_accessible_to_user`].
///
/// [`CurrentAuthHandler::list_app_installations_accessible_to_user`]: ./struct.CurrentAuthHandler.html#method.list_app_installations_accessible_to_user
#[derive(serde::Serialize)]
pub struct ListAppInstallationsAccessibleToUserBuilder<'octo> {
#[serde(skip)]
crab: &'octo Octocrab,

#[serde(skip_serializing_if = "Option::is_none")]
per_page: Option<u8>,

#[serde(skip_serializing_if = "Option::is_none")]
page: Option<u8>,
}

impl<'octo> ListAppInstallationsAccessibleToUserBuilder<'octo> {
fn new(crab: &'octo Octocrab) -> Self {
Self {
crab,
per_page: None,
page: None,
}
}

/// Results per page (max 100).
///
/// [See the GitHub API documentation](https://docs.github.com/en/rest/apps/installations?apiVersion=2022-11-28#list-app-installations-accessible-to-the-user-access-token--parameters)
pub fn per_page(mut self, per_page: impl Into<u8>) -> Self {
self.per_page = Some(per_page.into());
self
}

/// Page number of the results to fetch.
///
/// [See the GitHub API documentation](https://docs.github.com/en/rest/apps/installations?apiVersion=2022-11-28#list-app-installations-accessible-to-the-user-access-token--parameters)
pub fn page(mut self, page: impl Into<u8>) -> Self {
self.page = Some(page.into());
self
}

/// Sends the actual request.
pub async fn send(self) -> crate::Result<Page<Installation>> {
self.crab.get("/user/installations", (&self).into()).await
}
}
1 change: 1 addition & 0 deletions src/page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ impl<T: serde::de::DeserializeOwned> crate::FromResponse for Page<T> {
"jobs",
"artifacts",
"repositories",
"installations",
]
.into_iter()
.find(|v| json.get(v).is_some())
Expand Down

0 comments on commit ae2387e

Please sign in to comment.