1
0
mirror of https://github.com/raseels-repos/golang-saas-starter-kit.git synced 2025-07-17 01:42:36 +02:00

use CI_PROJECT_PATH for remote username

This commit is contained in:
Lee Brown
2019-08-22 23:33:09 -08:00
parent 0852548099
commit c1f8b8f937

View File

@ -119,11 +119,8 @@ func (cfgCtx *ConfigContext) Config(log *log.Logger) (*devdeploy.Config, error)
if cfg.ProjectName == "saas-starter-kit" {
remoteUser := gitRemoteUser( modDetails.ProjectRoot)
log.Println("cfg.ProjectName ", cfg.ProjectName )
log.Println("remoteUser ", remoteUser )
// Its a true fork from the origin repo.
if remoteUser != "geeks-accelerator" && remoteUser != "oss" {
if remoteUser != "saas-starter-kit" && remoteUser != "geeks-accelerator" {
// Replace the prefix 'saas' with the parent directory name, hopefully the gitlab group/username.
cfg.ProjectName = filepath.Base(filepath.Dir(cfg.ProjectRoot)) + "-starter-kit"
@ -579,18 +576,28 @@ func getCommitRef() string {
// gitRemoteUser returns the git username/organization for the git repo
func gitRemoteUser(projectRoot string) string {
dat, err := ioutil.ReadFile(filepath.Join(projectRoot, ".git/config"))
if err != nil {
return ""
}
var remoteUrl string
lines := strings.Split(string(dat), "\n")
for _, l := range lines {
l = strings.TrimSpace(l)
if strings.HasPrefix(l, "url =") {
remoteUrl = l
break
if ev := os.Getenv("CI_PROJECT_PATH"); ev != "" {
if strings.Contains(ev, "/") {
remoteUrl = strings.Split(ev, "/")[1]
remoteUrl = strings.Split(remoteUrl, "/")[0]
} else {
remoteUrl = ev
}
} else {
dat, err := ioutil.ReadFile(filepath.Join(projectRoot, ".git/config"))
if err != nil {
return ""
}
lines := strings.Split(string(dat), "\n")
for _, l := range lines {
l = strings.TrimSpace(l)
if strings.HasPrefix(l, "url =") {
remoteUrl = l
break
}
}
}