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
2019func 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.
2631func 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.
155167func 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