Skip to content

Commit bcea121

Browse files
authored
Use org id from get application instead of the stored token (#78)
1 parent 8280004 commit bcea121

2 files changed

Lines changed: 23 additions & 23 deletions

File tree

cmd/app/deploy.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"github.com/charmbracelet/huh"
1111
"github.com/charmbracelet/lipgloss"
1212
"github.com/major-technology/cli/clients/git"
13-
"github.com/major-technology/cli/clients/token"
1413
"github.com/major-technology/cli/errors"
1514
"github.com/major-technology/cli/singletons"
1615
"github.com/spf13/cobra"
@@ -32,8 +31,8 @@ func runDeploy(cobraCmd *cobra.Command) error {
3231
return errors.ErrorNotInGitRepository
3332
}
3433

35-
// Get application ID
36-
applicationID, err := getApplicationID()
34+
// Get application ID and organization ID
35+
applicationID, organizationID, err := getApplicationAndOrgID()
3736
if err != nil {
3837
return errors.WrapError("failed to get application ID", err)
3938
}
@@ -89,12 +88,6 @@ func runDeploy(cobraCmd *cobra.Command) error {
8988
cobraCmd.Println("✓ No uncommitted changes")
9089
}
9190

92-
// Get organization ID
93-
organizationID, _, err := token.GetDefaultOrg()
94-
if err != nil {
95-
return errors.WrapError("failed to get default organization", errors.ErrorNoOrganizationSelected)
96-
}
97-
9891
// Call API to create new version
9992
apiClient := singletons.GetAPIClient()
10093
resp, err := apiClient.CreateApplicationVersion(applicationID)

cmd/app/helper.go

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"time"
1010

1111
"github.com/major-technology/cli/clients/git"
12-
mjrToken "github.com/major-technology/cli/clients/token"
1312
"github.com/major-technology/cli/errors"
1413
"github.com/major-technology/cli/singletons"
1514
"github.com/major-technology/cli/utils"
@@ -18,41 +17,54 @@ import (
1817

1918
// getApplicationID retrieves the application ID for the current git repository
2019
func getApplicationID() (string, error) {
21-
return getApplicationIDFromDir("")
20+
appID, _, err := getApplicationAndOrgIDFromDir("")
21+
return appID, err
22+
}
23+
24+
// getApplicationAndOrgID retrieves the application ID and organization ID for the current git repository
25+
func getApplicationAndOrgID() (string, string, error) {
26+
return getApplicationAndOrgIDFromDir("")
2227
}
2328

2429
// getApplicationIDFromDir retrieves the application ID for a git repository in the specified directory.
2530
// If dir is empty, it uses the current directory.
2631
func getApplicationIDFromDir(dir string) (string, error) {
32+
appID, _, err := getApplicationAndOrgIDFromDir(dir)
33+
return appID, err
34+
}
35+
36+
// getApplicationAndOrgIDFromDir retrieves the application ID and organization ID for a git repository in the specified directory.
37+
// If dir is empty, it uses the current directory.
38+
func getApplicationAndOrgIDFromDir(dir string) (string, string, error) {
2739
// Get the git remote URL from the specified directory
2840
remoteURL, err := git.GetRemoteURLFromDir(dir)
2941
if err != nil {
30-
return "", err
42+
return "", "", err
3143
}
3244

3345
if remoteURL == "" {
34-
return "", fmt.Errorf("no git remote found in directory")
46+
return "", "", fmt.Errorf("no git remote found in directory")
3547
}
3648

3749
// Parse the remote URL to extract owner and repo
3850
remoteInfo, err := git.ParseRemoteURL(remoteURL)
3951
if err != nil {
40-
return "", errors.WrapError("failed to parse git remote URL", err)
52+
return "", "", errors.WrapError("failed to parse git remote URL", err)
4153
}
4254

4355
// Get API client
4456
apiClient := singletons.GetAPIClient()
4557
if apiClient == nil {
46-
return "", fmt.Errorf("API client not initialized")
58+
return "", "", fmt.Errorf("API client not initialized")
4759
}
4860

4961
// Get application by repository
5062
appResp, err := apiClient.GetApplicationByRepo(remoteInfo.Owner, remoteInfo.Repo)
5163
if err != nil {
52-
return "", errors.WrapError("failed to get application", err)
64+
return "", "", errors.WrapError("failed to get application", err)
5365
}
5466

55-
return appResp.ApplicationID, nil
67+
return appResp.ApplicationID, appResp.OrganizationID, nil
5668
}
5769

5870
// cloneRepository clones a repository using SSH or HTTPS based on availability
@@ -153,12 +165,7 @@ func pullOrCloneWithRetries(cmd *cobra.Command, workingDir, sshURL, httpsURL str
153165
// If targetDir is empty, it uses the current git repository root.
154166
// Returns the path to the generated file and the number of variables written.
155167
func generateEnvFile(targetDir string) (string, int, error) {
156-
orgID, _, err := mjrToken.GetDefaultOrg()
157-
if err != nil {
158-
return "", 0, errors.WrapError("failed to get default organization", errors.ErrorNoOrganizationSelected)
159-
}
160-
161-
applicationID, err := getApplicationIDFromDir(targetDir)
168+
applicationID, orgID, err := getApplicationAndOrgIDFromDir(targetDir)
162169
if err != nil {
163170
return "", 0, errors.WrapError("failed to get application ID", err)
164171
}

0 commit comments

Comments
 (0)