Skip to content

Commit

Permalink
ls
Browse files Browse the repository at this point in the history
  • Loading branch information
walteh committed May 25, 2024
1 parent 29c3e16 commit bdbd106
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 32 deletions.
4 changes: 2 additions & 2 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ runs:
- name: checkout simver code
uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-depth: 1
repository: walteh/simver
ref: ${{ env.SIMVER_GITHUB_ACTION_REF }}
path: __simver__
Expand Down Expand Up @@ -50,4 +50,4 @@ runs:
working-directory: __source__
env:
GITHUB_TOKEN: ${{ inputs.GITHUB_TOKEN }}
run: "simver_gha --read-only=false"
run: "ls -la && simver_gha --read-only=false"
14 changes: 7 additions & 7 deletions gitexec/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,17 @@ func BuildGitHubActionsProviders() (simver.GitProvider, simver.TagReader, simver

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

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, nil, errors.Errorf("creating gh provider: %w", err)
}

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, nil, errors.Errorf("creating gh provider: %w", err)
}

return gha, git, git, gh, &GitHubActionsPullRequestResolver{gh, git}, nil
Expand All @@ -76,12 +76,12 @@ func (p *GitHubActionsPullRequestResolver) CurrentPR(ctx context.Context) (*simv

n, err := strconv.Atoi(num)
if err != nil {
return nil, errors.Wrap(err, "error converting PR number to int")
return nil, errors.Errorf("converting PR number to int: %w", err)
}

pr, exists, err := p.gh.PRDetailsByPRNumber(ctx, n)
if err != nil {
return nil, errors.Wrap(err, "error getting PR details by PR number")
return nil, errors.Errorf("getting PR details by PR number: %w", err)
}

if !exists {
Expand All @@ -101,7 +101,7 @@ func (p *GitHubActionsPullRequestResolver) CurrentPR(ctx context.Context) (*simv

pr, exists, err := p.gh.PRDetailsByCommit(ctx, sha)
if err != nil {
return nil, errors.Wrap(err, "error getting PR details by commit")
return nil, errors.Errorf("getting PR details by commit: %w", err)
}

if exists {
Expand All @@ -117,7 +117,7 @@ func (p *GitHubActionsPullRequestResolver) CurrentPR(ctx context.Context) (*simv
// get the parent commit
parent, err := p.git.CommitFromRef(ctx, "HEAD^")
if err != nil {
return nil, errors.Wrap(err, "error getting parent commit")
return nil, errors.Errorf("getting parent commit: %w", err)
}

return simver.NewPushSimulatedPRDetails(parent, sha, branch), nil
Expand Down
14 changes: 7 additions & 7 deletions gitexec/gh.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func (p *ghProvider) PRDetailsByPRNumber(ctx context.Context, prnum int) (*simve
cmd := p.gh(ctx, "pr", "view", fmt.Sprintf("%d", prnum), "--json", githubPRDetailsCliQuery)
out, err := cmd.Output()
if err != nil {
return nil, false, errors.Wrap(err, "gh pr view")
return nil, false, errors.Errorf("gh pr view: %w", err)
}

byt := append([]byte("["), out...)
Expand All @@ -184,7 +184,7 @@ func (p *ghProvider) PRDetailsByBranch(ctx context.Context, branch string) (*sim
cmd := p.gh(ctx, "pr", "list", "--state", "all", "--head", branch, "--json", githubPRDetailsCliQuery)
out, err := cmd.Output()
if err != nil {
return nil, false, errors.Wrap(err, "gh pr list")
return nil, false, errors.Errorf("gh pr list: %w", err)
}

return p.getRelevantPR(ctx, out)
Expand All @@ -206,7 +206,7 @@ func (p *ghProvider) getBaseCommit(ctx context.Context, dets *simver.PRDetails)
cmd := p.gh(ctx, "api", "-H", "Accept: application/vnd.github+json", fmt.Sprintf("/repos/%s/%s/git/commits/%s", p.Org, p.Repo, cmt))
out, err := cmd.Output()
if err != nil {
return "", errors.Wrap(err, "gh api")
return "", errors.Errorf("gh api: %w", err)
}

var dat struct {
Expand All @@ -217,7 +217,7 @@ func (p *ghProvider) getBaseCommit(ctx context.Context, dets *simver.PRDetails)

err = json.Unmarshal(out, &dat)
if err != nil {
return "", errors.Wrap(err, "json unmarshal")
return "", errors.Errorf("json unmarshal: %w", err)
}

if len(dat.Parents) < 1 {
Expand All @@ -233,7 +233,7 @@ func (p *ghProvider) getRootCommit(ctx context.Context) (string, error) {
cmd := p.gh(ctx, "api", "-H", "Accept: application/vnd.github+json", fmt.Sprintf("/repos/%s/%s/git/ref/heads/main", p.Org, p.Repo))
out, err := cmd.Output()
if err != nil {
return "", errors.Wrap(err, "gh api")
return "", errors.Errorf("gh api: %w", err)
}

var dat struct {
Expand All @@ -244,7 +244,7 @@ func (p *ghProvider) getRootCommit(ctx context.Context) (string, error) {

err = json.Unmarshal(out, &dat)
if err != nil {
return "", errors.Wrap(err, "json unmarshal")
return "", errors.Errorf("json unmarshal: %w", err)
}

if dat.Object.Sha == "" {
Expand All @@ -265,7 +265,7 @@ func (p *ghProvider) PRDetailsByCommit(ctx context.Context, commitHash string) (
cmd := p.gh(ctx, "pr", "list", "--search", commitHash, "--state", "all", "--json", githubPRDetailsCliQuery)
out, err := cmd.Output()
if err != nil {
return nil, false, errors.Wrap(err, "gh pr list")
return nil, false, errors.Errorf("gh pr list: %w", err)
}

return p.getRelevantPR(ctx, out)
Expand Down
6 changes: 3 additions & 3 deletions gitexec/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func (p *gitProvider) Branch(ctx context.Context) (string, error) {
cmd := p.git(ctx, "branch", "--contains", "HEAD")
out, err := cmd.Output()
if err != nil {
return "", errors.Wrap(err, "git branch --contains HEAD")
return "", errors.Errorf("git branch --contains HEAD: %w", err)
}
lines := strings.Split(string(out), "\n")
res := ""
Expand Down Expand Up @@ -173,7 +173,7 @@ func (p *gitProvider) GetHeadRef(ctx context.Context) (string, error) {
cmd := p.git(ctx, "rev-parse", "HEAD")
out, err := cmd.Output()
if err != nil {
return "", errors.Wrap(err, "git rev-parse HEAD")
return "", errors.Errorf("git rev-parse HEAD: %w", err)
}

res := strings.TrimSpace(string(out))
Expand All @@ -190,7 +190,7 @@ func (p *gitProvider) Dirty(ctx context.Context) (bool, error) {
cmd := p.git(ctx, "diff", "HEAD")
out, err := cmd.Output()
if err != nil {
return false, errors.Wrap(err, "git status --porcelain")
return false, errors.Errorf("git status --porcelain: %w", err)
}

res := strings.TrimSpace(string(out))
Expand Down
10 changes: 5 additions & 5 deletions gitexec/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ func BuildLocalProviders(fls afero.Fs) (simver.GitProvider, simver.TagReader, si

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

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

// split the config file into lines
Expand Down Expand Up @@ -65,7 +65,7 @@ func BuildLocalProviders(fls afero.Fs) (simver.GitProvider, simver.TagReader, si
if bp, ok := fls.(*afero.BasePathFs); ok {
path, err = bp.RealPath("/")
if err != nil {
return nil, nil, nil, nil, errors.Wrap(err, "error getting real path")
return nil, nil, nil, nil, errors.Errorf("getting real path: %w", err)
}
} else {
path = "."
Expand All @@ -85,7 +85,7 @@ func BuildLocalProviders(fls afero.Fs) (simver.GitProvider, simver.TagReader, si

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

return git, git, git, &LocalPullRequestResolver{}, nil
Expand All @@ -99,7 +99,7 @@ func (p *LocalPullRequestResolver) CurrentPR(ctx context.Context) (*simver.PRDet

cmt, err := p.git.GetHeadRef(ctx)
if err != nil {
return nil, errors.Wrap(err, "error getting head ref")
return nil, errors.Errorf("getting head ref: %w", err)
}

return &simver.PRDetails{
Expand Down
8 changes: 4 additions & 4 deletions gitexec/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (p *gitProvider) TagsFromBranch(ctx context.Context, branch string) (simver

err = json.Unmarshal([]byte(line), &dat)
if err != nil {
return nil, errors.Wrap(err, "json unmarshal")
return nil, errors.Errorf("json unmarshal: %w", err)
}

if dat.Type != "commit" {
Expand Down Expand Up @@ -128,7 +128,7 @@ func (p *gitProvider) FetchTags(ctx context.Context) (simver.Tags, error) {
cmd.Stderr = os.Stderr
err := cmd.Run()
if err != nil {
return nil, errors.Wrap(err, "git fetch --tags")
return nil, errors.Errorf("git fetch --tags: %w", err)
}

zerolog.Ctx(ctx).Debug().Msg("printing tags")
Expand All @@ -137,7 +137,7 @@ func (p *gitProvider) FetchTags(ctx context.Context) (simver.Tags, error) {
cmd = p.git(ctx, "show-ref", "--tags")
out, err := cmd.Output()
if err != nil {
return nil, errors.Wrap(err, "git show-ref --tags")
return nil, errors.Errorf("git show-ref --tags: %w", err)
}

lines := strings.Split(string(out), "\n")
Expand Down Expand Up @@ -185,7 +185,7 @@ func (p *gitProvider) CreateTags(ctx context.Context, tag ...simver.Tag) error {
cmd.Stderr = os.Stderr
err := cmd.Run()
if err != nil {
return errors.Wrap(err, "git push origin --tags")
return errors.Errorf("git push origin --tags: %w", err)
}

zerolog.Ctx(ctx).Debug().Msg("tag created")
Expand Down
8 changes: 4 additions & 4 deletions local_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,22 @@ func NewLocalProjectState(ctx context.Context, gp GitProvider, tr TagReader) (Ex

commit, err := gp.GetHeadRef(ctx)
if err != nil {
return nil, errors.Wrap(err, "error getting parent commit")
return nil, errors.Errorf("getting parent commit: %w", err)
}

branch, err := gp.Branch(ctx)
if err != nil {
return nil, errors.Wrap(err, "error getting branch")
return nil, errors.Errorf("getting branch: %w", err)
}

tags, err := tr.TagsFromBranch(ctx, branch)
if err != nil {
return nil, errors.Wrap(err, "error getting tags from branch")
return nil, errors.Errorf("getting tags from branch: %w", err)
}

dirty, err := gp.Dirty(ctx)
if err != nil {
return nil, errors.Wrap(err, "error getting dirty")
return nil, errors.Errorf("getting dirty: %w", err)
}

return &LocalProjectState{
Expand Down

0 comments on commit bdbd106

Please sign in to comment.