Skip to content

Commit

Permalink
chore: allow to call GetRepoBaseInfo() on custom dir
Browse files Browse the repository at this point in the history
  • Loading branch information
tomaszbarwicki committed Jan 17, 2024
1 parent eb831fe commit 2e6aab1
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions release-automation/internal/repo/repoinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"fmt"
"os"
"strings"
"path"

"github.com/go-ini/ini"
"tractusx-release-automation/internal/tractusx"
Expand All @@ -38,7 +39,7 @@ type RepoInfo struct {
// It leverages environment variables typically available in GitHub workflows.
// As fallback option, the local git config (.git/config) file is used.
// Results are returned as *RepoInfo
func GetRepoBaseInfo() *RepoInfo {
func GetRepoBaseInfo(repoDir string) *RepoInfo {
const (
BASEURL = "https://github.com/"
SSHBASE = "git@github.com:"
Expand All @@ -57,7 +58,7 @@ func GetRepoBaseInfo() *RepoInfo {
}

// Parse local git configuration when executing locally
cfg, err := ini.Load(".git/config")
cfg, err := ini.Load(path.Join(repoDir, ".git/config"))
if err != nil {
fmt.Printf("Failed to read file: %v", err)
}
Expand All @@ -79,9 +80,9 @@ func GetRepoBaseInfo() *RepoInfo {
return &result
}

func isLeadingRepo() bool {
metadata, err := tractusx.MetadataFromLocalFile("./")
repoInfo := GetRepoBaseInfo()
func isLeadingRepo(repoDir string) bool {
metadata, err := tractusx.MetadataFromLocalFile(repoDir)
repoInfo := GetRepoBaseInfo(repoDir)
fullRepoName := "https://github.com/eclipse-tractusx/" + (*repoInfo).Reponame

if err != nil || metadata.LeadingRepository != fullRepoName {
Expand Down

0 comments on commit 2e6aab1

Please sign in to comment.