forked from toolshed/abra
refactor: centralise git commit machinery
This commit is contained in:
@ -15,7 +15,6 @@ import (
|
||||
gitPkg "coopcloud.tech/abra/pkg/git"
|
||||
"coopcloud.tech/abra/pkg/limit"
|
||||
"github.com/AlecAivazis/survey/v2"
|
||||
"github.com/go-git/go-git/v5"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
@ -224,43 +223,19 @@ A new catalogue copy can be published to the recipes repository by passing the
|
||||
logrus.Infof("generated new recipe catalogue in %s", config.APPS_JSON)
|
||||
|
||||
if internal.Commit {
|
||||
repoPath := path.Join(config.ABRA_DIR, "catalogue")
|
||||
commitRepo, err := git.PlainOpen(repoPath)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
commitWorktree, err := commitRepo.Worktree()
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
if internal.CommitMessage == "" {
|
||||
if internal.CommitMessage == "" && !internal.NoInput {
|
||||
prompt := &survey.Input{
|
||||
Message: "commit message",
|
||||
Default: "chore: publish new catalogue changes",
|
||||
Default: fmt.Sprintf("chore: publish catalogue changes"),
|
||||
}
|
||||
if err := survey.AskOne(prompt, &internal.CommitMessage); err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
err = commitWorktree.AddGlob("**.json")
|
||||
if err != nil {
|
||||
if err := gitPkg.Commit("**.json", internal.CommitMessage, false); err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
logrus.Debug("staged **.json for commit")
|
||||
|
||||
_, err = commitWorktree.Commit(internal.CommitMessage, &git.CommitOptions{})
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
logrus.Info("changes commited")
|
||||
|
||||
if err := commitRepo.Push(&git.PushOptions{}); err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
logrus.Info("changes pushed")
|
||||
}
|
||||
|
||||
return nil
|
||||
|
Reference in New Issue
Block a user