Skip to content

Commit

Permalink
fix(ghpr): Create diffs between commit pairs
Browse files Browse the repository at this point in the history
Signed-off-by: Cezar Craciunoiu <[email protected]>
  • Loading branch information
craciunoiuc authored and nderjung committed Dec 12, 2023
1 parent 771124f commit 7bb5e32
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions internal/ghpr/ghpr.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,27 +182,28 @@ func NewPullRequestFromID(ctx context.Context, client *ghapi.GithubClient, ghOrg
}

stopErr := errors.New("stop")
var lastCommit *gitobject.Commit
var prevCommit *gitobject.Commit

totalCommits := 0

pr.patches = make([]*patch.Patch, 0)

if err := itr.ForEach(func(commit *gitobject.Commit) error {
if lastCommit == nil {
lastCommit = commit
if prevCommit == nil {
prevCommit = commit
return nil
}

totalCommits++

p, err := patch.NewPatchFromCommits(ctx, pr.localRepo, lastCommit, commit)
p, err := patch.NewPatchFromCommits(ctx, pr.localRepo, prevCommit, commit)
if err != nil {
return err
}

p.Filename = strings.ReplaceAll(p.Title, " ", "-")
p.Filename = strings.ReplaceAll(p.Filename, ":", "")
p.Filename = strings.ReplaceAll(p.Filename, ".", "")
p.Filename = strings.ReplaceAll(p.Filename, "/", "-")
p.Filename = strings.ReplaceAll(p.Filename, "?", "")
p.Filename = strings.ReplaceAll(p.Filename, "`", "")
Expand All @@ -214,6 +215,7 @@ func NewPullRequestFromID(ctx context.Context, client *ghapi.GithubClient, ghOrg
return stopErr
}

prevCommit = commit
return nil
}); err != nil && !errors.Is(err, stopErr) {
return nil, fmt.Errorf("could not iterate over log error: %w", err)
Expand Down

0 comments on commit 7bb5e32

Please sign in to comment.