mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-01-10 03:47:03 +02:00
37034012c4
It's loaded from Git config. Thanks @caarlos0 for implementing remoteRepo func!
30 lines
583 B
Go
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
|
|
}
|