-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch version/0-42-0-RC1 to adopt changes from PR #2829
- Loading branch information
Showing
33 changed files
with
289 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
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" | ||
) | ||
|
||
type projecter interface { | ||
Dir() string | ||
URL() string | ||
Path() string | ||
LegacyCommitID() string | ||
} | ||
|
||
// 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") | ||
} | ||
} |
87 changes: 87 additions & 0 deletions
87
internal/runbits/legacy/projectmigration/projectmigration.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package projectmigration | ||
|
||
import ( | ||
"errors" | ||
"io/fs" | ||
"path/filepath" | ||
|
||
"github.com/ActiveState/cli/internal/errs" | ||
"github.com/ActiveState/cli/internal/fileutils" | ||
"github.com/ActiveState/cli/internal/locale" | ||
"github.com/ActiveState/cli/internal/multilog" | ||
"github.com/ActiveState/cli/internal/output" | ||
"github.com/ActiveState/cli/internal/prompt" | ||
"github.com/ActiveState/cli/pkg/localcommit" | ||
"github.com/ActiveState/cli/pkg/projectfile" | ||
) | ||
|
||
type projecter interface { | ||
Dir() string | ||
URL() string | ||
Path() string | ||
LegacyCommitID() string | ||
} | ||
|
||
var prompter prompt.Prompter | ||
var out output.Outputer | ||
var declined bool | ||
|
||
// Register exists to avoid boilerplate in passing prompt and out to every caller of | ||
// commitmediator.Get() for retrieving legacy commitId from activestate.yaml. | ||
// This is an anti-pattern and is only used to make this legacy feature palatable. | ||
func Register(prompter_ prompt.Prompter, out_ output.Outputer) { | ||
prompter = prompter_ | ||
out = out_ | ||
} | ||
|
||
func PromptAndMigrate(proj projecter) (bool, error) { | ||
if prompter == nil || out == nil { | ||
return false, errs.New("projectmigration.Register() has not been called") | ||
} | ||
|
||
if declined { | ||
return false, nil | ||
} | ||
|
||
defaultChoice := false | ||
if migrate, err := prompter.Confirm("", locale.T("projectmigration_confirm"), &defaultChoice); err == nil && !migrate { | ||
if out.Config().Interactive { | ||
out.Notice(locale.Tl("projectmigration_declined", "Migration declined for now")) | ||
} | ||
declined = true | ||
return false, nil | ||
} else if err != nil { | ||
return false, errs.Wrap(err, "Could not confirm migration choice") | ||
} | ||
|
||
if err := localcommit.Set(proj.Dir(), proj.LegacyCommitID()); err != nil { | ||
return false, errs.Wrap(err, "Could not create local commit file") | ||
} | ||
|
||
for dir := proj.Dir(); filepath.Dir(dir) != dir; dir = filepath.Dir(dir) { | ||
if !fileutils.DirExists(filepath.Join(dir, ".git")) { | ||
continue | ||
} | ||
err := localcommit.AddToGitIgnore(dir) | ||
if err != nil { | ||
if !errors.Is(err, fs.ErrPermission) { | ||
multilog.Error("Unable to add local commit file to .gitignore: %v", err) | ||
} | ||
out.Notice(locale.T("notice_commit_id_gitignore")) | ||
} | ||
break | ||
} | ||
|
||
pf := projectfile.NewProjectField() | ||
if err := pf.LoadProject(proj.URL()); err != nil { | ||
return false, errs.Wrap(err, "Could not load activestate.yaml") | ||
} | ||
pf.StripCommitID() | ||
if err := pf.Save(proj.Path()); err != nil { | ||
return false, errs.Wrap(err, "Could not save activestate.yaml") | ||
} | ||
|
||
out.Notice(locale.Tl("projectmigration_success", "Your project was successfully migrated")) | ||
|
||
return true, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.