Skip to content

Commit

Permalink
Merge branch version/0-43-0-RC1 to adopt changes from PR #2926
Browse files Browse the repository at this point in the history
  • Loading branch information
as-builds committed Dec 6, 2023
2 parents ec2a91a + 66c66c5 commit d5b81ea
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
8 changes: 5 additions & 3 deletions internal/runners/fork/fork.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -61,15 +61,17 @@ 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 {
return locale.WrapError(err, "err_fork_project", "Could not create fork")
}

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"`
Expand Down
13 changes: 7 additions & 6 deletions pkg/platform/model/projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.")
}
Expand Down Expand Up @@ -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) {
Expand Down
7 changes: 6 additions & 1 deletion pkg/projectfile/projectfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down

0 comments on commit d5b81ea

Please sign in to comment.