fix: auto-config ssh urls and push to them
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2021-12-27 18:06:56 +01:00
parent b98397144a
commit eb1b6be4c5
6 changed files with 85 additions and 19 deletions

View File

@ -1,36 +1,41 @@
package git
import (
"path"
configPkg "coopcloud.tech/abra/pkg/config"
"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/config"
"github.com/sirupsen/logrus"
)
// Push pushes the latest changes
func Push(recipeName string, tags bool) error {
recipeDir := path.Join(configPkg.RECIPES_DIR, recipeName)
commitRepo, err := git.PlainOpen(recipeDir)
// Push pushes the latest changes & optionally tags to the default remote
func Push(repoDir string, remote string, tags bool, dryRun bool) error {
if dryRun {
logrus.Infof("dry run: no git changes pushed in %s", repoDir)
return nil
}
commitRepo, err := git.PlainOpen(repoDir)
if err != nil {
return err
}
if err := commitRepo.Push(&git.PushOptions{}); err != nil {
opts := &git.PushOptions{}
if remote != "" {
opts.RemoteName = remote
}
if err := commitRepo.Push(opts); err != nil {
return err
}
logrus.Info("git changes pushed")
if tags {
pushOpts := &git.PushOptions{
RefSpecs: []config.RefSpec{
config.RefSpec("+refs/tags/*:refs/tags/*"),
},
}
if err := commitRepo.Push(pushOpts); err != nil {
opts.RefSpecs = append(opts.RefSpecs, config.RefSpec("+refs/tags/*:refs/tags/*"))
if err := commitRepo.Push(opts); err != nil {
return err
}
logrus.Info("git tags pushed")
}