josh_github_graphql/operations/
collaborators.rs1use crate::connection::GithubApiConnection;
2
3use josh_github_codegen_graphql::{get_repository_collaborators, GetRepositoryCollaborators};
4
5impl GithubApiConnection {
6 pub async fn get_maintainers(&self, owner: &str, name: &str) -> anyhow::Result<Vec<String>> {
7 let mut maintainers = Vec::new();
8 let mut cursor: Option<String> = None;
9
10 loop {
11 let variables = get_repository_collaborators::Variables {
12 owner: owner.to_string(),
13 name: name.to_string(),
14 first: 100,
15 after: cursor,
16 };
17
18 let response = self
19 .make_request::<GetRepositoryCollaborators>(variables)
20 .await?;
21
22 let collaborators = response.repository.and_then(|r| r.collaborators);
23
24 let collaborators = match collaborators {
25 Some(c) => c,
26 None => break,
27 };
28
29 if let Some(edges) = collaborators.edges {
30 use get_repository_collaborators::RepositoryPermission;
31 for edge in edges.into_iter().flatten() {
32 if matches!(
33 edge.permission,
34 RepositoryPermission::Write
35 | RepositoryPermission::Maintain
36 | RepositoryPermission::Admin
37 ) {
38 maintainers.push(edge.node.login);
39 }
40 }
41 }
42
43 if collaborators.page_info.has_next_page {
44 cursor = collaborators.page_info.end_cursor;
45 } else {
46 break;
47 }
48 }
49
50 Ok(maintainers)
51 }
52}