Skip to content

Commit

Permalink
Replace localcommit with new primed checkoutinfo package.
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchell-as committed Sep 26, 2024
1 parent 59bbc83 commit 9ba0b39
Show file tree
Hide file tree
Showing 57 changed files with 311 additions and 213 deletions.
4 changes: 2 additions & 2 deletions internal/captain/rationalize.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import (
"github.com/ActiveState/cli/internal/locale"
"github.com/ActiveState/cli/internal/runbits/rationalize"
"github.com/ActiveState/cli/pkg/buildscript"
"github.com/ActiveState/cli/pkg/localcommit"
"github.com/ActiveState/cli/pkg/checkoutinfo"
)

func rationalizeError(err *error) {
var errInvalidCommitID *localcommit.ErrInvalidCommitID
var errInvalidCommitID *checkoutinfo.ErrInvalidCommitID

switch {
case err == nil:
Expand Down
1 change: 1 addition & 0 deletions internal/events/cmdcall/cmdcall.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type primeable interface {
primer.Configurer
primer.Analyticer
primer.SvcModeler
primer.CheckoutInfoer
}

// CmdCall manages dependencies for the handling of events triggered by command
Expand Down
4 changes: 3 additions & 1 deletion internal/migrator/migrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/ActiveState/cli/internal/locale"
"github.com/ActiveState/cli/internal/logging"
"github.com/ActiveState/cli/internal/runbits/buildscript"
"github.com/ActiveState/cli/pkg/checkoutinfo"
"github.com/ActiveState/cli/pkg/platform/authentication"
"github.com/ActiveState/cli/pkg/platform/model"
"github.com/ActiveState/cli/pkg/projectfile"
Expand All @@ -29,7 +30,8 @@ func NewMigrator(auth *authentication.Auth, cfg *config.Instance, svcm *model.Sv
case 0:
if cfg.GetBool(constants.OptinBuildscriptsConfig) {
logging.Debug("Creating buildscript")
if err := buildscript_runbit.Initialize(filepath.Dir(project.Path()), auth, svcm); err != nil {
info := checkoutinfo.New(project)
if err := buildscript_runbit.Initialize(filepath.Dir(project.Path()), auth, svcm, info); err != nil {
return v, errs.Wrap(err, "Failed to initialize buildscript")
}
}
Expand Down
34 changes: 23 additions & 11 deletions internal/primer/primer.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,26 @@ import (
"github.com/ActiveState/cli/internal/prompt"
"github.com/ActiveState/cli/internal/subshell"
"github.com/ActiveState/cli/internal/svcctl"
"github.com/ActiveState/cli/pkg/checkoutinfo"
"github.com/ActiveState/cli/pkg/platform/authentication"
"github.com/ActiveState/cli/pkg/platform/model"
"github.com/ActiveState/cli/pkg/project"
"github.com/ActiveState/cli/pkg/projectfile"
)

type Values struct {
project *project.Project
projectfile *projectfile.Project
output output.Outputer
auth *authentication.Auth
prompt prompt.Prompter
subshell subshell.SubShell
conditional *constraints.Conditional
config *config.Instance
ipComm svcctl.IPCommunicator
svcModel *model.SvcModel
analytics analytics.Dispatcher
project *project.Project
projectfile *projectfile.Project
output output.Outputer
auth *authentication.Auth
prompt prompt.Prompter
subshell subshell.SubShell
conditional *constraints.Conditional
config *config.Instance
ipComm svcctl.IPCommunicator
svcModel *model.SvcModel
analytics analytics.Dispatcher
checkoutinfo *checkoutinfo.CheckoutInfo
}

func New(values ...any) *Values {
Expand Down Expand Up @@ -65,12 +67,14 @@ func New(values ...any) *Values {
}
}
}
result.checkoutinfo = checkoutinfo.New(result.projectfile)
return result
}

func (v *Values) SetProject(p *project.Project) {
v.project = p
v.projectfile = p.Source()
v.checkoutinfo = checkoutinfo.New(v.projectfile)
}

type Projecter interface {
Expand Down Expand Up @@ -118,6 +122,10 @@ type Conditioner interface {
Conditional() *constraints.Conditional
}

type CheckoutInfoer interface {
CheckoutInfo() *checkoutinfo.CheckoutInfo
}

func (v *Values) Project() *project.Project {
return v.project
}
Expand Down Expand Up @@ -161,3 +169,7 @@ func (v *Values) Config() *config.Instance {
func (v *Values) Analytics() analytics.Dispatcher {
return v.analytics
}

func (v *Values) CheckoutInfo() *checkoutinfo.CheckoutInfo {
return v.checkoutinfo
}
11 changes: 6 additions & 5 deletions internal/runbits/buildplanner/buildplanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"github.com/ActiveState/cli/internal/rtutils/ptr"
"github.com/ActiveState/cli/internal/runbits/rationalize"
"github.com/ActiveState/cli/pkg/buildplan"
"github.com/ActiveState/cli/pkg/localcommit"
"github.com/ActiveState/cli/pkg/platform/api/buildplanner/request"
"github.com/ActiveState/cli/pkg/platform/model"
bpModel "github.com/ActiveState/cli/pkg/platform/model/buildplanner"
Expand Down Expand Up @@ -39,6 +38,7 @@ type primeable interface {
primer.Auther
primer.Outputer
primer.SvcModeler
primer.CheckoutInfoer
}

// GetCommit returns a commit from the given arguments. By default, the local commit for the
Expand All @@ -54,6 +54,7 @@ func GetCommit(
out := prime.Output()
auth := prime.Auth()
svcm := prime.SvcModel()
info := prime.CheckoutInfo()

if pj == nil && !namespace.IsValid() {
return nil, rationalize.ErrNoProject
Expand Down Expand Up @@ -87,9 +88,9 @@ func GetCommit(
switch {
// Return the buildplan from this runtime.
case !namespaceProvided && !commitIdProvided:
localCommitID, err := localcommit.Get(pj.Path())
localCommitID, err := info.CommitID()
if err != nil {
return nil, errs.Wrap(err, "Could not get local commit")
return nil, errs.Wrap(err, "Could not get commit ID")
}

bp := bpModel.NewBuildPlannerModel(auth, svcm)
Expand Down Expand Up @@ -154,9 +155,9 @@ func GetCommit(
owner = pj.Owner()
name = pj.Name()
nsString = pj.NamespaceString()
commitID, err := localcommit.Get(pj.Path())
commitID, err := info.CommitID()
if err != nil {
return nil, errs.Wrap(err, "Could not get local commit")
return nil, errs.Wrap(err, "Could not get commit ID")
}
localCommitID = &commitID
}
Expand Down
12 changes: 3 additions & 9 deletions internal/runbits/buildscript/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ import (
"github.com/ActiveState/cli/internal/errs"
"github.com/ActiveState/cli/internal/fileutils"
"github.com/ActiveState/cli/internal/logging"
"github.com/ActiveState/cli/internal/primer"
"github.com/ActiveState/cli/pkg/buildscript"
"github.com/ActiveState/cli/pkg/localcommit"
"github.com/ActiveState/cli/pkg/checkoutinfo"
"github.com/ActiveState/cli/pkg/platform/authentication"
"github.com/ActiveState/cli/pkg/platform/model"
"github.com/ActiveState/cli/pkg/platform/model/buildplanner"
Expand Down Expand Up @@ -42,12 +41,7 @@ func ScriptFromFile(path string) (*buildscript.BuildScript, error) {
return buildscript.Unmarshal(data)
}

type primeable interface {
primer.Auther
primer.SvcModeler
}

func Initialize(path string, auth *authentication.Auth, svcm *model.SvcModel) error {
func Initialize(path string, auth *authentication.Auth, svcm *model.SvcModel, info *checkoutinfo.CheckoutInfo) error {
scriptPath := filepath.Join(path, constants.BuildScriptFileName)
script, err := ScriptFromFile(scriptPath)
if err == nil {
Expand All @@ -58,7 +52,7 @@ func Initialize(path string, auth *authentication.Auth, svcm *model.SvcModel) er
}

logging.Debug("Build script does not exist. Creating one.")
commitId, err := localcommit.Get(path)
commitId, err := info.CommitID()
if err != nil {
return errs.Wrap(err, "Unable to get the local commit ID")
}
Expand Down
12 changes: 6 additions & 6 deletions internal/runbits/checker/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ 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/pkg/checkoutinfo"
"github.com/ActiveState/cli/pkg/platform/authentication"
"github.com/ActiveState/cli/pkg/platform/model"
"github.com/ActiveState/cli/pkg/project"
)

// RunCommitsBehindNotifier checks for the commits behind count based on the
// provided project and displays the results to the user in a helpful manner.
func RunCommitsBehindNotifier(p *project.Project, out output.Outputer, auth *authentication.Auth) {
count, err := CommitsBehind(p, auth)
func RunCommitsBehindNotifier(p *project.Project, out output.Outputer, auth *authentication.Auth, info *checkoutinfo.CheckoutInfo) {
count, err := CommitsBehind(p, auth, info)
if err != nil {
if errors.Is(err, model.ErrCommitCountUnknowable) {
out.Notice(output.Title(locale.Tr("runtime_update_notice_unknown_count")))
Expand All @@ -35,7 +35,7 @@ func RunCommitsBehindNotifier(p *project.Project, out output.Outputer, auth *aut
}
}

func CommitsBehind(p *project.Project, auth *authentication.Auth) (int, error) {
func CommitsBehind(p *project.Project, auth *authentication.Auth, info *checkoutinfo.CheckoutInfo) (int, error) {
if p.IsHeadless() {
return 0, nil
}
Expand All @@ -49,9 +49,9 @@ func CommitsBehind(p *project.Project, auth *authentication.Auth) (int, error) {
return 0, locale.NewError("err_latest_commit", "Latest commit ID is nil")
}

commitID, err := localcommit.Get(p.Dir())
commitID, err := info.CommitID()
if err != nil {
return 0, errs.Wrap(err, "Unable to get local commit")
return 0, errs.Wrap(err, "Unable to get commit ID")
}

return model.CommitsBehind(*latestCommitID, commitID, auth)
Expand Down
9 changes: 3 additions & 6 deletions internal/runbits/checkout/checkout.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/ActiveState/cli/internal/language"
"github.com/ActiveState/cli/internal/osutils"
"github.com/ActiveState/cli/internal/runbits/git"
"github.com/ActiveState/cli/pkg/localcommit"
"github.com/ActiveState/cli/pkg/platform/api/mono/mono_models"
"github.com/ActiveState/cli/pkg/platform/authentication"
"github.com/ActiveState/cli/pkg/platform/model"
Expand All @@ -28,6 +27,7 @@ type primeable interface {
primer.Configurer
primer.Auther
primer.SvcModeler
primer.CheckoutInfoer
}

// Checkout will checkout the given platform project at the given path
Expand Down Expand Up @@ -99,7 +99,7 @@ func (r *Checkout) Run(ns *project.Namespaced, branchName, cachePath, targetPath
}

if r.prime.Config().GetBool(constants.OptinBuildscriptsConfig) {
if err := buildscript_runbit.Initialize(path, r.prime.Auth(), r.prime.SvcModel()); err != nil {
if err := buildscript_runbit.Initialize(path, r.prime.Auth(), r.prime.SvcModel(), r.prime.CheckoutInfo()); err != nil {
return "", errs.Wrap(err, "Unable to initialize buildscript")
}
}
Expand Down Expand Up @@ -184,6 +184,7 @@ func CreateProjectFiles(checkoutPath, cachePath, owner, name, branch, commitID,
Owner: owner,
Project: name, // match case on the Platform
BranchName: branch,
CommitID: commitID,
Directory: checkoutPath,
Language: language,
Cache: cachePath,
Expand All @@ -196,10 +197,6 @@ func CreateProjectFiles(checkoutPath, cachePath, owner, name, branch, commitID,
}
}

if err := localcommit.Set(checkoutPath, commitID); err != nil {
return errs.Wrap(err, "Could not create local commit file")
}

return nil
}

Expand Down
6 changes: 3 additions & 3 deletions internal/runbits/commits_runbit/time.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/ActiveState/cli/internal/captain"
"github.com/ActiveState/cli/internal/errs"
"github.com/ActiveState/cli/pkg/buildscript"
"github.com/ActiveState/cli/pkg/localcommit"
"github.com/ActiveState/cli/pkg/checkoutinfo"
"github.com/ActiveState/cli/pkg/platform/authentication"
"github.com/ActiveState/cli/pkg/platform/model"
"github.com/ActiveState/cli/pkg/project"
Expand Down Expand Up @@ -40,14 +40,14 @@ func ExpandTime(ts *captain.TimeValue, auth *authentication.Auth) (time.Time, er

// ExpandTimeForProject is the same as ExpandTime except that it ensures the returned time is either the same or
// later than that of the most recent commit.
func ExpandTimeForProject(ts *captain.TimeValue, auth *authentication.Auth, proj *project.Project) (time.Time, error) {
func ExpandTimeForProject(ts *captain.TimeValue, auth *authentication.Auth, proj *project.Project, info *checkoutinfo.CheckoutInfo) (time.Time, error) {
timestamp, err := ExpandTime(ts, auth)
if err != nil {
return time.Time{}, errs.Wrap(err, "Unable to expand time")
}

if proj != nil {
commitID, err := localcommit.Get(proj.Dir())
commitID, err := info.CommitID()
if err != nil {
return time.Time{}, errs.Wrap(err, "Unable to get commit ID")
}
Expand Down
1 change: 1 addition & 0 deletions internal/runbits/reqop_runbit/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type primeable interface {
primer.Configurer
primer.Analyticer
primer.SvcModeler
primer.CheckoutInfoer
}

type requirements []*Requirement
Expand Down
6 changes: 3 additions & 3 deletions internal/runbits/runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"github.com/ActiveState/cli/internal/runbits/runtime/progress"
"github.com/ActiveState/cli/internal/runbits/runtime/trigger"
"github.com/ActiveState/cli/pkg/buildplan"
"github.com/ActiveState/cli/pkg/localcommit"
"github.com/ActiveState/cli/pkg/platform/model"
bpModel "github.com/ActiveState/cli/pkg/platform/model/buildplanner"
"github.com/ActiveState/cli/pkg/project"
Expand Down Expand Up @@ -105,6 +104,7 @@ type primeable interface {
primer.Configurer
primer.SvcModeler
primer.Analyticer
primer.CheckoutInfoer
}

func Update(
Expand Down Expand Up @@ -147,7 +147,7 @@ func Update(
commitID = opts.Commit.CommitID
}
if commitID == "" {
commitID, err = localcommit.Get(proj.Dir())
commitID, err = prime.CheckoutInfo().CommitID()
if err != nil {
return nil, errs.Wrap(err, "Failed to get local commit")
}
Expand All @@ -169,7 +169,7 @@ func Update(
}
}()

rtHash, err := runtime_helpers.Hash(proj, &commitID)
rtHash, err := runtime_helpers.Hash(prime, &commitID)
if err != nil {
ah.fire(anaConsts.CatRuntimeDebug, anaConsts.ActRuntimeCache, nil)
return nil, errs.Wrap(err, "Failed to get runtime hash")
Expand Down
10 changes: 5 additions & 5 deletions internal/runners/activate/activate.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
"github.com/ActiveState/cli/internal/runbits/runtime/trigger"
"github.com/ActiveState/cli/internal/subshell"
"github.com/ActiveState/cli/internal/virtualenvironment"
"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/project"
Expand Down Expand Up @@ -66,6 +65,7 @@ type primeable interface {
primer.Configurer
primer.SvcModeler
primer.Analyticer
primer.CheckoutInfoer
}

func NewActivate(prime primeable) *Activate {
Expand Down Expand Up @@ -146,9 +146,9 @@ func (r *Activate) Run(params *ActivateParams) (rerr error) {
}

if proj != nil {
commitID, err := localcommit.Get(proj.Dir())
commitID, err := r.prime.CheckoutInfo().CommitID()
if err != nil {
return errs.Wrap(err, "Unable to get local commit")
return errs.Wrap(err, "Unable to get commit ID")
}
if cid := params.Namespace.CommitID; cid != nil && *cid != commitID {
return locale.NewInputError("err_activate_commit_id_mismatch")
Expand Down Expand Up @@ -196,9 +196,9 @@ func (r *Activate) Run(params *ActivateParams) (rerr error) {
}
}

commitID, err := localcommit.Get(proj.Dir())
commitID, err := r.prime.CheckoutInfo().CommitID()
if err != nil {
return errs.Wrap(err, "Unable to get local commit")
return errs.Wrap(err, "Unable to get commit ID")
}
if commitID == "" {
err := locale.NewInputError("err_project_no_commit", "Your project does not have a commit ID. Please run [ACTIONIABLE]'state push'[/RESET] first.", model.ProjectURL(proj.Owner(), proj.Name(), ""))
Expand Down
1 change: 1 addition & 0 deletions internal/runners/artifacts/artifacts.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type primeable interface {
primer.SvcModeler
primer.Configurer
primer.Analyticer
primer.CheckoutInfoer
}

type Params struct {
Expand Down
Loading

0 comments on commit 9ba0b39

Please sign in to comment.