@@ -29,6 +29,17 @@ import (
2929 "github.com/gobwas/glob"
3030)
3131
32+ // getDiffOrPatch generates either diff or formatted patch data between given revisions
33+ func getDiffOrPatch (repo * git.Repository , compareString string , w io.Writer , patch , binary bool ) error {
34+ if patch {
35+ return repo .GetPatch (compareString , w )
36+ }
37+ if binary {
38+ return repo .GetDiffBinary (compareString , w )
39+ }
40+ return repo .GetDiff (compareString , w )
41+ }
42+
3243// DownloadDiffOrPatch will write the patch for the pr to the writer
3344func DownloadDiffOrPatch (ctx context.Context , pr * issues_model.PullRequest , w io.Writer , patch , binary bool ) error {
3445 if err := pr .LoadBaseRepo (ctx ); err != nil {
@@ -42,7 +53,7 @@ func DownloadDiffOrPatch(ctx context.Context, pr *issues_model.PullRequest, w io
4253 }
4354 defer closer .Close ()
4455
45- if err := gitRepo . GetDiffOrPatch ( pr .MergeBase + ".." + pr .GetGitRefName (), w , patch , binary ); err != nil {
56+ if err := getDiffOrPatch ( gitRepo , pr .MergeBase + ". .." + pr .GetGitRefName (), w , patch , binary ); err != nil {
4657 log .Error ("unable to get patch file from %s to %s in %s Error: %v" , pr .MergeBase , pr .HeadBranch , pr .BaseRepo .FullName (), err )
4758 return fmt .Errorf ("unable to get patch file from %s to %s in %s Error: %w" , pr .MergeBase , pr .HeadBranch , pr .BaseRepo .FullName (), err )
4859 }
0 commit comments