mirror of
https://github.com/harness/drone.git
synced 2025-05-17 01:20:13 +08:00
Merge branch 'mg/pr-review/review-sha' of _OKE5H2PQKOUfzFFDuD4FA/default/CODE/gitness (#59)
This commit is contained in:
commit
b7e92c0ec2
@ -12,7 +12,6 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/harness/gitness/gitrpc"
|
"github.com/harness/gitness/gitrpc"
|
||||||
gitrpcenum "github.com/harness/gitness/gitrpc/enum"
|
|
||||||
"github.com/harness/gitness/internal/api/usererror"
|
"github.com/harness/gitness/internal/api/usererror"
|
||||||
"github.com/harness/gitness/internal/auth"
|
"github.com/harness/gitness/internal/auth"
|
||||||
"github.com/harness/gitness/internal/store"
|
"github.com/harness/gitness/internal/store"
|
||||||
@ -24,11 +23,16 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type ReviewSubmitInput struct {
|
type ReviewSubmitInput struct {
|
||||||
|
CommitSHA string `json:"commit_sha"`
|
||||||
Decision enum.PullReqReviewDecision `json:"decision"`
|
Decision enum.PullReqReviewDecision `json:"decision"`
|
||||||
Message string `json:"message"`
|
Message string `json:"message"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (in *ReviewSubmitInput) Validate() error {
|
func (in *ReviewSubmitInput) Validate() error {
|
||||||
|
if in.CommitSHA == "" {
|
||||||
|
return usererror.BadRequest("CommitSHA is a mandatory field")
|
||||||
|
}
|
||||||
|
|
||||||
decision, ok := in.Decision.Sanitize()
|
decision, ok := in.Decision.Sanitize()
|
||||||
if !ok || decision == enum.PullReqReviewDecisionPending {
|
if !ok || decision == enum.PullReqReviewDecisionPending {
|
||||||
msg := fmt.Sprintf("Decision must be: %q, %q or %q.",
|
msg := fmt.Sprintf("Decision must be: %q, %q or %q.",
|
||||||
@ -72,18 +76,15 @@ func (c *Controller) ReviewSubmit(
|
|||||||
return nil, usererror.BadRequest("Can't submit review to own pull requests.")
|
return nil, usererror.BadRequest("Can't submit review to own pull requests.")
|
||||||
}
|
}
|
||||||
|
|
||||||
ref, err := c.gitRPCClient.GetRef(ctx, gitrpc.GetRefParams{
|
commit, err := c.gitRPCClient.GetCommit(ctx, &gitrpc.GetCommitParams{
|
||||||
ReadParams: gitrpc.ReadParams{RepoUID: repo.GitUID},
|
ReadParams: gitrpc.ReadParams{RepoUID: repo.GitUID},
|
||||||
Name: pr.TargetBranch,
|
SHA: in.CommitSHA,
|
||||||
Type: gitrpcenum.RefTypeBranch,
|
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to get git branch sha: %w", err)
|
return nil, fmt.Errorf("failed to get git branch sha: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if ref.SHA == "" {
|
commitSHA := commit.Commit.SHA
|
||||||
return nil, usererror.BadRequest("Failed to get branch SHA. Does the branch still exist?")
|
|
||||||
}
|
|
||||||
|
|
||||||
var review *types.PullReqReview
|
var review *types.PullReqReview
|
||||||
|
|
||||||
@ -96,7 +97,7 @@ func (c *Controller) ReviewSubmit(
|
|||||||
Updated: now,
|
Updated: now,
|
||||||
PullReqID: pr.ID,
|
PullReqID: pr.ID,
|
||||||
Decision: in.Decision,
|
Decision: in.Decision,
|
||||||
SHA: ref.SHA,
|
SHA: commitSHA,
|
||||||
}
|
}
|
||||||
|
|
||||||
err = c.reviewStore.Create(ctx, review)
|
err = c.reviewStore.Create(ctx, review)
|
||||||
@ -104,7 +105,7 @@ func (c *Controller) ReviewSubmit(
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = c.updateReviewer(ctx, session, pr, review, ref.SHA)
|
_, err = c.updateReviewer(ctx, session, pr, review, commitSHA)
|
||||||
return err
|
return err
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -117,6 +118,7 @@ func (c *Controller) ReviewSubmit(
|
|||||||
}
|
}
|
||||||
|
|
||||||
payload := &types.PullRequestActivityPayloadReviewSubmit{
|
payload := &types.PullRequestActivityPayloadReviewSubmit{
|
||||||
|
CommitSHA: commitSHA,
|
||||||
Message: in.Message,
|
Message: in.Message,
|
||||||
Decision: in.Decision,
|
Decision: in.Decision,
|
||||||
}
|
}
|
||||||
|
@ -242,6 +242,7 @@ func (a *PullRequestActivityPayloadTitleChange) ActivityType() enum.PullReqActiv
|
|||||||
}
|
}
|
||||||
|
|
||||||
type PullRequestActivityPayloadReviewSubmit struct {
|
type PullRequestActivityPayloadReviewSubmit struct {
|
||||||
|
CommitSHA string `json:"commit_sha"`
|
||||||
Message string `json:"message,omitempty"`
|
Message string `json:"message,omitempty"`
|
||||||
Decision enum.PullReqReviewDecision `json:"decision"`
|
Decision enum.PullReqReviewDecision `json:"decision"`
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user