mirror of
https://github.com/harness/drone.git
synced 2025-05-08 12:00:02 +08:00
return old/new-line-new values used to create cc
This commit is contained in:
parent
b2e11103af
commit
de0ab2bc75
@ -9,7 +9,6 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"strings"
|
||||
|
||||
"github.com/harness/gitness/gitrpc/internal/streamio"
|
||||
"github.com/harness/gitness/gitrpc/internal/types"
|
||||
@ -224,7 +223,6 @@ type DiffCutOutput struct {
|
||||
Lines []string
|
||||
MergeBaseSHA string
|
||||
LatestSourceSHA string
|
||||
AnyNew bool
|
||||
}
|
||||
|
||||
type DiffCutParams struct {
|
||||
@ -260,14 +258,6 @@ func (c *Client) DiffCut(ctx context.Context, params *DiffCutParams) (DiffCutOut
|
||||
return DiffCutOutput{}, processRPCErrorf(err, "failed to get git diff sub hunk")
|
||||
}
|
||||
|
||||
var anyNew bool
|
||||
for _, line := range result.Lines {
|
||||
if strings.HasPrefix(line, "+") {
|
||||
anyNew = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
hunkHeader := types.HunkHeader{
|
||||
OldLine: int(result.HunkHeader.OldLine),
|
||||
OldSpan: int(result.HunkHeader.OldSpan),
|
||||
@ -282,6 +272,5 @@ func (c *Client) DiffCut(ctx context.Context, params *DiffCutParams) (DiffCutOut
|
||||
Lines: result.Lines,
|
||||
MergeBaseSHA: result.MergeBaseSha,
|
||||
LatestSourceSHA: result.LatestSourceSha,
|
||||
AnyNew: anyNew,
|
||||
}, nil
|
||||
}
|
||||
|
@ -120,9 +120,10 @@ func (c *Controller) CommentCreate(
|
||||
|
||||
setAsCodeComment(act, cut, in.Path, in.SourceCommitSHA)
|
||||
_ = act.SetPayload(&types.PullRequestActivityPayloadCodeComment{
|
||||
Title: cut.LinesHeader,
|
||||
Lines: cut.Lines,
|
||||
AnyNew: cut.AnyNew,
|
||||
Title: cut.LinesHeader,
|
||||
Lines: cut.Lines,
|
||||
LineStartNew: in.LineStartNew,
|
||||
LineEndNew: in.LineEndNew,
|
||||
})
|
||||
|
||||
err = c.writeActivity(ctx, pr, act)
|
||||
@ -273,19 +274,16 @@ func getCommentActivity(session *auth.Session, pr *types.PullReq, in *CommentCre
|
||||
|
||||
func setAsCodeComment(a *types.PullReqActivity, cut gitrpc.DiffCutOutput, path, sourceCommitSHA string) {
|
||||
var falseBool bool
|
||||
newLine := int64(cut.Header.NewLine)
|
||||
newSpan := int64(cut.Header.NewSpan)
|
||||
oldLine := int64(cut.Header.OldLine)
|
||||
oldSpan := int64(cut.Header.OldSpan)
|
||||
|
||||
a.Type = enum.PullReqActivityTypeCodeComment
|
||||
a.Kind = enum.PullReqActivityKindChangeComment
|
||||
a.Outdated = &falseBool
|
||||
a.CodeCommentMergeBaseSHA = &cut.MergeBaseSHA
|
||||
a.CodeCommentSourceSHA = &sourceCommitSHA
|
||||
a.CodeCommentPath = &path
|
||||
a.CodeCommentLineNew = &newLine
|
||||
a.CodeCommentSpanNew = &newSpan
|
||||
a.CodeCommentLineOld = &oldLine
|
||||
a.CodeCommentSpanOld = &oldSpan
|
||||
a.CodeComment = &types.CodeCommentFields{
|
||||
Outdated: falseBool,
|
||||
MergeBaseSHA: cut.MergeBaseSHA,
|
||||
SourceSHA: sourceCommitSHA,
|
||||
Path: path,
|
||||
LineNew: cut.Header.NewLine,
|
||||
SpanNew: cut.Header.NewSpan,
|
||||
LineOld: cut.Header.OldLine,
|
||||
SpanOld: cut.Header.OldSpan,
|
||||
}
|
||||
}
|
||||
|
@ -416,36 +416,40 @@ func (s *PullReqActivityStore) List(ctx context.Context, prID int64,
|
||||
|
||||
func mapPullReqActivity(act *pullReqActivity) *types.PullReqActivity {
|
||||
m := &types.PullReqActivity{
|
||||
ID: act.ID,
|
||||
Version: act.Version,
|
||||
CreatedBy: act.CreatedBy,
|
||||
Created: act.Created,
|
||||
Updated: act.Updated,
|
||||
Edited: act.Edited,
|
||||
Deleted: act.Deleted.Ptr(),
|
||||
ParentID: act.ParentID.Ptr(),
|
||||
RepoID: act.RepoID,
|
||||
PullReqID: act.PullReqID,
|
||||
Order: act.Order,
|
||||
SubOrder: act.SubOrder,
|
||||
ReplySeq: act.ReplySeq,
|
||||
Type: act.Type,
|
||||
Kind: act.Kind,
|
||||
Text: act.Text,
|
||||
PayloadRaw: act.Payload,
|
||||
Metadata: make(map[string]interface{}),
|
||||
ResolvedBy: act.ResolvedBy.Ptr(),
|
||||
Resolved: act.Resolved.Ptr(),
|
||||
Author: types.PrincipalInfo{},
|
||||
Resolver: nil,
|
||||
Outdated: act.Outdated.Ptr(),
|
||||
CodeCommentMergeBaseSHA: act.CodeCommentMergeBaseSHA.Ptr(),
|
||||
CodeCommentSourceSHA: act.CodeCommentSourceSHA.Ptr(),
|
||||
CodeCommentPath: act.CodeCommentPath.Ptr(),
|
||||
CodeCommentLineNew: act.CodeCommentLineNew.Ptr(),
|
||||
CodeCommentSpanNew: act.CodeCommentSpanNew.Ptr(),
|
||||
CodeCommentLineOld: act.CodeCommentLineOld.Ptr(),
|
||||
CodeCommentSpanOld: act.CodeCommentSpanOld.Ptr(),
|
||||
ID: act.ID,
|
||||
Version: act.Version,
|
||||
CreatedBy: act.CreatedBy,
|
||||
Created: act.Created,
|
||||
Updated: act.Updated,
|
||||
Edited: act.Edited,
|
||||
Deleted: act.Deleted.Ptr(),
|
||||
ParentID: act.ParentID.Ptr(),
|
||||
RepoID: act.RepoID,
|
||||
PullReqID: act.PullReqID,
|
||||
Order: act.Order,
|
||||
SubOrder: act.SubOrder,
|
||||
ReplySeq: act.ReplySeq,
|
||||
Type: act.Type,
|
||||
Kind: act.Kind,
|
||||
Text: act.Text,
|
||||
PayloadRaw: act.Payload,
|
||||
Metadata: make(map[string]interface{}),
|
||||
ResolvedBy: act.ResolvedBy.Ptr(),
|
||||
Resolved: act.Resolved.Ptr(),
|
||||
Author: types.PrincipalInfo{},
|
||||
Resolver: nil,
|
||||
}
|
||||
if m.Type == enum.PullReqActivityTypeCodeComment && m.Kind == enum.PullReqActivityKindChangeComment {
|
||||
m.CodeComment = &types.CodeCommentFields{
|
||||
Outdated: act.Outdated.Bool,
|
||||
MergeBaseSHA: act.CodeCommentMergeBaseSHA.String,
|
||||
SourceSHA: act.CodeCommentSourceSHA.String,
|
||||
Path: act.CodeCommentPath.String,
|
||||
LineNew: int(act.CodeCommentLineNew.Int64),
|
||||
SpanNew: int(act.CodeCommentSpanNew.Int64),
|
||||
LineOld: int(act.CodeCommentLineOld.Int64),
|
||||
SpanOld: int(act.CodeCommentSpanOld.Int64),
|
||||
}
|
||||
}
|
||||
|
||||
_ = json.Unmarshal(act.Metadata, &m.Metadata)
|
||||
@ -455,34 +459,36 @@ func mapPullReqActivity(act *pullReqActivity) *types.PullReqActivity {
|
||||
|
||||
func mapInternalPullReqActivity(act *types.PullReqActivity) *pullReqActivity {
|
||||
m := &pullReqActivity{
|
||||
ID: act.ID,
|
||||
Version: act.Version,
|
||||
CreatedBy: act.CreatedBy,
|
||||
Created: act.Created,
|
||||
Updated: act.Updated,
|
||||
Edited: act.Edited,
|
||||
Deleted: null.IntFromPtr(act.Deleted),
|
||||
ParentID: null.IntFromPtr(act.ParentID),
|
||||
RepoID: act.RepoID,
|
||||
PullReqID: act.PullReqID,
|
||||
Order: act.Order,
|
||||
SubOrder: act.SubOrder,
|
||||
ReplySeq: act.ReplySeq,
|
||||
Type: act.Type,
|
||||
Kind: act.Kind,
|
||||
Text: act.Text,
|
||||
Payload: act.PayloadRaw,
|
||||
Metadata: nil,
|
||||
ResolvedBy: null.IntFromPtr(act.ResolvedBy),
|
||||
Resolved: null.IntFromPtr(act.Resolved),
|
||||
Outdated: null.BoolFromPtr(act.Outdated),
|
||||
CodeCommentMergeBaseSHA: null.StringFromPtr(act.CodeCommentMergeBaseSHA),
|
||||
CodeCommentSourceSHA: null.StringFromPtr(act.CodeCommentSourceSHA),
|
||||
CodeCommentPath: null.StringFromPtr(act.CodeCommentPath),
|
||||
CodeCommentLineNew: null.IntFromPtr(act.CodeCommentLineNew),
|
||||
CodeCommentSpanNew: null.IntFromPtr(act.CodeCommentSpanNew),
|
||||
CodeCommentLineOld: null.IntFromPtr(act.CodeCommentLineOld),
|
||||
CodeCommentSpanOld: null.IntFromPtr(act.CodeCommentSpanOld),
|
||||
ID: act.ID,
|
||||
Version: act.Version,
|
||||
CreatedBy: act.CreatedBy,
|
||||
Created: act.Created,
|
||||
Updated: act.Updated,
|
||||
Edited: act.Edited,
|
||||
Deleted: null.IntFromPtr(act.Deleted),
|
||||
ParentID: null.IntFromPtr(act.ParentID),
|
||||
RepoID: act.RepoID,
|
||||
PullReqID: act.PullReqID,
|
||||
Order: act.Order,
|
||||
SubOrder: act.SubOrder,
|
||||
ReplySeq: act.ReplySeq,
|
||||
Type: act.Type,
|
||||
Kind: act.Kind,
|
||||
Text: act.Text,
|
||||
Payload: act.PayloadRaw,
|
||||
Metadata: nil,
|
||||
ResolvedBy: null.IntFromPtr(act.ResolvedBy),
|
||||
Resolved: null.IntFromPtr(act.Resolved),
|
||||
}
|
||||
if act.IsValidCodeComment() {
|
||||
m.Outdated = null.BoolFrom(act.CodeComment.Outdated)
|
||||
m.CodeCommentMergeBaseSHA = null.StringFrom(act.CodeComment.MergeBaseSHA)
|
||||
m.CodeCommentSourceSHA = null.StringFrom(act.CodeComment.SourceSHA)
|
||||
m.CodeCommentPath = null.StringFrom(act.CodeComment.Path)
|
||||
m.CodeCommentLineNew = null.IntFrom(int64(act.CodeComment.LineNew))
|
||||
m.CodeCommentSpanNew = null.IntFrom(int64(act.CodeComment.SpanNew))
|
||||
m.CodeCommentLineOld = null.IntFrom(int64(act.CodeComment.LineOld))
|
||||
m.CodeCommentSpanOld = null.IntFrom(int64(act.CodeComment.SpanOld))
|
||||
}
|
||||
|
||||
m.Metadata, _ = json.Marshal(act.Metadata)
|
||||
|
@ -9,12 +9,16 @@ type CodeComment struct {
|
||||
Version int64 `db:"pullreq_activity_version"`
|
||||
Updated int64 `db:"pullreq_activity_updated"`
|
||||
|
||||
Outdated bool `db:"pullreq_activity_outdated"`
|
||||
MergeBaseSHA string `db:"pullreq_activity_code_comment_merge_base_sha"`
|
||||
SourceSHA string `db:"pullreq_activity_code_comment_source_sha"`
|
||||
Path string `db:"pullreq_activity_code_comment_path"`
|
||||
LineNew int `db:"pullreq_activity_code_comment_line_new"`
|
||||
SpanNew int `db:"pullreq_activity_code_comment_span_new"`
|
||||
LineOld int `db:"pullreq_activity_code_comment_line_old"`
|
||||
SpanOld int `db:"pullreq_activity_code_comment_span_old"`
|
||||
CodeCommentFields
|
||||
}
|
||||
|
||||
type CodeCommentFields struct {
|
||||
Outdated bool `db:"pullreq_activity_outdated" json:"outdated"`
|
||||
MergeBaseSHA string `db:"pullreq_activity_code_comment_merge_base_sha" json:"merge_base_sha"`
|
||||
SourceSHA string `db:"pullreq_activity_code_comment_source_sha" json:"source_sha"`
|
||||
Path string `db:"pullreq_activity_code_comment_path" json:"path"`
|
||||
LineNew int `db:"pullreq_activity_code_comment_line_new" json:"line_new"`
|
||||
SpanNew int `db:"pullreq_activity_code_comment_span_new" json:"span_new"`
|
||||
LineOld int `db:"pullreq_activity_code_comment_line_old" json:"line_old"`
|
||||
SpanOld int `db:"pullreq_activity_code_comment_span_old" json:"span_old"`
|
||||
}
|
||||
|
@ -53,26 +53,13 @@ type PullReqActivity struct {
|
||||
Author PrincipalInfo `json:"author"`
|
||||
Resolver *PrincipalInfo `json:"resolver,omitempty"`
|
||||
|
||||
Outdated *bool `json:"outdated,omitempty"`
|
||||
CodeCommentMergeBaseSHA *string `json:"code_comment_merge_base_sha,omitempty"`
|
||||
CodeCommentSourceSHA *string `json:"code_comment_source_sha,omitempty"`
|
||||
CodeCommentPath *string `json:"code_comment_path,omitempty"`
|
||||
CodeCommentLineNew *int64 `json:"code_comment_line_new,omitempty"`
|
||||
CodeCommentSpanNew *int64 `json:"code_comment_span_new,omitempty"`
|
||||
CodeCommentLineOld *int64 `json:"code_comment_line_old,omitempty"`
|
||||
CodeCommentSpanOld *int64 `json:"code_comment_span_old,omitempty"`
|
||||
CodeComment *CodeCommentFields `json:"code_comment,omitempty"`
|
||||
}
|
||||
|
||||
func (a *PullReqActivity) IsValidCodeComment() bool {
|
||||
return a.Type == enum.PullReqActivityTypeCodeComment &&
|
||||
a.Kind == enum.PullReqActivityKindChangeComment &&
|
||||
a.CodeCommentMergeBaseSHA != nil &&
|
||||
a.CodeCommentSourceSHA != nil &&
|
||||
a.CodeCommentPath != nil &&
|
||||
a.CodeCommentLineNew != nil &&
|
||||
a.CodeCommentSpanNew != nil &&
|
||||
a.CodeCommentLineOld != nil &&
|
||||
a.CodeCommentSpanOld != nil
|
||||
a.CodeComment != nil
|
||||
}
|
||||
|
||||
func (a *PullReqActivity) AsCodeComment() *CodeComment {
|
||||
@ -80,17 +67,19 @@ func (a *PullReqActivity) AsCodeComment() *CodeComment {
|
||||
return &CodeComment{}
|
||||
}
|
||||
return &CodeComment{
|
||||
ID: a.ID,
|
||||
Version: a.Version,
|
||||
Updated: a.Updated,
|
||||
Outdated: *a.Outdated,
|
||||
MergeBaseSHA: *a.CodeCommentMergeBaseSHA,
|
||||
SourceSHA: *a.CodeCommentSourceSHA,
|
||||
Path: *a.CodeCommentPath,
|
||||
LineNew: int(*a.CodeCommentLineNew),
|
||||
SpanNew: int(*a.CodeCommentSpanNew),
|
||||
LineOld: int(*a.CodeCommentLineOld),
|
||||
SpanOld: int(*a.CodeCommentSpanOld),
|
||||
ID: a.ID,
|
||||
Version: a.Version,
|
||||
Updated: a.Updated,
|
||||
CodeCommentFields: CodeCommentFields{
|
||||
Outdated: a.CodeComment.Outdated,
|
||||
MergeBaseSHA: a.CodeComment.MergeBaseSHA,
|
||||
SourceSHA: a.CodeComment.SourceSHA,
|
||||
Path: a.CodeComment.Path,
|
||||
LineNew: a.CodeComment.LineNew,
|
||||
SpanNew: a.CodeComment.SpanNew,
|
||||
LineOld: a.CodeComment.LineOld,
|
||||
SpanOld: a.CodeComment.SpanOld,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@ -205,9 +194,10 @@ func (a PullRequestActivityPayloadComment) ActivityType() enum.PullReqActivityTy
|
||||
}
|
||||
|
||||
type PullRequestActivityPayloadCodeComment struct {
|
||||
Title string `json:"title"`
|
||||
Lines []string `json:"lines"`
|
||||
AnyNew bool `json:"any_new"`
|
||||
Title string `json:"title"`
|
||||
Lines []string `json:"lines"`
|
||||
LineStartNew bool `json:"line_start_new"`
|
||||
LineEndNew bool `json:"line_end_new"`
|
||||
}
|
||||
|
||||
func (a *PullRequestActivityPayloadCodeComment) ActivityType() enum.PullReqActivityType {
|
||||
|
Loading…
Reference in New Issue
Block a user