1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-10 03:47:03 +02:00
goreleaser/pipeline/defaults/remote.go
Jorin Vogel 37034012c4 Default value for repo option.
It's loaded from Git config.
Thanks @caarlos0 for implementing remoteRepo func!
2017-01-14 19:12:20 +01:00

30 lines
583 B
Go

package defaults
import (
"errors"
"os/exec"
"strings"
)
// remoteRepo gets the repo name from the Git config.
func remoteRepo() (result string, err error) {
cmd := exec.Command("git", "config", "--get", "remote.origin.url")
bts, err := cmd.CombinedOutput()
if err != nil {
return "", errors.New(err.Error() + ": " + string(bts))
}
return extractRepoFromURL(string(bts)), nil
}
func extractRepoFromURL(s string) string {
for _, r := range []string{
"git@github.com:",
".git",
"https://github.com/",
"\n",
} {
s = strings.Replace(s, r, "", -1)
}
return s
}