Skip to content

feat(cli) Add All missing features of the Organizations API#263

Open
DerBurri wants to merge 37 commits into
mainfrom
add-organization-api
Open

feat(cli) Add All missing features of the Organizations API#263
DerBurri wants to merge 37 commits into
mainfrom
add-organization-api

Conversation

@DerBurri

@DerBurri DerBurri commented May 13, 2026

Copy link
Copy Markdown
Contributor

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.

  1. Key points

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

@DerBurri DerBurri force-pushed the add-organization-api branch 2 times, most recently from 2452e6c to 1487f91 Compare May 13, 2026 12:18
@DerBurri DerBurri force-pushed the add-organization-api branch from 044e3a4 to a513836 Compare June 3, 2026 08:20
@DerBurri DerBurri self-assigned this Jun 3, 2026
@DerBurri DerBurri force-pushed the add-organization-api branch from 3ceec3c to a58b8eb Compare June 3, 2026 08:58
@DerBurri DerBurri marked this pull request as ready for review June 3, 2026 09:20
@DerBurri DerBurri requested a review from a team as a code owner June 3, 2026 09:20

@OliverTrautvetter OliverTrautvetter left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice feature, some comments for it 👍

Comment thread pkg/cs/env.go
Comment thread cli/cmd/root.go
Comment thread cli/cmd/team_add_member.go
Comment thread cli/cmd/team_create.go
Comment thread cli/cmd/team_remove.go
Comment thread cli/cmd/team_create.go
Comment thread cli/cmd/team_remove.go Outdated
Comment thread cli/cmd/team_remove.go Outdated
Comment thread cli/cmd/team_remove_member.go
Comment thread cli/cmd/team_remove_member.go Outdated
@DerBurri DerBurri force-pushed the add-organization-api branch from 00c60bf to db693fa Compare June 17, 2026 09:12
CodesphereBot and others added 19 commits June 17, 2026 14:48
)

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>
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>
DerBurri and others added 16 commits June 17, 2026 14:48
…unctions rebased on actual master

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>
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: 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>
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>
…cloud/cs-go into add-organization-api

Signed-off-by: Maximilian <burr.maximilian97@gmail.com>
@DerBurri DerBurri force-pushed the add-organization-api branch from e6cd229 to 3baf63f Compare June 17, 2026 12:48
Signed-off-by: Maximilian <burr.maximilian97@gmail.com>
@DerBurri DerBurri force-pushed the add-organization-api branch from b8b9251 to 66f578e Compare June 17, 2026 12:57

@OliverTrautvetter OliverTrautvetter left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some more comments to improve it

Comment thread api/team.go
Comment on lines +103 to 106
func (c *Client) DeleteTeam(orgId string, teamId int) error {
r, err := c.api.TeamsAPI.TeamsDeleteTeam(c.ctx, float32(teamId)).Execute()
return cserrors.FormatAPIError(r, err)
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

orgId never used, I think we hit the wrong endpoint here without the orgId

Comment thread cli/cmd/team_create.go
Use: "create",
Short: "Create team",
Long: `Create a team in Codesphere or an Organization`,
Example: io.FormatExampleCommands("team member add", []io.Example{

@OliverTrautvetter OliverTrautvetter Jun 18, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be team member create. Example is for team member add

Short: "Remove team member",
Long: io.Long(`Remove team member from a team.

To add a member to a team within an organization, the CS_ORG_ID environment variable or the -O/--org flag must be set.`),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be remove member

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 Codespehre client: %w", err)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo Codesphere


err := c.RunE(nil, []string{})
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("failed to create Codespehre client: client init failed"))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo

return errors.New("invalid role: must be 0 for admin or 1 for member")
}

fmt.Printf("add member: %s to team %d with role: %d", email, teamId, role)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be log.Printf / or remove if this was for debugging

Comment thread cli/cmd/team_create.go
Comment on lines +55 to +57
if err != nil {
return errors.Join(err, errors.New("failed to get organization ID"))
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if orgId is "" there is no error. But we still failed to get the org id right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its intended to have no error, because it then uses an different endpoint.
like orgless Teams

Comment thread api/types.go
AvatarUrl: *openapi.NewNullableString(t.AvatarUrl),
IsFirst: t.IsFirst,
OrganizationId: &orgId,
Role: 0, // Default to admin role if not specified by org API

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hardcoded, all team members are admins

Comment thread api/team.go
}

func (c *Client) GetTeam(teamId int) (*Team, error) {
team, r, err := c.api.TeamsAPI.TeamsGetTeam(c.ctx, float32(teamId)).Execute()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should check if team is nil

Comment thread cli/cmd/team_create.go
ClientFactory: NewClient,
}
t.cmd.RunE = t.RunE
t.cmd.Flags().StringVarP(&t.Opts.Name, "name", "n", "", "Team name")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

team name flag should be a required flag

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants