Skip to content

Commit

Permalink
feat: get git repo URL
Browse files Browse the repository at this point in the history
  • Loading branch information
Zebradil committed Jun 14, 2023
1 parent 72388b1 commit c9b726a
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions internal/myks/globe.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"io/fs"
"os"
"path/filepath"
"strings"

"github.com/creasty/defaults"
"github.com/rs/zerolog/log"
Expand Down Expand Up @@ -73,6 +74,9 @@ type Globe struct {

/// Runtime data

// Git repository URL
GitRepoUrl string `yaml:"gitRepoUrl"`

// Collected environments for processing
environments map[string]*Environment

Expand All @@ -94,6 +98,10 @@ func New(rootDir string) *Globe {
g.extraYttPaths = append(g.extraYttPaths, yttLibraryDir)
}

if err := g.setGitRepoUrl(); err != nil {
log.Warn().Err(err).Msg("Unable to set git repo url")
}

log.Debug().Interface("globe", g).Msg("Globe config")
return g
}
Expand Down Expand Up @@ -262,6 +270,21 @@ func (g *Globe) collectEnvironmentsInPath(searchPath string) {
}
}

func (g *Globe) setGitRepoUrl() error {
if g.GitRepoUrl == "" {
result, err := runCmd("git", nil, []string{"remote", "get-url", "origin"})
if err != nil {
return err
}
// Transform ssh url to https url
g.GitRepoUrl = strings.Trim(result.Stdout, "\n")
g.GitRepoUrl = strings.ReplaceAll(g.GitRepoUrl, ":", "/")
g.GitRepoUrl = strings.ReplaceAll(g.GitRepoUrl, "git@", "https://")
g.GitRepoUrl = strings.ReplaceAll(g.GitRepoUrl, ".git", "")
}
return nil
}

func (g *Globe) ytt(paths []string, args ...string) (CmdResult, error) {
return g.yttS(paths, nil, args...)
}
Expand Down

0 comments on commit c9b726a

Please sign in to comment.