Merge branch 'mg/code-comments/fix-line-numbers' of _OKE5H2PQKOUfzFFDuD4FA/default/CODE/gitness (#45)

This commit is contained in:
Marko Gacesa 2023-04-28 12:03:49 +00:00 committed by Harness
commit 70648fcbbc
10 changed files with 110 additions and 80 deletions

View File

@ -220,6 +220,7 @@ func (c *Client) GetDiffHunkHeaders(
type DiffCutOutput struct { type DiffCutOutput struct {
Header HunkHeader Header HunkHeader
LinesHeader string
Lines []string Lines []string
MergeBaseSHA string MergeBaseSHA string
LatestSourceSHA string LatestSourceSHA string
@ -277,6 +278,7 @@ func (c *Client) DiffCut(ctx context.Context, params *DiffCutParams) (DiffCutOut
return DiffCutOutput{ return DiffCutOutput{
Header: HunkHeader(hunkHeader), Header: HunkHeader(hunkHeader),
LinesHeader: result.LinesHeader,
Lines: result.Lines, Lines: result.Lines,
MergeBaseSHA: result.MergeBaseSha, MergeBaseSHA: result.MergeBaseSha,
LatestSourceSHA: result.LatestSourceSha, LatestSourceSHA: result.LatestSourceSha,

View File

@ -122,7 +122,7 @@ func (g Adapter) DiffCut(
ctx context.Context, ctx context.Context,
repoPath, targetRef, sourceRef, path string, repoPath, targetRef, sourceRef, path string,
params types.DiffCutParams, params types.DiffCutParams,
) (types.Hunk, error) { ) (types.HunkHeader, types.Hunk, error) {
pipeRead, pipeWrite := io.Pipe() pipeRead, pipeWrite := io.Pipe()
stderr := &bytes.Buffer{} stderr := &bytes.Buffer{}
go func() { go func() {
@ -143,19 +143,19 @@ func (g Adapter) DiffCut(
}) })
}() }()
hunk, err := parser.DiffCut(pipeRead, params) diffCutHeader, linesHunk, err := parser.DiffCut(pipeRead, params)
// First check if there's something in the stderr buffer, if yes that's the error // First check if there's something in the stderr buffer, if yes that's the error
if errStderr := parseDiffStderr(stderr); errStderr != nil { if errStderr := parseDiffStderr(stderr); errStderr != nil {
return types.Hunk{}, errStderr return types.HunkHeader{}, types.Hunk{}, errStderr
} }
// Next check if reading the git diff output caused an error // Next check if reading the git diff output caused an error
if err != nil { if err != nil {
return types.Hunk{}, err return types.HunkHeader{}, types.Hunk{}, err
} }
return hunk, nil return diffCutHeader, linesHunk, nil
} }
func parseDiffStderr(stderr *bytes.Buffer) error { func parseDiffStderr(stderr *bytes.Buffer) error {

View File

@ -17,18 +17,18 @@ import (
// and returns lines specified with the parameters. // and returns lines specified with the parameters.
// //
//nolint:funlen,gocognit,nestif,gocognit,gocyclo,cyclop // it's actually very readable //nolint:funlen,gocognit,nestif,gocognit,gocyclo,cyclop // it's actually very readable
func DiffCut(r io.Reader, params types.DiffCutParams) (types.Hunk, error) { func DiffCut(r io.Reader, params types.DiffCutParams) (types.HunkHeader, types.Hunk, error) {
scanner := bufio.NewScanner(r) scanner := bufio.NewScanner(r)
var err error var err error
var hunkHeader types.HunkHeader var hunkHeader types.HunkHeader
if _, err = scanFileHeader(scanner); err != nil { if _, err = scanFileHeader(scanner); err != nil {
return types.Hunk{}, err return types.HunkHeader{}, types.Hunk{}, err
} }
if hunkHeader, err = scanHunkHeader(scanner); err != nil { if hunkHeader, err = scanHunkHeader(scanner); err != nil {
return types.Hunk{}, err return types.HunkHeader{}, types.Hunk{}, err
} }
currentOldLine := hunkHeader.OldLine currentOldLine := hunkHeader.OldLine
@ -51,7 +51,7 @@ func DiffCut(r io.Reader, params types.DiffCutParams) (types.Hunk, error) {
line, action, err = scanHunkLine(scanner) line, action, err = scanHunkLine(scanner)
if err != nil { if err != nil {
return types.Hunk{}, err return types.HunkHeader{}, types.Hunk{}, err
} }
if line == "" { if line == "" {
@ -93,7 +93,7 @@ func DiffCut(r io.Reader, params types.DiffCutParams) (types.Hunk, error) {
} }
if !inCut { if !inCut {
return types.Hunk{}, types.ErrHunkNotFound return types.HunkHeader{}, types.Hunk{}, types.ErrHunkNotFound
} }
var ( var (
@ -111,34 +111,36 @@ func DiffCut(r io.Reader, params types.DiffCutParams) (types.Hunk, error) {
linesAfter = append(linesAfter, line) linesAfter = append(linesAfter, line)
} }
if err = scanner.Err(); err != nil { if err = scanner.Err(); err != nil {
return types.Hunk{}, err return types.HunkHeader{}, types.Hunk{}, err
} }
} }
diffCutHeaderLines := diffCutHeader
for _, s := range linesBefore { for _, s := range linesBefore {
action := diffAction(s[0]) action := diffAction(s[0])
if action != actionRemoved { if action != actionRemoved {
diffCutHeader.NewLine-- diffCutHeaderLines.NewLine--
diffCutHeader.NewSpan++ diffCutHeaderLines.NewSpan++
} }
if action != actionAdded { if action != actionAdded {
diffCutHeader.OldLine-- diffCutHeaderLines.OldLine--
diffCutHeader.OldSpan++ diffCutHeaderLines.OldSpan++
} }
} }
for _, s := range linesAfter { for _, s := range linesAfter {
action := diffAction(s[0]) action := diffAction(s[0])
if action != actionRemoved { if action != actionRemoved {
diffCutHeader.NewSpan++ diffCutHeaderLines.NewSpan++
} }
if action != actionAdded { if action != actionAdded {
diffCutHeader.OldSpan++ diffCutHeaderLines.OldSpan++
} }
} }
return types.Hunk{ return diffCutHeader, types.Hunk{
HunkHeader: diffCutHeader, HunkHeader: diffCutHeaderLines,
Lines: concat(linesBefore, diffCut, linesAfter), Lines: concat(linesBefore, diffCut, linesAfter),
}, nil }, nil
} }

View File

@ -12,6 +12,7 @@ import (
"github.com/harness/gitness/gitrpc/internal/types" "github.com/harness/gitness/gitrpc/internal/types"
) )
//nolint:gocognit // it's a unit test!!!
func TestDiffCut(t *testing.T) { func TestDiffCut(t *testing.T) {
const input = `diff --git a/test.txt b/test.txt const input = `diff --git a/test.txt b/test.txt
--- a/test.txt --- a/test.txt
@ -107,7 +108,7 @@ func TestDiffCut(t *testing.T) {
for _, test := range tests { for _, test := range tests {
t.Run(test.name, func(t *testing.T) { t.Run(test.name, func(t *testing.T) {
hunk, err := DiffCut( hunkHeader, linesHunk, err := DiffCut(
strings.NewReader(input), strings.NewReader(input),
test.params, test.params,
) )
@ -122,11 +123,19 @@ func TestDiffCut(t *testing.T) {
return return
} }
if want, got := test.expCutHeader, hunk.HunkHeader.String(); want != got { if test.params.LineStartNew && test.params.LineStart != hunkHeader.NewLine {
t.Errorf("hunk line start mismatch: want=%d got=%d", test.params.LineStart, hunkHeader.NewLine)
}
if !test.params.LineStartNew && test.params.LineStart != hunkHeader.OldLine {
t.Errorf("hunk line start mismatch: want=%d got=%d", test.params.LineStart, hunkHeader.OldLine)
}
if want, got := test.expCutHeader, linesHunk.String(); want != got {
t.Errorf("header mismatch: want=%s got=%s", want, got) t.Errorf("header mismatch: want=%s got=%s", want, got)
} }
if want, got := test.expCut, hunk.Lines; !reflect.DeepEqual(want, got) { if want, got := test.expCut, linesHunk.Lines; !reflect.DeepEqual(want, got) {
t.Errorf("lines mismatch: want=%s got=%s", want, got) t.Errorf("lines mismatch: want=%s got=%s", want, got)
} }
}) })

View File

@ -129,22 +129,27 @@ func (s DiffService) DiffCut(
return nil, processGitErrorf(err, "failed to get list of source branch commits") return nil, processGitErrorf(err, "failed to get list of source branch commits")
} }
hunk, err := s.adapter.DiffCut(ctx, repoPath, r.TargetCommitSha, r.SourceCommitSha, r.Path, types.DiffCutParams{ diffHunkHeader, linesHunk, err := s.adapter.DiffCut(ctx,
LineStart: int(r.LineStart), repoPath,
LineStartNew: r.LineStartNew, r.TargetCommitSha, r.SourceCommitSha,
LineEnd: int(r.LineEnd), r.Path,
LineEndNew: r.LineEndNew, types.DiffCutParams{
BeforeLines: 2, LineStart: int(r.LineStart),
AfterLines: 2, LineStartNew: r.LineStartNew,
LineLimit: 40, LineEnd: int(r.LineEnd),
}) LineEndNew: r.LineEndNew,
BeforeLines: 2,
AfterLines: 2,
LineLimit: 40,
})
if err != nil { if err != nil {
return nil, processGitErrorf(err, "failed to get diff hunk") return nil, processGitErrorf(err, "failed to get diff hunk")
} }
return &rpc.DiffCutResponse{ return &rpc.DiffCutResponse{
HunkHeader: mapHunkHeader(hunk.HunkHeader), HunkHeader: mapHunkHeader(diffHunkHeader),
Lines: hunk.Lines, LinesHeader: linesHunk.HunkHeader.String(),
Lines: linesHunk.Lines,
MergeBaseSha: mergeBase, MergeBaseSha: mergeBase,
LatestSourceSha: sourceCommits[0], LatestSourceSha: sourceCommits[0],
}, nil }, nil

View File

@ -55,6 +55,6 @@ type GitAdapter interface {
baseRef string, headRef string, direct bool) (types.DiffShortStat, error) baseRef string, headRef string, direct bool) (types.DiffShortStat, error)
GetDiffHunkHeaders(ctx context.Context, repoPath, targetRef, sourceRef string) ([]*types.DiffFileHunkHeaders, error) GetDiffHunkHeaders(ctx context.Context, repoPath, targetRef, sourceRef string) ([]*types.DiffFileHunkHeaders, error)
DiffCut(ctx context.Context, repoPath, targetRef, sourceRef, path string, DiffCut(ctx context.Context, repoPath, targetRef, sourceRef, path string,
params types.DiffCutParams) (types.Hunk, error) params types.DiffCutParams) (types.HunkHeader, types.Hunk, error)
Blame(ctx context.Context, repoPath, rev, file string, lineFrom, lineTo int) types.BlameReader Blame(ctx context.Context, repoPath, rev, file string, lineFrom, lineTo int) types.BlameReader
} }

View File

@ -79,7 +79,8 @@ message DiffCutRequest {
message DiffCutResponse { message DiffCutResponse {
HunkHeader hunk_header = 1; HunkHeader hunk_header = 1;
repeated string lines = 2; string lines_header = 2;
string merge_base_sha = 3; repeated string lines = 3;
string latest_source_sha = 4; string merge_base_sha = 4;
string latest_source_sha = 5;
} }

View File

@ -637,9 +637,10 @@ type DiffCutResponse struct {
unknownFields protoimpl.UnknownFields unknownFields protoimpl.UnknownFields
HunkHeader *HunkHeader `protobuf:"bytes,1,opt,name=hunk_header,json=hunkHeader,proto3" json:"hunk_header,omitempty"` HunkHeader *HunkHeader `protobuf:"bytes,1,opt,name=hunk_header,json=hunkHeader,proto3" json:"hunk_header,omitempty"`
Lines []string `protobuf:"bytes,2,rep,name=lines,proto3" json:"lines,omitempty"` LinesHeader string `protobuf:"bytes,2,opt,name=lines_header,json=linesHeader,proto3" json:"lines_header,omitempty"`
MergeBaseSha string `protobuf:"bytes,3,opt,name=merge_base_sha,json=mergeBaseSha,proto3" json:"merge_base_sha,omitempty"` Lines []string `protobuf:"bytes,3,rep,name=lines,proto3" json:"lines,omitempty"`
LatestSourceSha string `protobuf:"bytes,4,opt,name=latest_source_sha,json=latestSourceSha,proto3" json:"latest_source_sha,omitempty"` MergeBaseSha string `protobuf:"bytes,4,opt,name=merge_base_sha,json=mergeBaseSha,proto3" json:"merge_base_sha,omitempty"`
LatestSourceSha string `protobuf:"bytes,5,opt,name=latest_source_sha,json=latestSourceSha,proto3" json:"latest_source_sha,omitempty"`
} }
func (x *DiffCutResponse) Reset() { func (x *DiffCutResponse) Reset() {
@ -681,6 +682,13 @@ func (x *DiffCutResponse) GetHunkHeader() *HunkHeader {
return nil return nil
} }
func (x *DiffCutResponse) GetLinesHeader() string {
if x != nil {
return x.LinesHeader
}
return ""
}
func (x *DiffCutResponse) GetLines() []string { func (x *DiffCutResponse) GetLines() []string {
if x != nil { if x != nil {
return x.Lines return x.Lines
@ -793,38 +801,41 @@ var file_diff_proto_rawDesc = []byte{
0x65, 0x5f, 0x65, 0x6e, 0x64, 0x18, 0x09, 0x20, 0x01, 0x28, 0x05, 0x52, 0x07, 0x6c, 0x69, 0x6e, 0x65, 0x5f, 0x65, 0x6e, 0x64, 0x18, 0x09, 0x20, 0x01, 0x28, 0x05, 0x52, 0x07, 0x6c, 0x69, 0x6e,
0x65, 0x45, 0x6e, 0x64, 0x12, 0x20, 0x0a, 0x0c, 0x6c, 0x69, 0x6e, 0x65, 0x5f, 0x65, 0x6e, 0x64, 0x65, 0x45, 0x6e, 0x64, 0x12, 0x20, 0x0a, 0x0c, 0x6c, 0x69, 0x6e, 0x65, 0x5f, 0x65, 0x6e, 0x64,
0x5f, 0x6e, 0x65, 0x77, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0a, 0x6c, 0x69, 0x6e, 0x65, 0x5f, 0x6e, 0x65, 0x77, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0a, 0x6c, 0x69, 0x6e, 0x65,
0x45, 0x6e, 0x64, 0x4e, 0x65, 0x77, 0x22, 0xab, 0x01, 0x0a, 0x0f, 0x44, 0x69, 0x66, 0x66, 0x43, 0x45, 0x6e, 0x64, 0x4e, 0x65, 0x77, 0x22, 0xce, 0x01, 0x0a, 0x0f, 0x44, 0x69, 0x66, 0x66, 0x43,
0x75, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x30, 0x0a, 0x0b, 0x68, 0x75, 0x75, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x30, 0x0a, 0x0b, 0x68, 0x75,
0x6e, 0x6b, 0x5f, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x6e, 0x6b, 0x5f, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32,
0x0f, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x48, 0x75, 0x6e, 0x6b, 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, 0x0f, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x48, 0x75, 0x6e, 0x6b, 0x48, 0x65, 0x61, 0x64, 0x65, 0x72,
0x52, 0x0a, 0x68, 0x75, 0x6e, 0x6b, 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, 0x12, 0x14, 0x0a, 0x05, 0x52, 0x0a, 0x68, 0x75, 0x6e, 0x6b, 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, 0x12, 0x21, 0x0a, 0x0c,
0x6c, 0x69, 0x6e, 0x65, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x09, 0x52, 0x05, 0x6c, 0x69, 0x6e, 0x6c, 0x69, 0x6e, 0x65, 0x73, 0x5f, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x18, 0x02, 0x20, 0x01,
0x65, 0x73, 0x12, 0x24, 0x0a, 0x0e, 0x6d, 0x65, 0x72, 0x67, 0x65, 0x5f, 0x62, 0x61, 0x73, 0x65, 0x28, 0x09, 0x52, 0x0b, 0x6c, 0x69, 0x6e, 0x65, 0x73, 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, 0x12,
0x5f, 0x73, 0x68, 0x61, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x6d, 0x65, 0x72, 0x67, 0x14, 0x0a, 0x05, 0x6c, 0x69, 0x6e, 0x65, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x09, 0x52, 0x05,
0x65, 0x42, 0x61, 0x73, 0x65, 0x53, 0x68, 0x61, 0x12, 0x2a, 0x0a, 0x11, 0x6c, 0x61, 0x74, 0x65, 0x6c, 0x69, 0x6e, 0x65, 0x73, 0x12, 0x24, 0x0a, 0x0e, 0x6d, 0x65, 0x72, 0x67, 0x65, 0x5f, 0x62,
0x73, 0x74, 0x5f, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x5f, 0x73, 0x68, 0x61, 0x18, 0x04, 0x20, 0x61, 0x73, 0x65, 0x5f, 0x73, 0x68, 0x61, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x6d,
0x01, 0x28, 0x09, 0x52, 0x0f, 0x6c, 0x61, 0x74, 0x65, 0x73, 0x74, 0x53, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x72, 0x67, 0x65, 0x42, 0x61, 0x73, 0x65, 0x53, 0x68, 0x61, 0x12, 0x2a, 0x0a, 0x11, 0x6c,
0x65, 0x53, 0x68, 0x61, 0x32, 0x96, 0x02, 0x0a, 0x0b, 0x44, 0x69, 0x66, 0x66, 0x53, 0x65, 0x72, 0x61, 0x74, 0x65, 0x73, 0x74, 0x5f, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x5f, 0x73, 0x68, 0x61,
0x76, 0x69, 0x63, 0x65, 0x12, 0x35, 0x0a, 0x07, 0x52, 0x61, 0x77, 0x44, 0x69, 0x66, 0x66, 0x12, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0f, 0x6c, 0x61, 0x74, 0x65, 0x73, 0x74, 0x53, 0x6f,
0x75, 0x72, 0x63, 0x65, 0x53, 0x68, 0x61, 0x32, 0x96, 0x02, 0x0a, 0x0b, 0x44, 0x69, 0x66, 0x66,
0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x35, 0x0a, 0x07, 0x52, 0x61, 0x77, 0x44, 0x69,
0x66, 0x66, 0x12, 0x10, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x44, 0x69, 0x66, 0x66, 0x52, 0x65, 0x71,
0x75, 0x65, 0x73, 0x74, 0x1a, 0x14, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x52, 0x61, 0x77, 0x44, 0x69,
0x66, 0x66, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x30, 0x01, 0x12, 0x3f,
0x0a, 0x0d, 0x44, 0x69, 0x66, 0x66, 0x53, 0x68, 0x6f, 0x72, 0x74, 0x53, 0x74, 0x61, 0x74, 0x12,
0x10, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x44, 0x69, 0x66, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x10, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x44, 0x69, 0x66, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73,
0x74, 0x1a, 0x14, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x52, 0x61, 0x77, 0x44, 0x69, 0x66, 0x66, 0x52, 0x74, 0x1a, 0x1a, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x44, 0x69, 0x66, 0x66, 0x53, 0x68, 0x6f, 0x72,
0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x30, 0x01, 0x12, 0x3f, 0x0a, 0x0d, 0x44, 0x74, 0x53, 0x74, 0x61, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12,
0x69, 0x66, 0x66, 0x53, 0x68, 0x6f, 0x72, 0x74, 0x53, 0x74, 0x61, 0x74, 0x12, 0x10, 0x2e, 0x72, 0x57, 0x0a, 0x12, 0x47, 0x65, 0x74, 0x44, 0x69, 0x66, 0x66, 0x48, 0x75, 0x6e, 0x6b, 0x48, 0x65,
0x70, 0x63, 0x2e, 0x44, 0x69, 0x66, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1a, 0x61, 0x64, 0x65, 0x72, 0x73, 0x12, 0x1e, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x44,
0x2e, 0x72, 0x70, 0x63, 0x2e, 0x44, 0x69, 0x66, 0x66, 0x53, 0x68, 0x6f, 0x72, 0x74, 0x53, 0x74, 0x69, 0x66, 0x66, 0x48, 0x75, 0x6e, 0x6b, 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x52, 0x65,
0x61, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x57, 0x0a, 0x12, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1f, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x44,
0x47, 0x65, 0x74, 0x44, 0x69, 0x66, 0x66, 0x48, 0x75, 0x6e, 0x6b, 0x48, 0x65, 0x61, 0x64, 0x65, 0x69, 0x66, 0x66, 0x48, 0x75, 0x6e, 0x6b, 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x52, 0x65,
0x72, 0x73, 0x12, 0x1e, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x44, 0x69, 0x66, 0x66, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x36, 0x0a, 0x07, 0x44, 0x69, 0x66, 0x66,
0x48, 0x75, 0x6e, 0x6b, 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x43, 0x75, 0x74, 0x12, 0x13, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x44, 0x69, 0x66, 0x66, 0x43, 0x75,
0x73, 0x74, 0x1a, 0x1f, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x44, 0x69, 0x66, 0x66, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x14, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x44,
0x48, 0x75, 0x6e, 0x6b, 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x69, 0x66, 0x66, 0x43, 0x75, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00,
0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x36, 0x0a, 0x07, 0x44, 0x69, 0x66, 0x66, 0x43, 0x75, 0x74, 0x42, 0x27, 0x5a, 0x25, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x68,
0x12, 0x13, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x44, 0x69, 0x66, 0x66, 0x43, 0x75, 0x74, 0x52, 0x65, 0x61, 0x72, 0x6e, 0x65, 0x73, 0x73, 0x2f, 0x67, 0x69, 0x74, 0x6e, 0x65, 0x73, 0x73, 0x2f, 0x67,
0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x14, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x44, 0x69, 0x66, 0x66, 0x69, 0x74, 0x72, 0x70, 0x63, 0x2f, 0x72, 0x70, 0x63, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f,
0x43, 0x75, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x27, 0x5a, 0x33,
0x25, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x68, 0x61, 0x72, 0x6e,
0x65, 0x73, 0x73, 0x2f, 0x67, 0x69, 0x74, 0x6e, 0x65, 0x73, 0x73, 0x2f, 0x67, 0x69, 0x74, 0x72,
0x70, 0x63, 0x2f, 0x72, 0x70, 0x63, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
} }
var ( var (

View File

@ -120,7 +120,7 @@ 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.Header.Text, Title: cut.LinesHeader,
Lines: cut.Lines, Lines: cut.Lines,
AnyNew: cut.AnyNew, AnyNew: cut.AnyNew,
}) })

View File

@ -30,7 +30,7 @@ type PullReqActivity struct {
Created int64 `json:"created"` Created int64 `json:"created"`
Updated int64 `json:"-"` // not returned, it's updated by the server internally. Clients should use EditedAt. Updated int64 `json:"-"` // not returned, it's updated by the server internally. Clients should use EditedAt.
Edited int64 `json:"edited"` Edited int64 `json:"edited"`
Deleted *int64 `json:"deleted"` Deleted *int64 `json:"deleted,omitempty"`
ParentID *int64 `json:"parent_id"` ParentID *int64 `json:"parent_id"`
RepoID int64 `json:"repo_id"` RepoID int64 `json:"repo_id"`
@ -48,19 +48,19 @@ type PullReqActivity struct {
Metadata map[string]interface{} `json:"metadata"` Metadata map[string]interface{} `json:"metadata"`
ResolvedBy *int64 `json:"-"` // not returned, because the resolver info is in the Resolver field ResolvedBy *int64 `json:"-"` // not returned, because the resolver info is in the Resolver field
Resolved *int64 `json:"resolved"` Resolved *int64 `json:"resolved,omitempty"`
Author PrincipalInfo `json:"author"` Author PrincipalInfo `json:"author"`
Resolver *PrincipalInfo `json:"resolver"` Resolver *PrincipalInfo `json:"resolver,omitempty"`
Outdated *bool `json:"outdated"` Outdated *bool `json:"outdated,omitempty"`
CodeCommentMergeBaseSHA *string `json:"code_comment_merge_base_sha"` CodeCommentMergeBaseSHA *string `json:"code_comment_merge_base_sha,omitempty"`
CodeCommentSourceSHA *string `json:"code_comment_source_sha"` CodeCommentSourceSHA *string `json:"code_comment_source_sha,omitempty"`
CodeCommentPath *string `json:"code_comment_path"` CodeCommentPath *string `json:"code_comment_path,omitempty"`
CodeCommentLineNew *int64 `json:"code_comment_line_new"` CodeCommentLineNew *int64 `json:"code_comment_line_new,omitempty"`
CodeCommentSpanNew *int64 `json:"code_comment_span_new"` CodeCommentSpanNew *int64 `json:"code_comment_span_new,omitempty"`
CodeCommentLineOld *int64 `json:"code_comment_line_old"` CodeCommentLineOld *int64 `json:"code_comment_line_old,omitempty"`
CodeCommentSpanOld *int64 `json:"code_comment_span_old"` CodeCommentSpanOld *int64 `json:"code_comment_span_old,omitempty"`
} }
func (a *PullReqActivity) IsValidCodeComment() bool { func (a *PullReqActivity) IsValidCodeComment() bool {