1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-10 03:47:03 +02:00
goreleaser/pipeline/release/remote.go
Carlos Alexandro Becker 1ed299a6d7 refactor: defaulter interface
Right now the code looks weird because the defaults
of a pipe are far away of the implementation of the pipe.

the intend of this PR is to bring them closer by having a
Defaulter interface.

I also renamed the Pipe interface to Piper, and removed
the Description method in favor for fmt.Stringer.
2017-12-03 13:00:01 -02:00

42 lines
890 B
Go

package release
import (
"strings"
"github.com/goreleaser/goreleaser/config"
"github.com/goreleaser/goreleaser/internal/git"
"github.com/pkg/errors"
)
// remoteRepo gets the repo name from the Git config.
func remoteRepo() (result config.Repo, err error) {
if !git.IsRepo() {
return result, errors.New("current folder is not a git repository")
}
out, err := git.Run("config", "--get", "remote.origin.url")
if err != nil {
return result, errors.Wrap(err, "repository doesn't have an `origin` remote")
}
return extractRepoFromURL(out), nil
}
func extractRepoFromURL(s string) config.Repo {
for _, r := range []string{
"git@github.com:",
".git",
"https://github.com/",
"\n",
} {
s = strings.Replace(s, r, "", -1)
}
return toRepo(s)
}
func toRepo(s string) config.Repo {
var ss = strings.Split(s, "/")
return config.Repo{
Owner: ss[0],
Name: ss[1],
}
}