fix: auto-config ssh urls and push to them

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

28
pkg/git/remote.go Normal file
View File

@ -0,0 +1,28 @@
package git
import (
"strings"
"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/config"
"github.com/sirupsen/logrus"
)
// CreateRemote creates a new git remote in a repository
func CreateRemote(repo *git.Repository, name, url string, dryRun bool) error {
if dryRun {
logrus.Infof("dry run: remote %s (%s) not created", name, url)
return nil
}
if _, err := repo.CreateRemote(&config.RemoteConfig{
Name: name,
URLs: []string{url},
}); err != nil {
if !strings.Contains(err.Error(), "remote already exists") {
return err
}
}
return nil
}