Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions crates/crates_io_github/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,24 @@ pub struct GitHubTeamMembership {
pub state: String,
}

impl GitHubTeamMembership {
pub fn is_active(&self) -> bool {
self.state == "active"
}
}

#[derive(Debug, Deserialize)]
pub struct GitHubOrgMembership {
pub state: String,
pub role: String,
}

impl GitHubOrgMembership {
pub fn is_active_admin(&self) -> bool {
self.state == "active" && self.role == "admin"
}
}

#[derive(Debug, Deserialize, Clone, Eq, Hash, PartialEq)]
pub struct GitHubPublicKey {
pub key_identifier: String,
Expand Down
4 changes: 2 additions & 2 deletions src/models/team.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ async fn is_gh_org_owner(
token: &AccessToken,
) -> Result<bool, GitHubError> {
let membership = gh_client.org_membership(org_id, gh_login, token).await?;
Ok(membership.is_some_and(|m| m.state == "active" && m.role == "admin"))
Ok(membership.is_some_and(|m| m.is_active_admin()))
}

async fn team_with_gh_id_contains_user(
Expand All @@ -236,5 +236,5 @@ async fn team_with_gh_id_contains_user(

// There is also `state: pending` for which we could possibly give
// some feedback, but it's not obvious how that should work.
Ok(membership.is_some_and(|m| m.state == "active"))
Ok(membership.is_some_and(|m| m.is_active()))
}
Loading