Add default CommitID for create pull review api (#11334)

If user create pull review through api but not set CommitID,
I think it's necessary to use last headCommitID as default seting,
or this review will be considered as stale review which is wrong

Signed-off-by: a1012112796 <1012112796@qq.com>
tokarchuk/v1.17
赵智超 5 years ago committed by GitHub
parent c58bc4bf80
commit 119173130a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 19
      routers/api/v1/repo/pull_review.go

@ -12,6 +12,7 @@ import (
"code.gitea.io/gitea/models" "code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/convert" "code.gitea.io/gitea/modules/convert"
"code.gitea.io/gitea/modules/git"
api "code.gitea.io/gitea/modules/structs" api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/routers/api/v1/utils" "code.gitea.io/gitea/routers/api/v1/utils"
pull_service "code.gitea.io/gitea/services/pull" pull_service "code.gitea.io/gitea/services/pull"
@ -313,6 +314,24 @@ func CreatePullReview(ctx *context.APIContext, opts api.CreatePullReviewOptions)
return return
} }
// if CommitID is empty, set it as lastCommitID
if opts.CommitID == "" {
gitRepo, err := git.OpenRepository(pr.Issue.Repo.RepoPath())
if err != nil {
ctx.ServerError("git.OpenRepository", err)
return
}
defer gitRepo.Close()
headCommitID, err := gitRepo.GetRefCommitID(pr.GetGitRefName())
if err != nil {
ctx.ServerError("GetRefCommitID", err)
return
}
opts.CommitID = headCommitID
}
// create review comments // create review comments
for _, c := range opts.Comments { for _, c := range opts.Comments {
line := c.NewLineNum line := c.NewLineNum

Loading…
Cancel
Save