diff --git a/internal/runners/fork/fork.go b/internal/runners/fork/fork.go index 15fbbcc914..955528f4c1 100644 --- a/internal/runners/fork/fork.go +++ b/internal/runners/fork/fork.go @@ -1,12 +1,12 @@ package fork import ( - "github.com/ActiveState/cli/internal/constants" "github.com/ActiveState/cli/internal/errs" "github.com/ActiveState/cli/internal/locale" "github.com/ActiveState/cli/internal/output" "github.com/ActiveState/cli/internal/primer" "github.com/ActiveState/cli/internal/prompt" + "github.com/ActiveState/cli/pkg/platform/api" "github.com/ActiveState/cli/pkg/platform/authentication" "github.com/ActiveState/cli/pkg/platform/model" "github.com/ActiveState/cli/pkg/project" @@ -61,7 +61,9 @@ func (f *Fork) Run(params *Params) error { target.Project = params.Namespace.Project } - f.out.Notice(locale.Tl("fork_forking", "Creating fork of {{.V0}} at https://{{.V1}}/{{.V2}}..", params.Namespace.String(), constants.PlatformURL, target.String())) + url := api.GetPlatformURL(target.String()).String() + + f.out.Notice(locale.Tl("fork_forking", "Creating fork of {{.V0}} at {{.V1}}...", params.Namespace.String(), url)) _, err := model.CreateCopy(params.Namespace.Owner, params.Namespace.Project, target.Owner, target.Project, params.Private) if err != nil { @@ -69,7 +71,7 @@ func (f *Fork) Run(params *Params) error { } f.out.Print(output.Prepare( - locale.Tl("fork_success", "Your fork has been successfully created at https://{{.V0}}/{{.V1}}.", constants.PlatformURL, target.String()), + locale.Tl("fork_success", "Your fork has been successfully created at {{.V0}}.", url), &struct { OriginalOwner string `json:"OriginalOwner"` OriginalName string `json:"OriginalName"` diff --git a/pkg/platform/model/projects.go b/pkg/platform/model/projects.go index e3cc24da17..bc3ac5641a 100644 --- a/pkg/platform/model/projects.go +++ b/pkg/platform/model/projects.go @@ -10,7 +10,6 @@ import ( "github.com/ActiveState/cli/pkg/platform/api/graphql/model" "github.com/ActiveState/cli/pkg/platform/api/graphql/request" - "github.com/ActiveState/cli/internal/constants" "github.com/ActiveState/cli/internal/locale" "github.com/ActiveState/cli/internal/logging" "github.com/ActiveState/cli/pkg/platform/api" @@ -225,8 +224,8 @@ func CreateCopy(sourceOwner, sourceName, targetOwner, targetName string, makePri if _, err := authentication.Client().Projects.DeleteProject(deleteParams, authentication.ClientAuth()); err != nil { return nil, locale.WrapError( err, "err_fork_private_but_project_created", - "Your project was created but could not be made private, please head over to https://{{.V0}}/{{.V1}}/{{.V2}} to manually update your privacy settings.", - constants.PlatformURL, targetOwner, targetName) + "Your project was created but could not be made private, please head over to {{.V0}} to manually update your privacy settings.", + api.GetPlatformURL(fmt.Sprintf("%s/%s", targetOwner, targetName)).String()) } return nil, locale.WrapError(err, "err_fork_private", "Your fork could not be made private.") } @@ -256,11 +255,13 @@ func MakeProjectPrivate(owner, name string) error { // ProjectURL creates a valid platform URL for the given project parameters func ProjectURL(owner, name, commitID string) string { - url := fmt.Sprintf("https://%s/%s/%s", constants.PlatformURL, owner, name) + url := api.GetPlatformURL(fmt.Sprintf("%s/%s", owner, name)) if commitID != "" { - url = url + "?commitID=" + commitID + query := url.Query() + query.Add("commitID", commitID) + url.RawQuery = query.Encode() } - return url + return url.String() } func AddBranch(projectID strfmt.UUID, label string) (strfmt.UUID, error) { diff --git a/pkg/projectfile/projectfile.go b/pkg/projectfile/projectfile.go index 48e4fd323c..223d2af4bb 100644 --- a/pkg/projectfile/projectfile.go +++ b/pkg/projectfile/projectfile.go @@ -953,7 +953,12 @@ func createCustom(params *CreateParams, lang language.Language) (*Project, error } if params.ProjectURL == "" { - u, err := url.Parse(fmt.Sprintf("https://%s/%s/%s", constants.PlatformURL, params.Owner, params.Project)) + // Note: cannot use api.GetPlatformURL() due to import cycle. + host := constants.DefaultAPIHost + if hostOverride := os.Getenv(constants.APIHostEnvVarName); hostOverride != "" { + host = hostOverride + } + u, err := url.Parse(fmt.Sprintf("https://%s/%s/%s", host, params.Owner, params.Project)) if err != nil { return nil, errs.Wrap(err, "url parse new project url failed") }