-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support old project format with commitID in activestate.yaml. #2829
Changes from 8 commits
95b3728
6fe2a50
94c1b58
312e01a
b700527
82a914d
bbda2a4
869caa9
aa62fe5
394a7f9
df44957
19f9f31
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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") | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
@@ -0,0 +1,79 @@ | ||||
package projectmigration | ||||
|
||||
import ( | ||||
"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") | ||||
} | ||||
|
||||
if fileutils.DirExists(filepath.Join(proj.Dir(), ".git")) { | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Realize this probably wasn't introduced here but we should go up the directory tree to check for this also, since people may not checkout their activestate.yaml inside the same dir as their git repo (eg. TheHomeRepot). You can use: cli/internal/fileutils/fileutils.go Line 422 in 35d1e55
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sadly, that's files only, not directories. Still, I'll do something to walk up the tree. |
||||
err := localcommit.AddToGitIgnore(proj.Dir()) | ||||
if err != nil { | ||||
multilog.Error("Unable to add local commit file to .gitignore: %v", err) | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This would almost certainly be due to something client-side like permission errors I think? We should probably not log this to rollbar. Or maybe add a check to only log if it's not a permission or IO error. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wasn't able to find a generic ErrIO variable, but I did find ErrPermission, so we'll go with that. |
||||
out.Notice(locale.T("notice_commit_id_gitignore")) | ||||
} | ||||
} | ||||
|
||||
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 | ||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rawktron please review
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the full message? We have to give them some context for this. Is there another part of this message?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rawktron That is the full message. Whenever they run a
state
command that needs to read a commitId from activestate.yaml, this message is presented to them. The ticket did not specify what the prompt should look like, so I came up with this for the time being. Please advise what message you'd like to give.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be something like "State Tool has introduced a new project format to provide enhanced functionality. Your project is currently using the old format and will remain read-only until you migrate to the new project format.
WARNING: After you migrate, older versions of the State Tool will not be able to use your project.
Would you like to perform the migration now?"