-
Notifications
You must be signed in to change notification settings - Fork 23
feat(init): list sub-orgs with counts in org picker (ENG-4673) #157
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
Open
IgorHorta
wants to merge
2
commits into
main
Choose a base branch
from
igor/eng-4673-cli-init-should-list-suborgs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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
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 |
|---|---|---|
|
|
@@ -8,20 +8,44 @@ import ( | |
| "github.com/Infisical/infisical-merge/packages/models" | ||
| ) | ||
|
|
||
| func GetOrganizationsNameList(organizationResponse api.GetOrganizationsResponse) []string { | ||
| organizations := organizationResponse.Organizations | ||
| // OrgPickerItem holds the org ID to pass to CallSelectOrganization. | ||
| type OrgPickerItem struct { | ||
| ID string | ||
| } | ||
|
|
||
| if len(organizations) == 0 { | ||
| message := fmt.Sprintf("You don't have any organization created in Infisical. You must first create a organization at %s", config.INFISICAL_URL) | ||
| PrintErrorMessageAndExit(message) | ||
| // BuildOrgRootLabels returns first-prompt labels: org name with sub-org count when present. | ||
| // orgs is the flat list from GET /v1/organization; subOrgMap is keyed by org ID. | ||
| func BuildOrgRootLabels(orgs []api.Organization, subOrgMap map[string][]api.SubOrganization) []string { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: With go static type - we already know it's a map - i don't think we need to say it again as |
||
| labels := make([]string, len(orgs)) | ||
| for i, org := range orgs { | ||
| n := len(subOrgMap[org.ID]) | ||
| switch n { | ||
| case 0: | ||
| labels[i] = org.Name | ||
| case 1: | ||
| labels[i] = fmt.Sprintf("%s (1 sub-org)", org.Name) | ||
| default: | ||
| labels[i] = fmt.Sprintf("%s (%d sub-orgs)", org.Name, n) | ||
| } | ||
| } | ||
| return labels | ||
| } | ||
|
|
||
| var organizationNames []string | ||
| for _, workspace := range organizations { | ||
| organizationNames = append(organizationNames, workspace.Name) | ||
| } | ||
| // BuildSubOrgPickerItems returns items + labels for the second prompt. | ||
| // The first item is always the root org itself, followed by each sub-org. | ||
| func BuildSubOrgPickerItems(rootID, rootName string, subs []api.SubOrganization) ([]OrgPickerItem, []string) { | ||
| items := make([]OrgPickerItem, 0, 1+len(subs)) | ||
| labels := make([]string, 0, 1+len(subs)) | ||
|
|
||
| rootLabel := fmt.Sprintf("%s (organization)", rootName) | ||
| items = append(items, OrgPickerItem{ID: rootID}) | ||
| labels = append(labels, rootLabel) | ||
|
|
||
| return organizationNames | ||
| for _, sub := range subs { | ||
| items = append(items, OrgPickerItem{ID: sub.ID}) | ||
| labels = append(labels, sub.Name) | ||
| } | ||
IgorHorta marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return items, labels | ||
| } | ||
|
|
||
| func GetWorkspacesInOrganization(workspaceResponse api.GetWorkSpacesResponse, orgId string) ([]models.Workspace, []string) { | ||
|
|
||
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 |
|---|---|---|
|
|
@@ -27,11 +27,14 @@ func UserInitCmd() { | |
| n, err := ptmx.Read(buf) | ||
| if n > 0 { | ||
| terminalOut := string(buf) | ||
| if strings.Contains(terminalOut, "Which Infisical organization would you like to select a project from?") && step < 0 { | ||
| if strings.Contains(terminalOut, "Which Infisical organization would you like to select a project from?") && step < 0 { | ||
| step += 1 | ||
| stepChan <- step | ||
| } else if strings.Contains(terminalOut, "Which of your Infisical projects would you like to connect this project to?") && step < 1 { | ||
| step += 1; | ||
| } else if strings.Contains(terminalOut, "Which scope within") && step < 1 { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the meaning of |
||
| step += 1 | ||
| stepChan <- step | ||
| } else if strings.Contains(terminalOut, "Which of your Infisical projects would you like to connect this project to?") && step < 2 { | ||
| step += 1 | ||
| stepChan <- step | ||
| } | ||
| } | ||
|
|
@@ -44,10 +47,12 @@ func UserInitCmd() { | |
|
|
||
| for i := range stepChan { | ||
| switch i { | ||
| case 0: | ||
| case 0: | ||
| ptmx.Write([]byte("\n")) | ||
| case 1: | ||
| ptmx.Write([]byte("\n")) | ||
| case 2: | ||
| ptmx.Write([]byte("\n")) | ||
| } | ||
| } | ||
| } | ||
|
|
||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be also when a resource not found as well right? I think Route not found has an explicit message