Skip to content

Commit

Permalink
Merge branch 'version/0-42-0-RC1' into DX-2225
Browse files Browse the repository at this point in the history
  • Loading branch information
MDrakos committed Nov 2, 2023
2 parents 5126fcd + da528fd commit 3292649
Show file tree
Hide file tree
Showing 38 changed files with 252 additions and 227 deletions.
6 changes: 3 additions & 3 deletions cmd/state-svc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,12 @@ func runForeground(cfg *config.Instance, an *anaSync.Client, auth *authenticatio
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

logFile := logging.FilePath()
logging.Debug("Logging to %q", logFile)
logFileName := logging.FileName()
logging.Debug("Logging to %q", logging.FilePathFor(logFileName))
stopTimer := logging.StartRotateLogTimer()
defer stopTimer()

p := NewService(ctx, cfg, an, auth, logFile)
p := NewService(ctx, cfg, an, auth, logFileName)

if argText != "" {
argText = fmt.Sprintf(" (invoked by %q)", argText)
Expand Down
2 changes: 1 addition & 1 deletion cmd/state/internal/cmdtree/cmdtree.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ func New(prime *primer.Values, args ...string) *CmdTree {
refreshCmd,
newSwitchCommand(prime),
newTestCommand(prime),
newCommitCommand(prime),
//newCommitCommand(prime), // re-enable in DX-2307
)

return &CmdTree{
Expand Down
4 changes: 0 additions & 4 deletions internal/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,10 +312,6 @@ const ActiveStateSupportURL = "https://www.activestate.com/support/?utm_source=p
// ActiveStateDashboardURL is the URL for the ActiveState account preferences page
const ActiveStateDashboardURL = "https://platform.activestate.com/?utm_source=platform-application-gui&utm_medium=activestate-desktop&utm_content=drop-down&utm_campaign=maru"

// DashboardCommitURL is the URL used to inspect commits
// TODO: Can this be removed?
const DashboardCommitURL = "https://platform.activestate.com/commit/"

// BugTrackerURL is the URL of our bug tracker
const BugTrackerURL = "https://github.com/ActiveState/state-tool/issues"

Expand Down
3 changes: 2 additions & 1 deletion internal/constraints/constraints.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ type projectable interface {
Path() string
Dir() string
URL() string
LegacyCommitID() string // for commitmediator.Get
LegacyCommitID() string // for commitmediator.Get
LegacySetCommit(string) error // for commitmediator.Set; remove in DX-2307
}

func NewPrimeConditional(auth *authentication.Auth, pj projectable, subshellName string) *Conditional {
Expand Down
35 changes: 20 additions & 15 deletions internal/runbits/commitmediator/commitmediator.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package commitmediator

import (
"github.com/ActiveState/cli/internal/errs"
"github.com/ActiveState/cli/internal/runbits/legacy/projectmigration"
"github.com/ActiveState/cli/pkg/localcommit"
"github.com/go-openapi/strfmt"
)

Expand All @@ -12,22 +9,30 @@ type projecter interface {
URL() string
Path() string
LegacyCommitID() string
LegacySetCommit(string) error // remove this in DX-2307
}

// Get returns the given project's commit ID in either the new format (commit file), or the old
// format (activestate.yaml).
// If you require the commit file, use localcommit.Get().
func Get(proj projecter) (strfmt.UUID, error) {
if commitID, err := localcommit.Get(proj.Dir()); err == nil {
return commitID, nil
} else if localcommit.IsFileDoesNotExistError(err) {
if migrated, err := projectmigration.PromptAndMigrate(proj); err == nil && migrated {
return localcommit.Get(proj.Dir())
} else if err != nil {
return "", errs.Wrap(err, "Could not prompt and/or migrate project")
}
return strfmt.UUID(proj.LegacyCommitID()), nil
} else {
return "", errs.Wrap(err, "Could not get local commit")
}
// Re-enable the contents of this function in DX-2307
//if commitID, err := localcommit.Get(proj.Dir()); err == nil {
// return commitID, nil
//} else if localcommit.IsFileDoesNotExistError(err) {
//if migrated, err := projectmigration.PromptAndMigrate(proj); err == nil && migrated {
// return localcommit.Get(proj.Dir())
//} else if err != nil {
// return "", errs.Wrap(err, "Could not prompt and/or migrate project")
//}
return strfmt.UUID(proj.LegacyCommitID()), nil
//} else {
// return "", errs.Wrap(err, "Could not get local commit")
//}
}

func Set(proj projecter, commitID string) error {
// Replace all calls to this function with localcommit.Set() in DX-2307.
// Also, consider changing localcommit.Set() to accept a projecter interface with Dir().
return proj.LegacySetCommit(commitID)
}
2 changes: 0 additions & 2 deletions internal/runbits/rationalize/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ var ErrNotAuthenticated = errors.New("not authenticated")

var ErrActionAborted = errors.New("aborted by user")

var ErrHeadless = errors.New("headless")

type ErrAPI struct {
Wrapped error
Code int
Expand Down
10 changes: 5 additions & 5 deletions internal/runbits/refresh.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"github.com/ActiveState/cli/internal/locale"
"github.com/ActiveState/cli/internal/output"
"github.com/ActiveState/cli/internal/rtutils"
"github.com/ActiveState/cli/internal/runbits/buildscript"
"github.com/ActiveState/cli/pkg/platform/authentication"
"github.com/ActiveState/cli/pkg/platform/model"
"github.com/ActiveState/cli/pkg/platform/runtime"
Expand All @@ -25,10 +24,11 @@ func RefreshRuntime(
trigger target.Trigger,
svcm *model.SvcModel,
) (rerr error) {
_, err := buildscript.Sync(proj, &commitID, out, auth)
if err != nil {
return locale.WrapError(err, "err_update_build_script")
}
// Re-enable in DX-2307.
//_, err := buildscript.Sync(proj, &commitID, out, auth)
//if err != nil {
// return locale.WrapError(err, "err_update_build_script")
//}
target := target.NewProjectTarget(proj, nil, trigger)
isCached := true
rt, err := runtime.New(target, an, svcm, auth)
Expand Down
34 changes: 18 additions & 16 deletions internal/runbits/requirements/requirements.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ import (
"github.com/ActiveState/cli/internal/prompt"
"github.com/ActiveState/cli/internal/rtutils/ptr"
"github.com/ActiveState/cli/internal/runbits"
"github.com/ActiveState/cli/pkg/localcommit"
"github.com/ActiveState/cli/internal/runbits/commitmediator"
"github.com/ActiveState/cli/internal/runbits/rationalize"
bpModel "github.com/ActiveState/cli/pkg/platform/api/buildplanner/model"
medmodel "github.com/ActiveState/cli/pkg/platform/api/mediator/model"
"github.com/ActiveState/cli/pkg/platform/authentication"
"github.com/ActiveState/cli/pkg/platform/model"
"github.com/ActiveState/cli/pkg/platform/runtime/buildscript"
"github.com/ActiveState/cli/pkg/platform/runtime/target"
"github.com/ActiveState/cli/pkg/project"
"github.com/thoas/go-funk"
Expand Down Expand Up @@ -101,14 +101,14 @@ func (r *RequirementOperation) ExecuteRequirementOperation(requirementName, requ

var err error
if r.Project == nil {
return locale.NewInputError("err_no_project", "No project found")
return rationalize.ErrNoProject
}
out.Notice(locale.Tl("operating_message", "", r.Project.NamespaceString(), r.Project.Dir()))

switch nsType {
case model.NamespacePackage, model.NamespaceBundle:
commitID, err := localcommit.Get(r.Project.Dir())
if err != nil && !localcommit.IsFileDoesNotExistError(err) {
commitID, err := commitmediator.Get(r.Project)
if err != nil {
return errs.Wrap(err, "Unable to get local commit")
}

Expand Down Expand Up @@ -189,8 +189,8 @@ func (r *RequirementOperation) ExecuteRequirementOperation(requirementName, requ
pg = nil
}

parentCommitID, err := localcommit.Get(r.Project.Dir())
if err != nil && !localcommit.IsFileDoesNotExistError(err) {
parentCommitID, err := commitmediator.Get(r.Project)
if err != nil {
return errs.Wrap(err, "Unable to get local commit")
}
hasParentCommit := parentCommitID != ""
Expand Down Expand Up @@ -268,20 +268,22 @@ func (r *RequirementOperation) ExecuteRequirementOperation(requirementName, requ
return errs.Wrap(err, "Unsupported namespace type: %s", ns.Type().String())
}

expr, err := bp.GetBuildExpression(r.Project.Owner(), r.Project.Name(), commitID.String())
if err != nil {
return errs.Wrap(err, "Could not get remote build expr")
}
// Re-enable in DX-2307.
//expr, err := bp.GetBuildExpression(r.Project.Owner(), r.Project.Name(), commitID.String())
//if err != nil {
// return errs.Wrap(err, "Could not get remote build expr")
//}

if err := localcommit.Set(r.Project.Dir(), commitID.String()); err != nil {
if err := commitmediator.Set(r.Project, commitID.String()); err != nil {
return locale.WrapError(err, "err_package_update_commit_id")
}

// Note: a commit ID file needs to exist at this point.
err = buildscript.Update(r.Project, expr, r.Auth)
if err != nil {
return locale.WrapError(err, "err_update_build_script")
}
// Re-enable in DX-2307.
//err = buildscript.Update(r.Project, expr, r.Auth)
//if err != nil {
// return locale.WrapError(err, "err_update_build_script")
//}

// refresh or install runtime
err = runbits.RefreshRuntime(r.Auth, r.Output, r.Analytics, r.Project, commitID, true, trigger, r.SvcModel)
Expand Down
29 changes: 1 addition & 28 deletions internal/runners/auth/auth.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package auth

import (
"github.com/ActiveState/cli/internal/errs"
"github.com/ActiveState/cli/internal/keypairs"
"github.com/ActiveState/cli/internal/locale"
"github.com/ActiveState/cli/internal/output"
"github.com/ActiveState/cli/internal/primer"
"github.com/ActiveState/cli/internal/prompt"
authlet "github.com/ActiveState/cli/pkg/cmdlets/auth"
"github.com/ActiveState/cli/pkg/platform/authentication"
"github.com/ActiveState/cli/pkg/platform/model"
)

type Auth struct {
Expand Down Expand Up @@ -72,37 +70,12 @@ func (a *Auth) Run(params *AuthParams) error {
}

username := a.Auth.WhoAmI()
organization, err := model.FetchOrgByURLName(username, a.Auth)
if err != nil {
return errs.Wrap(err, "Could not fetch organizations")
}

tiers, err := model.FetchTiers()
if err != nil {
return errs.Wrap(err, "Could not fetch tiers")
}

tier := organization.Tier
privateProjects := false
for _, t := range tiers {
if tier == t.Name && t.RequiresPayment {
privateProjects = true
break
}
}

a.Outputer.Print(output.Prepare(
locale.T("logged_in_as", map[string]string{"Name": username}),
&struct {
Username string `json:"username,omitempty"`
URLName string `json:"urlname,omitempty"`
Tier string `json:"tier,omitempty"`
PrivateProjects bool `json:"privateProjects"`
Username string `json:"username"`
}{
username,
organization.URLname,
tier,
privateProjects,
},
))

Expand Down
4 changes: 2 additions & 2 deletions internal/runners/branch/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"github.com/ActiveState/cli/internal/locale"
"github.com/ActiveState/cli/internal/logging"
"github.com/ActiveState/cli/internal/output"
"github.com/ActiveState/cli/pkg/localcommit"
"github.com/ActiveState/cli/internal/runbits/commitmediator"
"github.com/ActiveState/cli/pkg/platform/model"
"github.com/ActiveState/cli/pkg/project"
)
Expand Down Expand Up @@ -49,7 +49,7 @@ func (a *Add) Run(params AddParams) error {
return locale.WrapError(err, "err_fetch_branch", "", localBranch)
}

commitID, err := localcommit.Get(a.project.Dir())
commitID, err := commitmediator.Get(a.project)
if err != nil {
return errs.Wrap(err, "Unable to get local commit")
}
Expand Down
27 changes: 14 additions & 13 deletions internal/runners/initialize/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"github.com/ActiveState/cli/internal/primer"
"github.com/ActiveState/cli/internal/runbits"
"github.com/ActiveState/cli/internal/runbits/commitmediator"
"github.com/ActiveState/cli/pkg/localcommit"
"github.com/ActiveState/cli/pkg/platform/authentication"
"github.com/ActiveState/cli/pkg/platform/model"
"github.com/ActiveState/cli/pkg/platform/runtime/setup"
Expand Down Expand Up @@ -157,10 +156,11 @@ func (r *Initialize) Run(params *RunParams) (rerr error) {
}
}

emptyDir, err := fileutils.IsEmptyDir(path)
if err != nil {
multilog.Error("Unable to check if directory is empty: %v", err)
}
// Re-enable in DX-2307.
//emptyDir, err := fileutils.IsEmptyDir(path)
//if err != nil {
// multilog.Error("Unable to check if directory is empty: %v", err)
//}

// Match the case of the organization.
// Otherwise the incorrect case will be written to the project file.
Expand Down Expand Up @@ -247,16 +247,17 @@ func (r *Initialize) Run(params *RunParams) (rerr error) {
return locale.WrapError(err, "err_init_commit", "Could not create initial commit")
}

if err := localcommit.Set(proj.Dir(), commitID.String()); err != nil {
if err := commitmediator.Set(proj, commitID.String()); err != nil {
return errs.Wrap(err, "Unable to create local commit file")
}
if emptyDir || fileutils.DirExists(filepath.Join(path, ".git")) {
err := localcommit.AddToGitIgnore(path)
if err != nil {
r.out.Notice(locale.Tr("notice_commit_id_gitignore", constants.ProjectConfigDirName, constants.CommitIdFileName))
multilog.Error("Unable to add local commit file to .gitignore: %v", err)
}
}
// Re-enable in DX-2307.
//if emptyDir || fileutils.DirExists(filepath.Join(path, ".git")) {
// err := localcommit.AddToGitIgnore(path)
// if err != nil {
// r.out.Notice(locale.Tr("notice_commit_id_gitignore", constants.ProjectConfigDirName, constants.CommitIdFileName))
// multilog.Error("Unable to add local commit file to .gitignore: %v", err)
// }
//}

err = runbits.RefreshRuntime(r.auth, r.out, r.analytics, proj, commitID, true, target.TriggerInit, r.svcModel)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions internal/runners/packages/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/ActiveState/cli/internal/primer"
"github.com/ActiveState/cli/internal/prompt"
"github.com/ActiveState/cli/internal/runbits"
"github.com/ActiveState/cli/pkg/localcommit"
"github.com/ActiveState/cli/internal/runbits/commitmediator"
"github.com/ActiveState/cli/pkg/platform/api"
gqlModel "github.com/ActiveState/cli/pkg/platform/api/graphql/model"
"github.com/ActiveState/cli/pkg/platform/api/reqsimport"
Expand Down Expand Up @@ -177,7 +177,7 @@ func fetchImportChangeset(cp ChangesetProvider, file string, lang string) (model
}

func commitChangeset(project *project.Project, msg string, changeset model.Changeset) (strfmt.UUID, error) {
localCommitID, err := localcommit.Get(project.Dir())
localCommitID, err := commitmediator.Get(project)
if err != nil {
return "", errs.Wrap(err, "Unable to get local commit")
}
Expand All @@ -188,7 +188,7 @@ func commitChangeset(project *project.Project, msg string, changeset model.Chang
locale.T("commit_failed_pull_tip"))
}

if err := localcommit.Set(project.Dir(), commitID.String()); err != nil {
if err := commitmediator.Set(project, commitID.String()); err != nil {
return "", locale.WrapError(err, "err_package_update_commit_id")
}
return commitID, nil
Expand Down
Loading

0 comments on commit 3292649

Please sign in to comment.