2017-12-02 19:53:19 -02:00
|
|
|
package release
|
2017-01-14 19:12:20 +01:00
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
2017-03-22 21:01:29 -03:00
|
|
|
|
|
|
|
"github.com/goreleaser/goreleaser/config"
|
2017-10-16 15:43:26 -02:00
|
|
|
"github.com/goreleaser/goreleaser/internal/git"
|
2017-10-15 17:46:21 -02:00
|
|
|
"github.com/pkg/errors"
|
2017-01-14 19:12:20 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// remoteRepo gets the repo name from the Git config.
|
2017-03-22 21:01:29 -03:00
|
|
|
func remoteRepo() (result config.Repo, err error) {
|
2017-10-16 15:43:26 -02:00
|
|
|
if !git.IsRepo() {
|
|
|
|
return result, errors.New("current folder is not a git repository")
|
2017-10-15 17:46:21 -02:00
|
|
|
}
|
2017-10-16 15:43:26 -02:00
|
|
|
out, err := git.Run("config", "--get", "remote.origin.url")
|
2017-01-14 19:12:20 +01:00
|
|
|
if err != nil {
|
2017-10-15 17:46:21 -02:00
|
|
|
return result, errors.Wrap(err, "repository doesn't have an `origin` remote")
|
2017-01-14 19:12:20 +01:00
|
|
|
}
|
2017-10-16 15:43:26 -02:00
|
|
|
return extractRepoFromURL(out), nil
|
2017-01-14 19:12:20 +01:00
|
|
|
}
|
|
|
|
|
2017-03-22 21:01:29 -03:00
|
|
|
func extractRepoFromURL(s string) config.Repo {
|
2017-01-14 19:12:20 +01:00
|
|
|
for _, r := range []string{
|
|
|
|
"git@github.com:",
|
|
|
|
".git",
|
|
|
|
"https://github.com/",
|
|
|
|
"\n",
|
|
|
|
} {
|
|
|
|
s = strings.Replace(s, r, "", -1)
|
|
|
|
}
|
2017-03-22 21:01:29 -03:00
|
|
|
return toRepo(s)
|
|
|
|
}
|
|
|
|
|
|
|
|
func toRepo(s string) config.Repo {
|
|
|
|
var ss = strings.Split(s, "/")
|
|
|
|
return config.Repo{
|
|
|
|
Owner: ss[0],
|
|
|
|
Name: ss[1],
|
|
|
|
}
|
2017-01-14 19:12:20 +01:00
|
|
|
}
|