From 1983c143863647a40f76a2fdac13b0649f0a7c4b Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 12 Jan 2023 17:10:48 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E7=A9=BA=E6=8C=87?= =?UTF-8?q?=E9=92=88=E5=BC=82=E5=B8=B8=E4=BB=A5=E5=8F=8Adiff=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E8=BF=94=E5=9B=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- routers/hat/hat.go | 1 + routers/hat/repo/pull_version.go | 7 ++----- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/routers/hat/hat.go b/routers/hat/hat.go index 3e871f8..1ff0d48 100644 --- a/routers/hat/hat.go +++ b/routers/hat/hat.go @@ -102,6 +102,7 @@ func Routers(ctx gocontext.Context) *web.Route { m.Get("/files", context.RepoRef(), repo.GetPullFiles) m.Group("/versions", func() { m.Get("", repo.ListPullRequestVersions) + m.Get("/{versionId}/diff", context.RepoRef(), repo.GetPullRequestVersionDiff) }) }) }, mustAllowPulls, reqRepoReader(unit_model.TypeCode), context.ReferencesGitRepo()) diff --git a/routers/hat/repo/pull_version.go b/routers/hat/repo/pull_version.go index d4eaea9..0527273 100644 --- a/routers/hat/repo/pull_version.go +++ b/routers/hat/repo/pull_version.go @@ -18,7 +18,7 @@ import ( ) func ListPullRequestVersions(ctx *context.APIContext) { - pr, err := issues_model.GetPullRequestByIndex(ctx, ctx.Repo.Repository.RepoID, ctx.ParamsInt64(":index")) + pr, err := issues_model.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, ctx.ParamsInt64(":index")) if err != nil { if issues_model.IsErrPullRequestNotExist(err) { ctx.NotFound() @@ -89,7 +89,7 @@ func GetPullRequestVersionDiff(ctx *context.APIContext) { if filepath == "" { ctx.JSON(http.StatusOK, diffs) } else { - var targetDiffFile *hat_gitdiff.DiffFile + targetDiffFile := &hat_gitdiff.DiffFile{} for _, file := range diffs.Files { if file.Name == filepath { if diffString, err := hat_git.GetDiffStringByFilePath(ctx.Repo.GitRepo, prv.BaseCommitID, prv.HeadCommitID, file.Name); err == nil { @@ -117,9 +117,6 @@ func GetPullRequestVersionDiff(ctx *context.APIContext) { } targetDiffFile.Diff = strings.Join(afterStrings, "\n") } - targetDiffFile = &hat_gitdiff.DiffFile{ - DiffFile: *file, - } break } }