diff options
author | 赵智超 <1012112796@qq.com> | 2020-05-09 02:50:23 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-08 19:50:23 +0100 |
commit | 119173130af174e12bb3dcd6d3b88b3f7d5e9798 (patch) | |
tree | 76a2d9abe75546f045e89b8fe3a57caf11f30b4e /routers/api/v1 | |
parent | c58bc4bf804a3e8f92dd634974ed4f636893c9c1 (diff) | |
download | gitea-119173130af174e12bb3dcd6d3b88b3f7d5e9798.tar.gz gitea-119173130af174e12bb3dcd6d3b88b3f7d5e9798.zip |
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>
Diffstat (limited to 'routers/api/v1')
-rw-r--r-- | routers/api/v1/repo/pull_review.go | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/routers/api/v1/repo/pull_review.go b/routers/api/v1/repo/pull_review.go index b3772b00a9..44559d70ed 100644 --- a/routers/api/v1/repo/pull_review.go +++ b/routers/api/v1/repo/pull_review.go @@ -12,6 +12,7 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/convert" + "code.gitea.io/gitea/modules/git" api "code.gitea.io/gitea/modules/structs" "code.gitea.io/gitea/routers/api/v1/utils" pull_service "code.gitea.io/gitea/services/pull" @@ -313,6 +314,24 @@ func CreatePullReview(ctx *context.APIContext, opts api.CreatePullReviewOptions) 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 for _, c := range opts.Comments { line := c.NewLineNum |