Skip to content

Commit

Permalink
make local exec more generic
Browse files Browse the repository at this point in the history
  • Loading branch information
walteh committed Nov 21, 2023
1 parent 2773aee commit 9a95ebb
Showing 1 changed file with 10 additions and 25 deletions.
35 changes: 10 additions & 25 deletions gitexec/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ import (
"github.com/walteh/simver"
)

func BuildLocalProviders(fls afero.Fs) (simver.GitProvider, simver.TagProvider, simver.TagWriter, simver.PRProvider, simver.PRResolver, error) {
func BuildLocalProviders(fls afero.Fs) (simver.GitProvider, simver.TagProvider, simver.TagWriter, simver.PRResolver, error) {

repoData, err := fls.Open("/.git/config")
repoData, err := fls.Open(".git/config")
if err != nil {
return nil, nil, nil, nil, nil, errors.Wrap(err, "error opening /.git/config")
return nil, nil, nil, nil, errors.Wrap(err, "error opening /.git/config")
}

repoConfig, err := afero.ReadAll(repoData)
if err != nil {
return nil, nil, nil, nil, nil, errors.Wrap(err, "error reading /.git/config")
return nil, nil, nil, nil, errors.Wrap(err, "error reading /.git/config")
}

// split the config file into lines
Expand All @@ -35,7 +35,7 @@ func BuildLocalProviders(fls afero.Fs) (simver.GitProvider, simver.TagProvider,
}

if len(remoteOrigin) == 0 {
return nil, nil, nil, nil, nil, errors.New("could not find remote origin in /.git/config")
return nil, nil, nil, nil, errors.New("could not find remote origin in /.git/config")
}

// find the url line
Expand All @@ -48,7 +48,7 @@ func BuildLocalProviders(fls afero.Fs) (simver.GitProvider, simver.TagProvider,
}

if urlLine == "" {
return nil, nil, nil, nil, nil, errors.New("could not find url line in remote origin in /.git/config")
return nil, nil, nil, nil, errors.New("could not find url line in remote origin in /.git/config")
}

// grab the url
Expand All @@ -65,7 +65,7 @@ func BuildLocalProviders(fls afero.Fs) (simver.GitProvider, simver.TagProvider,
if bp, ok := fls.(*afero.BasePathFs); ok {
path, err = bp.RealPath("/")
if err != nil {
return nil, nil, nil, nil, nil, errors.Wrap(err, "error getting real path")
return nil, nil, nil, nil, errors.Wrap(err, "error getting real path")
}
} else {
path = "."
Expand All @@ -83,35 +83,20 @@ func BuildLocalProviders(fls afero.Fs) (simver.GitProvider, simver.TagProvider,
Repo: repo,
}

pr := &GHProvierOpts{
GitHubToken: "invalid",
RepoPath: path,
GHExecutable: "gh",
Org: org,
Repo: repo,
}

git, err := NewGitProvider(c)
if err != nil {
return nil, nil, nil, nil, nil, errors.Wrap(err, "error creating git provider")
}

gh, err := NewGHProvider(pr)
if err != nil {
return nil, nil, nil, nil, nil, errors.Wrap(err, "error creating gh provider")
return nil, nil, nil, nil, errors.Wrap(err, "error creating git provider")
}

gha, err := WrapGitProviderInGithubActions(git)
if err != nil {
return nil, nil, nil, nil, nil, errors.Wrap(err, "error creating gh provider")
return nil, nil, nil, nil, errors.Wrap(err, "error creating gh provider")
}

return gha, git, git, gh, &LocalPullRequestResolver{gh, git}, nil
return gha, git, git, &LocalPullRequestResolver{}, nil
}

type LocalPullRequestResolver struct {
gh simver.PRProvider
git simver.GitProvider
}

func (p *LocalPullRequestResolver) CurrentPR(ctx context.Context) (*simver.PRDetails, error) {
Expand Down

0 comments on commit 9a95ebb

Please sign in to comment.