github.com/tomsquest/goreleaser@v0.34.3-0.20171008022654-7d6ef4d338b3/pipeline/defaults/remote.go (about)

     1  package defaults
     2  
     3  import (
     4  	"errors"
     5  	"os/exec"
     6  	"strings"
     7  
     8  	"github.com/goreleaser/goreleaser/config"
     9  )
    10  
    11  // remoteRepo gets the repo name from the Git config.
    12  func remoteRepo() (result config.Repo, err error) {
    13  	cmd := exec.Command("git", "config", "--get", "remote.origin.url")
    14  	bts, err := cmd.CombinedOutput()
    15  	if err != nil {
    16  		return result, errors.New(err.Error() + ": " + string(bts))
    17  	}
    18  	return extractRepoFromURL(string(bts)), nil
    19  }
    20  
    21  func extractRepoFromURL(s string) config.Repo {
    22  	for _, r := range []string{
    23  		"git@github.com:",
    24  		".git",
    25  		"https://github.com/",
    26  		"\n",
    27  	} {
    28  		s = strings.Replace(s, r, "", -1)
    29  	}
    30  	return toRepo(s)
    31  }
    32  
    33  func toRepo(s string) config.Repo {
    34  	var ss = strings.Split(s, "/")
    35  	return config.Repo{
    36  		Owner: ss[0],
    37  		Name:  ss[1],
    38  	}
    39  }