-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
384 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
query TeamMembersList($team: ID!) { | ||
team(id: $team) { | ||
members { | ||
edges { | ||
node { | ||
id | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
mutation TeamMemberAdd($team: ID!, $accounts: [ID!]!) { | ||
addToTeam(teamID: $team, userIDs: $accounts) | ||
} | ||
|
||
mutation TeamMemberRemove($team: ID!, $accounts: [ID!]!) { | ||
removeFromTeam(teamID: $team, userIDs: $accounts) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
use anyhow::Result; | ||
use clap::Args; | ||
use graphql_client::{GraphQLQuery, Response}; | ||
|
||
use crate::api::ApiClient; | ||
|
||
#[derive(GraphQLQuery)] | ||
#[graphql( | ||
schema_path = "schema.json", | ||
query_path = "src/command/teams/members.graphql", | ||
response_derives = "Debug" | ||
)] | ||
pub struct TeamMembersList; | ||
|
||
#[derive(Debug, Args, serde::Serialize)] | ||
#[command(next_help_heading = "Team list options")] | ||
pub struct TeamListArgs {} | ||
|
||
impl TeamListArgs { | ||
pub async fn run(&self, team: String) -> Result<()> { | ||
let request_body = | ||
TeamMembersList::build_query(self::team_members_list::Variables { team: team.clone() }); | ||
|
||
let client = ApiClient::new(); | ||
let res: Response<team_members_list::ResponseData> = client.post(&request_body).await?; | ||
if let Some(errors) = res.errors.clone() { | ||
for err in errors { | ||
println!("Error: {}", err.message); | ||
} | ||
|
||
return Ok(()); | ||
} | ||
|
||
if let Some(data) = res.data { | ||
println!("{} members:", team); | ||
data.team | ||
.and_then(|team_list| team_list.members.edges) | ||
.into_iter() | ||
.flatten() | ||
.for_each(|edge| { | ||
if let Some(node) = edge.and_then(|edge| edge.node) { | ||
println!(" {}", node.id) | ||
} | ||
}); | ||
} | ||
|
||
Ok(()) | ||
} | ||
} | ||
|
||
#[derive(GraphQLQuery)] | ||
#[graphql( | ||
schema_path = "schema.json", | ||
query_path = "src/command/teams/members.graphql", | ||
response_derives = "Debug" | ||
)] | ||
pub struct TeamMemberAdd; | ||
|
||
#[derive(Debug, Args, serde::Serialize)] | ||
#[command(next_help_heading = "Team add options")] | ||
pub struct TeamAddArgs { | ||
#[arg(help = "Name of the team member to add.")] | ||
pub account: Vec<String>, | ||
} | ||
|
||
impl TeamAddArgs { | ||
pub async fn run(&self, team: String) -> Result<()> { | ||
let request_body = TeamMemberAdd::build_query(self::team_member_add::Variables { | ||
team, | ||
accounts: self.account.clone(), | ||
}); | ||
|
||
let client = ApiClient::new(); | ||
let res: Response<team_member_add::ResponseData> = client.post(&request_body).await?; | ||
if let Some(errors) = res.errors { | ||
for err in errors { | ||
println!("Error: {}", err.message); | ||
} | ||
|
||
return Ok(()); | ||
} | ||
|
||
Ok(()) | ||
} | ||
} | ||
|
||
#[derive(GraphQLQuery)] | ||
#[graphql( | ||
schema_path = "schema.json", | ||
query_path = "src/command/teams/members.graphql", | ||
response_derives = "Debug" | ||
)] | ||
pub struct TeamMemberRemove; | ||
|
||
#[derive(Debug, Args, serde::Serialize)] | ||
#[command(next_help_heading = "Team remove options")] | ||
pub struct TeamRemoveArgs { | ||
#[arg(help = "Name of the team member to add.")] | ||
pub account: Vec<String>, | ||
} | ||
|
||
impl TeamRemoveArgs { | ||
pub async fn run(&self, team: String) -> Result<()> { | ||
let request_body = TeamMemberRemove::build_query(self::team_member_remove::Variables { | ||
team, | ||
accounts: self.account.clone(), | ||
}); | ||
|
||
let client = ApiClient::new(); | ||
let res: Response<team_member_remove::ResponseData> = client.post(&request_body).await?; | ||
if let Some(errors) = res.errors { | ||
for err in errors { | ||
println!("Error: {}", err.message); | ||
} | ||
|
||
return Ok(()); | ||
} | ||
|
||
Ok(()) | ||
} | ||
} |
Oops, something went wrong.