gitee.com/mirrors_opencollective/goreleaser@v0.45.0/pipeline/release/remote.go (about)

     1  package release
     2  
     3  import (
     4  	"strings"
     5  
     6  	"github.com/goreleaser/goreleaser/config"
     7  	"github.com/goreleaser/goreleaser/internal/git"
     8  	"github.com/pkg/errors"
     9  )
    10  
    11  // remoteRepo gets the repo name from the Git config.
    12  func remoteRepo() (result config.Repo, err error) {
    13  	if !git.IsRepo() {
    14  		return result, errors.New("current folder is not a git repository")
    15  	}
    16  	out, err := git.Run("config", "--get", "remote.origin.url")
    17  	if err != nil {
    18  		return result, errors.Wrap(err, "repository doesn't have an `origin` remote")
    19  	}
    20  	return extractRepoFromURL(out), nil
    21  }
    22  
    23  func extractRepoFromURL(s string) config.Repo {
    24  	for _, r := range []string{
    25  		"git@github.com:",
    26  		".git",
    27  		"https://github.com/",
    28  		"\n",
    29  	} {
    30  		s = strings.Replace(s, r, "", -1)
    31  	}
    32  	return toRepo(s)
    33  }
    34  
    35  func toRepo(s string) config.Repo {
    36  	var ss = strings.Split(s, "/")
    37  	return config.Repo{
    38  		Owner: ss[0],
    39  		Name:  ss[1],
    40  	}
    41  }