修复:空指针异常以及diff信息返回

This commit is contained in:
yystopf 2023-01-12 17:10:48 +08:00
parent 6fe8614ffe
commit 1983c14386
2 changed files with 3 additions and 5 deletions

View File

@ -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())

View File

@ -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
}
}