mirror of
https://github.com/harness/drone.git
synced 2025-05-11 22:50:11 +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"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/harness/gitness/gitrpc/internal/streamio"
|
"github.com/harness/gitness/gitrpc/internal/streamio"
|
||||||
"github.com/harness/gitness/gitrpc/internal/types"
|
"github.com/harness/gitness/gitrpc/internal/types"
|
||||||
@ -224,7 +223,6 @@ type DiffCutOutput struct {
|
|||||||
Lines []string
|
Lines []string
|
||||||
MergeBaseSHA string
|
MergeBaseSHA string
|
||||||
LatestSourceSHA string
|
LatestSourceSHA string
|
||||||
AnyNew bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type DiffCutParams struct {
|
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")
|
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{
|
hunkHeader := types.HunkHeader{
|
||||||
OldLine: int(result.HunkHeader.OldLine),
|
OldLine: int(result.HunkHeader.OldLine),
|
||||||
OldSpan: int(result.HunkHeader.OldSpan),
|
OldSpan: int(result.HunkHeader.OldSpan),
|
||||||
@ -282,6 +272,5 @@ func (c *Client) DiffCut(ctx context.Context, params *DiffCutParams) (DiffCutOut
|
|||||||
Lines: result.Lines,
|
Lines: result.Lines,
|
||||||
MergeBaseSHA: result.MergeBaseSha,
|
MergeBaseSHA: result.MergeBaseSha,
|
||||||
LatestSourceSHA: result.LatestSourceSha,
|
LatestSourceSHA: result.LatestSourceSha,
|
||||||
AnyNew: anyNew,
|
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
@ -120,9 +120,10 @@ func (c *Controller) CommentCreate(
|
|||||||
|
|
||||||
setAsCodeComment(act, cut, in.Path, in.SourceCommitSHA)
|
setAsCodeComment(act, cut, in.Path, in.SourceCommitSHA)
|
||||||
_ = act.SetPayload(&types.PullRequestActivityPayloadCodeComment{
|
_ = act.SetPayload(&types.PullRequestActivityPayloadCodeComment{
|
||||||
Title: cut.LinesHeader,
|
Title: cut.LinesHeader,
|
||||||
Lines: cut.Lines,
|
Lines: cut.Lines,
|
||||||
AnyNew: cut.AnyNew,
|
LineStartNew: in.LineStartNew,
|
||||||
|
LineEndNew: in.LineEndNew,
|
||||||
})
|
})
|
||||||
|
|
||||||
err = c.writeActivity(ctx, pr, act)
|
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) {
|
func setAsCodeComment(a *types.PullReqActivity, cut gitrpc.DiffCutOutput, path, sourceCommitSHA string) {
|
||||||
var falseBool bool
|
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.Type = enum.PullReqActivityTypeCodeComment
|
||||||
a.Kind = enum.PullReqActivityKindChangeComment
|
a.Kind = enum.PullReqActivityKindChangeComment
|
||||||
a.Outdated = &falseBool
|
a.CodeComment = &types.CodeCommentFields{
|
||||||
a.CodeCommentMergeBaseSHA = &cut.MergeBaseSHA
|
Outdated: falseBool,
|
||||||
a.CodeCommentSourceSHA = &sourceCommitSHA
|
MergeBaseSHA: cut.MergeBaseSHA,
|
||||||
a.CodeCommentPath = &path
|
SourceSHA: sourceCommitSHA,
|
||||||
a.CodeCommentLineNew = &newLine
|
Path: path,
|
||||||
a.CodeCommentSpanNew = &newSpan
|
LineNew: cut.Header.NewLine,
|
||||||
a.CodeCommentLineOld = &oldLine
|
SpanNew: cut.Header.NewSpan,
|
||||||
a.CodeCommentSpanOld = &oldSpan
|
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 {
|
func mapPullReqActivity(act *pullReqActivity) *types.PullReqActivity {
|
||||||
m := &types.PullReqActivity{
|
m := &types.PullReqActivity{
|
||||||
ID: act.ID,
|
ID: act.ID,
|
||||||
Version: act.Version,
|
Version: act.Version,
|
||||||
CreatedBy: act.CreatedBy,
|
CreatedBy: act.CreatedBy,
|
||||||
Created: act.Created,
|
Created: act.Created,
|
||||||
Updated: act.Updated,
|
Updated: act.Updated,
|
||||||
Edited: act.Edited,
|
Edited: act.Edited,
|
||||||
Deleted: act.Deleted.Ptr(),
|
Deleted: act.Deleted.Ptr(),
|
||||||
ParentID: act.ParentID.Ptr(),
|
ParentID: act.ParentID.Ptr(),
|
||||||
RepoID: act.RepoID,
|
RepoID: act.RepoID,
|
||||||
PullReqID: act.PullReqID,
|
PullReqID: act.PullReqID,
|
||||||
Order: act.Order,
|
Order: act.Order,
|
||||||
SubOrder: act.SubOrder,
|
SubOrder: act.SubOrder,
|
||||||
ReplySeq: act.ReplySeq,
|
ReplySeq: act.ReplySeq,
|
||||||
Type: act.Type,
|
Type: act.Type,
|
||||||
Kind: act.Kind,
|
Kind: act.Kind,
|
||||||
Text: act.Text,
|
Text: act.Text,
|
||||||
PayloadRaw: act.Payload,
|
PayloadRaw: act.Payload,
|
||||||
Metadata: make(map[string]interface{}),
|
Metadata: make(map[string]interface{}),
|
||||||
ResolvedBy: act.ResolvedBy.Ptr(),
|
ResolvedBy: act.ResolvedBy.Ptr(),
|
||||||
Resolved: act.Resolved.Ptr(),
|
Resolved: act.Resolved.Ptr(),
|
||||||
Author: types.PrincipalInfo{},
|
Author: types.PrincipalInfo{},
|
||||||
Resolver: nil,
|
Resolver: nil,
|
||||||
Outdated: act.Outdated.Ptr(),
|
}
|
||||||
CodeCommentMergeBaseSHA: act.CodeCommentMergeBaseSHA.Ptr(),
|
if m.Type == enum.PullReqActivityTypeCodeComment && m.Kind == enum.PullReqActivityKindChangeComment {
|
||||||
CodeCommentSourceSHA: act.CodeCommentSourceSHA.Ptr(),
|
m.CodeComment = &types.CodeCommentFields{
|
||||||
CodeCommentPath: act.CodeCommentPath.Ptr(),
|
Outdated: act.Outdated.Bool,
|
||||||
CodeCommentLineNew: act.CodeCommentLineNew.Ptr(),
|
MergeBaseSHA: act.CodeCommentMergeBaseSHA.String,
|
||||||
CodeCommentSpanNew: act.CodeCommentSpanNew.Ptr(),
|
SourceSHA: act.CodeCommentSourceSHA.String,
|
||||||
CodeCommentLineOld: act.CodeCommentLineOld.Ptr(),
|
Path: act.CodeCommentPath.String,
|
||||||
CodeCommentSpanOld: act.CodeCommentSpanOld.Ptr(),
|
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)
|
_ = json.Unmarshal(act.Metadata, &m.Metadata)
|
||||||
@ -455,34 +459,36 @@ func mapPullReqActivity(act *pullReqActivity) *types.PullReqActivity {
|
|||||||
|
|
||||||
func mapInternalPullReqActivity(act *types.PullReqActivity) *pullReqActivity {
|
func mapInternalPullReqActivity(act *types.PullReqActivity) *pullReqActivity {
|
||||||
m := &pullReqActivity{
|
m := &pullReqActivity{
|
||||||
ID: act.ID,
|
ID: act.ID,
|
||||||
Version: act.Version,
|
Version: act.Version,
|
||||||
CreatedBy: act.CreatedBy,
|
CreatedBy: act.CreatedBy,
|
||||||
Created: act.Created,
|
Created: act.Created,
|
||||||
Updated: act.Updated,
|
Updated: act.Updated,
|
||||||
Edited: act.Edited,
|
Edited: act.Edited,
|
||||||
Deleted: null.IntFromPtr(act.Deleted),
|
Deleted: null.IntFromPtr(act.Deleted),
|
||||||
ParentID: null.IntFromPtr(act.ParentID),
|
ParentID: null.IntFromPtr(act.ParentID),
|
||||||
RepoID: act.RepoID,
|
RepoID: act.RepoID,
|
||||||
PullReqID: act.PullReqID,
|
PullReqID: act.PullReqID,
|
||||||
Order: act.Order,
|
Order: act.Order,
|
||||||
SubOrder: act.SubOrder,
|
SubOrder: act.SubOrder,
|
||||||
ReplySeq: act.ReplySeq,
|
ReplySeq: act.ReplySeq,
|
||||||
Type: act.Type,
|
Type: act.Type,
|
||||||
Kind: act.Kind,
|
Kind: act.Kind,
|
||||||
Text: act.Text,
|
Text: act.Text,
|
||||||
Payload: act.PayloadRaw,
|
Payload: act.PayloadRaw,
|
||||||
Metadata: nil,
|
Metadata: nil,
|
||||||
ResolvedBy: null.IntFromPtr(act.ResolvedBy),
|
ResolvedBy: null.IntFromPtr(act.ResolvedBy),
|
||||||
Resolved: null.IntFromPtr(act.Resolved),
|
Resolved: null.IntFromPtr(act.Resolved),
|
||||||
Outdated: null.BoolFromPtr(act.Outdated),
|
}
|
||||||
CodeCommentMergeBaseSHA: null.StringFromPtr(act.CodeCommentMergeBaseSHA),
|
if act.IsValidCodeComment() {
|
||||||
CodeCommentSourceSHA: null.StringFromPtr(act.CodeCommentSourceSHA),
|
m.Outdated = null.BoolFrom(act.CodeComment.Outdated)
|
||||||
CodeCommentPath: null.StringFromPtr(act.CodeCommentPath),
|
m.CodeCommentMergeBaseSHA = null.StringFrom(act.CodeComment.MergeBaseSHA)
|
||||||
CodeCommentLineNew: null.IntFromPtr(act.CodeCommentLineNew),
|
m.CodeCommentSourceSHA = null.StringFrom(act.CodeComment.SourceSHA)
|
||||||
CodeCommentSpanNew: null.IntFromPtr(act.CodeCommentSpanNew),
|
m.CodeCommentPath = null.StringFrom(act.CodeComment.Path)
|
||||||
CodeCommentLineOld: null.IntFromPtr(act.CodeCommentLineOld),
|
m.CodeCommentLineNew = null.IntFrom(int64(act.CodeComment.LineNew))
|
||||||
CodeCommentSpanOld: null.IntFromPtr(act.CodeCommentSpanOld),
|
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)
|
m.Metadata, _ = json.Marshal(act.Metadata)
|
||||||
|
@ -9,12 +9,16 @@ type CodeComment struct {
|
|||||||
Version int64 `db:"pullreq_activity_version"`
|
Version int64 `db:"pullreq_activity_version"`
|
||||||
Updated int64 `db:"pullreq_activity_updated"`
|
Updated int64 `db:"pullreq_activity_updated"`
|
||||||
|
|
||||||
Outdated bool `db:"pullreq_activity_outdated"`
|
CodeCommentFields
|
||||||
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"`
|
type CodeCommentFields struct {
|
||||||
LineNew int `db:"pullreq_activity_code_comment_line_new"`
|
Outdated bool `db:"pullreq_activity_outdated" json:"outdated"`
|
||||||
SpanNew int `db:"pullreq_activity_code_comment_span_new"`
|
MergeBaseSHA string `db:"pullreq_activity_code_comment_merge_base_sha" json:"merge_base_sha"`
|
||||||
LineOld int `db:"pullreq_activity_code_comment_line_old"`
|
SourceSHA string `db:"pullreq_activity_code_comment_source_sha" json:"source_sha"`
|
||||||
SpanOld int `db:"pullreq_activity_code_comment_span_old"`
|
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"`
|
Author PrincipalInfo `json:"author"`
|
||||||
Resolver *PrincipalInfo `json:"resolver,omitempty"`
|
Resolver *PrincipalInfo `json:"resolver,omitempty"`
|
||||||
|
|
||||||
Outdated *bool `json:"outdated,omitempty"`
|
CodeComment *CodeCommentFields `json:"code_comment,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"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *PullReqActivity) IsValidCodeComment() bool {
|
func (a *PullReqActivity) IsValidCodeComment() bool {
|
||||||
return a.Type == enum.PullReqActivityTypeCodeComment &&
|
return a.Type == enum.PullReqActivityTypeCodeComment &&
|
||||||
a.Kind == enum.PullReqActivityKindChangeComment &&
|
a.Kind == enum.PullReqActivityKindChangeComment &&
|
||||||
a.CodeCommentMergeBaseSHA != nil &&
|
a.CodeComment != nil
|
||||||
a.CodeCommentSourceSHA != nil &&
|
|
||||||
a.CodeCommentPath != nil &&
|
|
||||||
a.CodeCommentLineNew != nil &&
|
|
||||||
a.CodeCommentSpanNew != nil &&
|
|
||||||
a.CodeCommentLineOld != nil &&
|
|
||||||
a.CodeCommentSpanOld != nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *PullReqActivity) AsCodeComment() *CodeComment {
|
func (a *PullReqActivity) AsCodeComment() *CodeComment {
|
||||||
@ -80,17 +67,19 @@ func (a *PullReqActivity) AsCodeComment() *CodeComment {
|
|||||||
return &CodeComment{}
|
return &CodeComment{}
|
||||||
}
|
}
|
||||||
return &CodeComment{
|
return &CodeComment{
|
||||||
ID: a.ID,
|
ID: a.ID,
|
||||||
Version: a.Version,
|
Version: a.Version,
|
||||||
Updated: a.Updated,
|
Updated: a.Updated,
|
||||||
Outdated: *a.Outdated,
|
CodeCommentFields: CodeCommentFields{
|
||||||
MergeBaseSHA: *a.CodeCommentMergeBaseSHA,
|
Outdated: a.CodeComment.Outdated,
|
||||||
SourceSHA: *a.CodeCommentSourceSHA,
|
MergeBaseSHA: a.CodeComment.MergeBaseSHA,
|
||||||
Path: *a.CodeCommentPath,
|
SourceSHA: a.CodeComment.SourceSHA,
|
||||||
LineNew: int(*a.CodeCommentLineNew),
|
Path: a.CodeComment.Path,
|
||||||
SpanNew: int(*a.CodeCommentSpanNew),
|
LineNew: a.CodeComment.LineNew,
|
||||||
LineOld: int(*a.CodeCommentLineOld),
|
SpanNew: a.CodeComment.SpanNew,
|
||||||
SpanOld: int(*a.CodeCommentSpanOld),
|
LineOld: a.CodeComment.LineOld,
|
||||||
|
SpanOld: a.CodeComment.SpanOld,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -205,9 +194,10 @@ func (a PullRequestActivityPayloadComment) ActivityType() enum.PullReqActivityTy
|
|||||||
}
|
}
|
||||||
|
|
||||||
type PullRequestActivityPayloadCodeComment struct {
|
type PullRequestActivityPayloadCodeComment struct {
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
Lines []string `json:"lines"`
|
Lines []string `json:"lines"`
|
||||||
AnyNew bool `json:"any_new"`
|
LineStartNew bool `json:"line_start_new"`
|
||||||
|
LineEndNew bool `json:"line_end_new"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *PullRequestActivityPayloadCodeComment) ActivityType() enum.PullReqActivityType {
|
func (a *PullRequestActivityPayloadCodeComment) ActivityType() enum.PullReqActivityType {
|
||||||
|
Loading…
Reference in New Issue
Block a user