-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add bl team add / update / delete / icon commands #105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
7cf37b4
docs: add patterns from issue-54 implementation
23prime 70a58ba
feat: add bl team add / update / delete / icon commands
23prime 8a416e8
refactor: consolidate format_team_row to mod.rs and add member count …
23prime 1906965
fix: reject empty members list in TeamUpdateArgs::try_new when name i…
23prime File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -34,3 +34,4 @@ NEWKEY | |
| burndown | ||
| splitn | ||
| hexdigit | ||
| PRRT | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,114 @@ | ||
| use anstream::println; | ||
| use anyhow::{Context, Result}; | ||
|
|
||
| use super::format_team_row; | ||
| use crate::api::{BacklogApi, BacklogClient}; | ||
|
|
||
| pub struct TeamAddArgs { | ||
| name: String, | ||
| members: Vec<u64>, | ||
| json: bool, | ||
| } | ||
|
|
||
| impl TeamAddArgs { | ||
| pub fn new(name: String, members: Vec<u64>, json: bool) -> Self { | ||
| Self { | ||
| name, | ||
| members, | ||
| json, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| pub fn add(args: &TeamAddArgs) -> Result<()> { | ||
| let client = BacklogClient::from_config()?; | ||
| add_with(args, &client) | ||
| } | ||
|
|
||
| pub fn add_with(args: &TeamAddArgs, api: &dyn BacklogApi) -> Result<()> { | ||
| let mut params = vec![("name".to_string(), args.name.clone())]; | ||
| for id in &args.members { | ||
| params.push(("members[]".to_string(), id.to_string())); | ||
| } | ||
| let team = api.create_team(¶ms)?; | ||
| if args.json { | ||
| println!( | ||
| "{}", | ||
| serde_json::to_string_pretty(&team).context("Failed to serialize JSON")? | ||
| ); | ||
| } else { | ||
| println!("Created: {}", format_team_row(&team)); | ||
| } | ||
| Ok(()) | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
| use anyhow::anyhow; | ||
| use std::collections::BTreeMap; | ||
|
|
||
| use crate::api::team::{Team, TeamMember}; | ||
|
|
||
| struct MockApi { | ||
| team: Option<Team>, | ||
| } | ||
|
|
||
| impl crate::api::BacklogApi for MockApi { | ||
| fn create_team(&self, _params: &[(String, String)]) -> anyhow::Result<Team> { | ||
| self.team.clone().ok_or_else(|| anyhow!("create failed")) | ||
| } | ||
| } | ||
|
|
||
| fn sample_member() -> TeamMember { | ||
| TeamMember { | ||
| id: 2, | ||
| user_id: Some("dev".to_string()), | ||
| name: "Developer".to_string(), | ||
| role_type: 2, | ||
| lang: None, | ||
| mail_address: None, | ||
| last_login_time: None, | ||
| extra: BTreeMap::new(), | ||
| } | ||
| } | ||
|
|
||
| fn sample_team() -> Team { | ||
| Team { | ||
| id: 1, | ||
| name: "dev-team".to_string(), | ||
| members: vec![sample_member()], | ||
| display_order: None, | ||
| created: "2024-01-01T00:00:00Z".to_string(), | ||
| updated: "2024-01-01T00:00:00Z".to_string(), | ||
| extra: BTreeMap::new(), | ||
| } | ||
| } | ||
|
|
||
| fn args(json: bool) -> TeamAddArgs { | ||
| TeamAddArgs::new("dev-team".to_string(), vec![2], json) | ||
| } | ||
|
|
||
| #[test] | ||
| fn add_with_text_output_succeeds() { | ||
| let api = MockApi { | ||
| team: Some(sample_team()), | ||
| }; | ||
| assert!(add_with(&args(false), &api).is_ok()); | ||
| } | ||
|
|
||
| #[test] | ||
| fn add_with_json_output_succeeds() { | ||
| let api = MockApi { | ||
| team: Some(sample_team()), | ||
| }; | ||
| assert!(add_with(&args(true), &api).is_ok()); | ||
| } | ||
|
|
||
| #[test] | ||
| fn add_with_propagates_api_error() { | ||
| let api = MockApi { team: None }; | ||
| let err = add_with(&args(false), &api).unwrap_err(); | ||
| assert!(err.to_string().contains("create failed")); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.