feat(cli) Add All missing features of the Organizations API#263
feat(cli) Add All missing features of the Organizations API#263DerBurri wants to merge 61 commits into
Conversation
2452e6c to
1487f91
Compare
044e3a4 to
a513836
Compare
3ceec3c to
a58b8eb
Compare
OliverTrautvetter
left a comment
There was a problem hiding this comment.
Nice feature, some comments for it 👍
00c60bf to
db693fa
Compare
b8b9251 to
66f578e
Compare
OliverTrautvetter
left a comment
There was a problem hiding this comment.
Some more comments to improve it
58da364 to
92ac544
Compare
…#274) Signed-off-by: Maximilian <burr.maximilian97@gmail.com>
…#275) Signed-off-by: Maximilian <burr.maximilian97@gmail.com>
Signed-off-by: Maximilian <burr.maximilian97@gmail.com>
Signed-off-by: Maximilian <burr.maximilian97@gmail.com>
Signed-off-by: Maximilian <burr.maximilian97@gmail.com>
* feat: add first draft cs mcp server * fix: add cs-mcp to gitignore * fix: fix env var names in readme * update: clean up workspace structs * update: add mcp server to the main cs-go cli * update: remove mcp readme, add long mcp cmd description, remove old build related stuff * update: update file name of the main mcp file * chore(docs): Auto-update docs and licenses Signed-off-by: siherrmann <25087590+siherrmann@users.noreply.github.com> * fix: fix dependency error * fix: fix dependecy issue --------- Signed-off-by: siherrmann <25087590+siherrmann@users.noreply.github.com> Co-authored-by: siherrmann <25087590+siherrmann@users.noreply.github.com> Signed-off-by: Maximilian <burr.maximilian97@gmail.com>
Signed-off-by: Maximilian <burr.maximilian97@gmail.com>
Signed-off-by: Maximilian <burr.maximilian97@gmail.com>
Signed-off-by: Maximilian <burr.maximilian97@gmail.com>
Signed-off-by: DerBurri <7892993+DerBurri@users.noreply.github.com> Signed-off-by: Maximilian <burr.maximilian97@gmail.com>
chore(mock): Update MockClient.ListTeams signature test(cli): Update ListTeams mock expectation in list_workspaces_test feat(api): Add ConvertOrgTeamToTeam helper for organization teams refactor(cli): Simplify ListTeamsCmd.RunE to use new ListTeams signature feat(cli): Update Client interface for ListTeams to include orgId feat(cli): Add --org flag and GlobalOptions.OrgId for organization context feat(pkg): Add GetOrgId to Environment for CS_ORG_ID feat(cli): Implement 'cs list org' command to list organizations Signed-off-by: Maximilian <burr.maximilian97@gmail.com>
Signed-off-by: DerBurri <7892993+DerBurri@users.noreply.github.com> Signed-off-by: Maximilian <burr.maximilian97@gmail.com>
added team add and delete opton with org context Signed-off-by: Maximilian <burr.maximilian97@gmail.com>
Signed-off-by: DerBurri <7892993+DerBurri@users.noreply.github.com> Signed-off-by: Maximilian <burr.maximilian97@gmail.com>
…cloud/cs-go into add-organization-api Signed-off-by: Maximilian <burr.maximilian97@gmail.com>
Signed-off-by: Maximilian <burr.maximilian97@gmail.com>
* feat: add first draft cs mcp server * fix: add cs-mcp to gitignore * fix: fix env var names in readme * update: clean up workspace structs * update: add mcp server to the main cs-go cli * update: remove mcp readme, add long mcp cmd description, remove old build related stuff * update: update file name of the main mcp file * chore(docs): Auto-update docs and licenses Signed-off-by: siherrmann <25087590+siherrmann@users.noreply.github.com> * fix: fix dependency error * fix: fix dependecy issue --------- Signed-off-by: siherrmann <25087590+siherrmann@users.noreply.github.com> Co-authored-by: siherrmann <25087590+siherrmann@users.noreply.github.com> Signed-off-by: Maximilian <burr.maximilian97@gmail.com>
Signed-off-by: Maximilian <burr.maximilian97@gmail.com>
Signed-off-by: Maximilian <burr.maximilian97@gmail.com>
Signed-off-by: Maximilian <burr.maximilian97@gmail.com>
Signed-off-by: Maximilian <burr.maximilian97@gmail.com>
Signed-off-by: Maximilian <burr.maximilian97@gmail.com>
Signed-off-by: Maximilian <burr.maximilian97@gmail.com>
Signed-off-by: DerBurri <7892993+DerBurri@users.noreply.github.com> Signed-off-by: Maximilian <burr.maximilian97@gmail.com>
Signed-off-by: Maximilian <burr.maximilian97@gmail.com>
Signed-off-by: Maximilian <burr.maximilian97@gmail.com>
Signed-off-by: Maximilian <burr.maximilian97@gmail.com>
add wrapper for team conversion to allow non hardcoded value of role in the missing field Signed-off-by: Maximilian <burr.maximilian97@gmail.com>
Signed-off-by: DerBurri <7892993+DerBurri@users.noreply.github.com> Signed-off-by: Maximilian <burr.maximilian97@gmail.com>
Signed-off-by: Maximilian <burr.maximilian97@gmail.com>
Signed-off-by: Maximilian <burr.maximilian97@gmail.com>
Signed-off-by: Maximilian <burr.maximilian97@gmail.com>
* chore(ci): Create release on dependency updates * chore(docs): Auto-update docs and licenses Signed-off-by: NautiluX <2600004+NautiluX@users.noreply.github.com> --------- Signed-off-by: NautiluX <2600004+NautiluX@users.noreply.github.com> Co-authored-by: NautiluX <2600004+NautiluX@users.noreply.github.com> Signed-off-by: Maximilian <burr.maximilian97@gmail.com>
…#284) Signed-off-by: Maximilian <burr.maximilian97@gmail.com>
Signed-off-by: Maximilian <burr.maximilian97@gmail.com>
78947e6 to
27dbe5a
Compare
ce8b283 to
8522181
Compare
Signed-off-by: Maximilian <burr.maximilian97@gmail.com>
6f01b45 to
faf3bdf
Compare
Signed-off-by: DerBurri <7892993+DerBurri@users.noreply.github.com>
OliverTrautvetter
left a comment
There was a problem hiding this comment.
Some more comments, but we are moving into the right direction 😄
| func (c *RemoveTeamCmd) RunE(_ *cobra.Command, args []string) error { | ||
| client, err := c.ClientFactory(*c.Opts.GlobalOptions) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to create Codespehre client: %w", err) |
There was a problem hiding this comment.
Still 4 typos where "Codespehre" should be changed to "Codesphere"
| func (client *Client) TeamIdByName(name string) (Team, error) { | ||
| teams, err := client.ListTeams() | ||
| teams, err := client.ListTeams("") |
There was a problem hiding this comment.
The comment here is unresolved, what about this?
| // Returns [NotFound] if no plan with the given Id could be found | ||
| // Returns [Duplicated] if no plan with the given Id could be found |
There was a problem hiding this comment.
"plan" and "no plan" should be "team" and "multiple teams"
| return err | ||
| } | ||
|
|
||
| fmt.Printf("Team created: %+v in Organization: %+v\n", createdTeam.Id, orgId) |
There was a problem hiding this comment.
orgId can be ""
if orgId != "" {
fmt.Printf("Team created: %d in Organization: %s\n", ...)
} else {
fmt.Printf("Team created: %d\n", ...)
}
| return cserrors.FormatAPIError(r, err) | ||
| } | ||
|
|
||
| func (c *Client) AddTeamMember(teamId int, email string, role int) error { |
There was a problem hiding this comment.
should this not have a orgId parameter?
| func (c *AddTeamMemberCmd) RunE(_ *cobra.Command, args []string) error { | ||
| client, err := c.ClientFactory(*c.Opts.GlobalOptions) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to create Codesphere client: %w", err) | ||
| } | ||
|
|
||
| teamId, err := c.Opts.GetTeamId() | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| err = c.AddTeamMember(client, teamId, c.Opts.Email, c.Opts.Role) | ||
| return err | ||
|
|
||
| } |
There was a problem hiding this comment.
Should we not get the orgId?
comment says "To add a member to a team within an organization, the CS_ORG_ID environment variable or the -O/--org flag must be set.`),"
but is never used in AddTeamMember function
| t.cmd.RunE = t.RunE | ||
| t.cmd.Flags().StringVarP(&t.Opts.Email, "email", "e", "", "Team member email") | ||
| _ = t.cmd.MarkFlagRequired("email") | ||
| t.cmd.Flags().IntVarP(&t.Opts.Role, "role", "r", int(cs.RoleAdmin), "Team member role 0=admin, 1=member") |
There was a problem hiding this comment.
I don't think it is good to have 0 as default admin. uninitialized value would give admin rights here, because it is 0
best would be maybe -1 for admin and 1 for member or 1 for member and 2 for admin while 0 is not allowed
| Context("Validation", func() { | ||
| It("should fail if the mail is empty", func() { | ||
|
|
||
| err := c.AddTeamMember(mockClient, teamId, "", dcId) |
There was a problem hiding this comment.
wait why is cdId used as role
| Example: io.FormatExampleCommands("team member add", []io.Example{ | ||
| {Cmd: "-t <teamId> -e user@example.com -r 1", Desc: "Add a user to a team as a member"}, | ||
| {Cmd: "-t <teamId> -e admin@example.com -r 0", Desc: "Add a user to a team as an admin"}, | ||
| {Cmd: "-O <org-id> -t <teamId> -e user@example.com -r 1", Desc: "Add a user to a team within an organization"}, |
There was a problem hiding this comment.
double space bettween -t and
This branch implements org-aware team functionality across the CLI and API client, adds unit tests for team flows, and makes client creation injectable to improve testability. It also includes several refactors and dependency updates required to support the new behavior.
Organization-aware team behavior:
Use GlobalOptions.OrgId and environment GetOrgId() for org-scoped commands.
Add organization filtering to ListTeams and helper conversions for org teams (API + CLI).
Team management commands and tests:
Implement and test AddTeamMember and RemoveTeamMember command logic and validation.
Implement and test team deletion (RemoveTeam) with injectible ClientFactory to mock API calls.
Add/extend unit tests for create/add/remove team flows.
Error handling & observability:
Improve API error logging to include traceId.
Centralize API error formatting via api/errors.FormatAPIError.
Testability & infra:
Make client construction injectable for CLI commands to allow mocks in tests.
Build-and-run integration test workflow updated (artifact + label matrix) — see integration-test.yml.
Chores & deps:
Multiple dependency updates and lint/test chore fixes.
Representative commits
CLI commands: team_create.go, team_add_member.go, team_remove_member.go, team_remove.go
Tests: team_create_test.go, team_add_member_test.go, team_remove_member_test.go, team_remove_test.go
API error handling: errors.go, tests in errors_test.go
CI workflow: integration-test.yml
Client interface and mocks: client.go, mocks.go
Testing / verification
Ran unit tests for the CLI package locally: go test ./cli/cmd — passing.
Integration tests are built and run via the updated GitHub Actions workflow; note that some int tests previously observed backend HTTP 500s during workspace deletion (server-side). If CI shows failures, collect trace IDs and forward to backend logs for investigation.
Migration / usage notes