diff --git a/gitrpc/diff.go b/gitrpc/diff.go index f88cdac77..009b4c0e5 100644 --- a/gitrpc/diff.go +++ b/gitrpc/diff.go @@ -220,6 +220,7 @@ func (c *Client) GetDiffHunkHeaders( type DiffCutOutput struct { Header HunkHeader + LinesHeader string Lines []string MergeBaseSHA string LatestSourceSHA string @@ -277,6 +278,7 @@ func (c *Client) DiffCut(ctx context.Context, params *DiffCutParams) (DiffCutOut return DiffCutOutput{ Header: HunkHeader(hunkHeader), + LinesHeader: result.LinesHeader, Lines: result.Lines, MergeBaseSHA: result.MergeBaseSha, LatestSourceSHA: result.LatestSourceSha, diff --git a/gitrpc/internal/gitea/diff.go b/gitrpc/internal/gitea/diff.go index 4324e4f78..272254d16 100644 --- a/gitrpc/internal/gitea/diff.go +++ b/gitrpc/internal/gitea/diff.go @@ -122,7 +122,7 @@ func (g Adapter) DiffCut( ctx context.Context, repoPath, targetRef, sourceRef, path string, params types.DiffCutParams, -) (types.Hunk, error) { +) (types.HunkHeader, types.Hunk, error) { pipeRead, pipeWrite := io.Pipe() stderr := &bytes.Buffer{} 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 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 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 { diff --git a/gitrpc/internal/parser/diff_cut.go b/gitrpc/internal/parser/diff_cut.go index d7dfd146f..fe40d3fa6 100644 --- a/gitrpc/internal/parser/diff_cut.go +++ b/gitrpc/internal/parser/diff_cut.go @@ -17,18 +17,18 @@ import ( // and returns lines specified with the parameters. // //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) var err error var hunkHeader types.HunkHeader if _, err = scanFileHeader(scanner); err != nil { - return types.Hunk{}, err + return types.HunkHeader{}, types.Hunk{}, err } if hunkHeader, err = scanHunkHeader(scanner); err != nil { - return types.Hunk{}, err + return types.HunkHeader{}, types.Hunk{}, err } currentOldLine := hunkHeader.OldLine @@ -51,7 +51,7 @@ func DiffCut(r io.Reader, params types.DiffCutParams) (types.Hunk, error) { line, action, err = scanHunkLine(scanner) if err != nil { - return types.Hunk{}, err + return types.HunkHeader{}, types.Hunk{}, err } if line == "" { @@ -93,7 +93,7 @@ func DiffCut(r io.Reader, params types.DiffCutParams) (types.Hunk, error) { } if !inCut { - return types.Hunk{}, types.ErrHunkNotFound + return types.HunkHeader{}, types.Hunk{}, types.ErrHunkNotFound } var ( @@ -111,34 +111,36 @@ func DiffCut(r io.Reader, params types.DiffCutParams) (types.Hunk, error) { linesAfter = append(linesAfter, line) } if err = scanner.Err(); err != nil { - return types.Hunk{}, err + return types.HunkHeader{}, types.Hunk{}, err } } + diffCutHeaderLines := diffCutHeader + for _, s := range linesBefore { action := diffAction(s[0]) if action != actionRemoved { - diffCutHeader.NewLine-- - diffCutHeader.NewSpan++ + diffCutHeaderLines.NewLine-- + diffCutHeaderLines.NewSpan++ } if action != actionAdded { - diffCutHeader.OldLine-- - diffCutHeader.OldSpan++ + diffCutHeaderLines.OldLine-- + diffCutHeaderLines.OldSpan++ } } for _, s := range linesAfter { action := diffAction(s[0]) if action != actionRemoved { - diffCutHeader.NewSpan++ + diffCutHeaderLines.NewSpan++ } if action != actionAdded { - diffCutHeader.OldSpan++ + diffCutHeaderLines.OldSpan++ } } - return types.Hunk{ - HunkHeader: diffCutHeader, + return diffCutHeader, types.Hunk{ + HunkHeader: diffCutHeaderLines, Lines: concat(linesBefore, diffCut, linesAfter), }, nil } diff --git a/gitrpc/internal/parser/diff_cut_test.go b/gitrpc/internal/parser/diff_cut_test.go index cb3559474..9a6a330be 100644 --- a/gitrpc/internal/parser/diff_cut_test.go +++ b/gitrpc/internal/parser/diff_cut_test.go @@ -12,6 +12,7 @@ import ( "github.com/harness/gitness/gitrpc/internal/types" ) +//nolint:gocognit // it's a unit test!!! func TestDiffCut(t *testing.T) { const input = `diff --git a/test.txt b/test.txt --- a/test.txt @@ -107,7 +108,7 @@ func TestDiffCut(t *testing.T) { for _, test := range tests { t.Run(test.name, func(t *testing.T) { - hunk, err := DiffCut( + hunkHeader, linesHunk, err := DiffCut( strings.NewReader(input), test.params, ) @@ -122,11 +123,19 @@ func TestDiffCut(t *testing.T) { 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) } - 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) } }) diff --git a/gitrpc/internal/service/diff.go b/gitrpc/internal/service/diff.go index d175b339a..636292bfa 100644 --- a/gitrpc/internal/service/diff.go +++ b/gitrpc/internal/service/diff.go @@ -129,22 +129,27 @@ func (s DiffService) DiffCut( 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{ - LineStart: int(r.LineStart), - LineStartNew: r.LineStartNew, - LineEnd: int(r.LineEnd), - LineEndNew: r.LineEndNew, - BeforeLines: 2, - AfterLines: 2, - LineLimit: 40, - }) + diffHunkHeader, linesHunk, err := s.adapter.DiffCut(ctx, + repoPath, + r.TargetCommitSha, r.SourceCommitSha, + r.Path, + types.DiffCutParams{ + LineStart: int(r.LineStart), + LineStartNew: r.LineStartNew, + LineEnd: int(r.LineEnd), + LineEndNew: r.LineEndNew, + BeforeLines: 2, + AfterLines: 2, + LineLimit: 40, + }) if err != nil { return nil, processGitErrorf(err, "failed to get diff hunk") } return &rpc.DiffCutResponse{ - HunkHeader: mapHunkHeader(hunk.HunkHeader), - Lines: hunk.Lines, + HunkHeader: mapHunkHeader(diffHunkHeader), + LinesHeader: linesHunk.HunkHeader.String(), + Lines: linesHunk.Lines, MergeBaseSha: mergeBase, LatestSourceSha: sourceCommits[0], }, nil diff --git a/gitrpc/internal/service/interface.go b/gitrpc/internal/service/interface.go index b47a13195..9d0705fd4 100644 --- a/gitrpc/internal/service/interface.go +++ b/gitrpc/internal/service/interface.go @@ -55,6 +55,6 @@ type GitAdapter interface { baseRef string, headRef string, direct bool) (types.DiffShortStat, error) GetDiffHunkHeaders(ctx context.Context, repoPath, targetRef, sourceRef string) ([]*types.DiffFileHunkHeaders, error) 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 } diff --git a/gitrpc/proto/diff.proto b/gitrpc/proto/diff.proto index 74f1fd3a3..baf56b3bb 100644 --- a/gitrpc/proto/diff.proto +++ b/gitrpc/proto/diff.proto @@ -79,7 +79,8 @@ message DiffCutRequest { message DiffCutResponse { HunkHeader hunk_header = 1; - repeated string lines = 2; - string merge_base_sha = 3; - string latest_source_sha = 4; + string lines_header = 2; + repeated string lines = 3; + string merge_base_sha = 4; + string latest_source_sha = 5; } diff --git a/gitrpc/rpc/diff.pb.go b/gitrpc/rpc/diff.pb.go index e767f49d3..f25037936 100644 --- a/gitrpc/rpc/diff.pb.go +++ b/gitrpc/rpc/diff.pb.go @@ -637,9 +637,10 @@ type DiffCutResponse struct { unknownFields protoimpl.UnknownFields 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"` - MergeBaseSha string `protobuf:"bytes,3,opt,name=merge_base_sha,json=mergeBaseSha,proto3" json:"merge_base_sha,omitempty"` - LatestSourceSha string `protobuf:"bytes,4,opt,name=latest_source_sha,json=latestSourceSha,proto3" json:"latest_source_sha,omitempty"` + LinesHeader string `protobuf:"bytes,2,opt,name=lines_header,json=linesHeader,proto3" json:"lines_header,omitempty"` + Lines []string `protobuf:"bytes,3,rep,name=lines,proto3" json:"lines,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() { @@ -681,6 +682,13 @@ func (x *DiffCutResponse) GetHunkHeader() *HunkHeader { return nil } +func (x *DiffCutResponse) GetLinesHeader() string { + if x != nil { + return x.LinesHeader + } + return "" +} + func (x *DiffCutResponse) GetLines() []string { if x != nil { 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, 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, - 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, 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, - 0x52, 0x0a, 0x68, 0x75, 0x6e, 0x6b, 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, 0x12, 0x14, 0x0a, 0x05, - 0x6c, 0x69, 0x6e, 0x65, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x09, 0x52, 0x05, 0x6c, 0x69, 0x6e, - 0x65, 0x73, 0x12, 0x24, 0x0a, 0x0e, 0x6d, 0x65, 0x72, 0x67, 0x65, 0x5f, 0x62, 0x61, 0x73, 0x65, - 0x5f, 0x73, 0x68, 0x61, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x6d, 0x65, 0x72, 0x67, - 0x65, 0x42, 0x61, 0x73, 0x65, 0x53, 0x68, 0x61, 0x12, 0x2a, 0x0a, 0x11, 0x6c, 0x61, 0x74, 0x65, - 0x73, 0x74, 0x5f, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x5f, 0x73, 0x68, 0x61, 0x18, 0x04, 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, + 0x52, 0x0a, 0x68, 0x75, 0x6e, 0x6b, 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, 0x12, 0x21, 0x0a, 0x0c, + 0x6c, 0x69, 0x6e, 0x65, 0x73, 0x5f, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x18, 0x02, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x0b, 0x6c, 0x69, 0x6e, 0x65, 0x73, 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, 0x12, + 0x14, 0x0a, 0x05, 0x6c, 0x69, 0x6e, 0x65, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x09, 0x52, 0x05, + 0x6c, 0x69, 0x6e, 0x65, 0x73, 0x12, 0x24, 0x0a, 0x0e, 0x6d, 0x65, 0x72, 0x67, 0x65, 0x5f, 0x62, + 0x61, 0x73, 0x65, 0x5f, 0x73, 0x68, 0x61, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x6d, + 0x65, 0x72, 0x67, 0x65, 0x42, 0x61, 0x73, 0x65, 0x53, 0x68, 0x61, 0x12, 0x2a, 0x0a, 0x11, 0x6c, + 0x61, 0x74, 0x65, 0x73, 0x74, 0x5f, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x5f, 0x73, 0x68, 0x61, + 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, - 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, 0x74, 0x1a, 0x1a, - 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x44, 0x69, 0x66, 0x66, 0x53, 0x68, 0x6f, 0x72, 0x74, 0x53, 0x74, - 0x61, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x57, 0x0a, 0x12, - 0x47, 0x65, 0x74, 0x44, 0x69, 0x66, 0x66, 0x48, 0x75, 0x6e, 0x6b, 0x48, 0x65, 0x61, 0x64, 0x65, - 0x72, 0x73, 0x12, 0x1e, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x44, 0x69, 0x66, 0x66, - 0x48, 0x75, 0x6e, 0x6b, 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, - 0x73, 0x74, 0x1a, 0x1f, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x44, 0x69, 0x66, 0x66, - 0x48, 0x75, 0x6e, 0x6b, 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, - 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x36, 0x0a, 0x07, 0x44, 0x69, 0x66, 0x66, 0x43, 0x75, 0x74, - 0x12, 0x13, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x44, 0x69, 0x66, 0x66, 0x43, 0x75, 0x74, 0x52, 0x65, - 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x14, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x44, 0x69, 0x66, 0x66, - 0x43, 0x75, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x27, 0x5a, - 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, + 0x74, 0x1a, 0x1a, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x44, 0x69, 0x66, 0x66, 0x53, 0x68, 0x6f, 0x72, + 0x74, 0x53, 0x74, 0x61, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, + 0x57, 0x0a, 0x12, 0x47, 0x65, 0x74, 0x44, 0x69, 0x66, 0x66, 0x48, 0x75, 0x6e, 0x6b, 0x48, 0x65, + 0x61, 0x64, 0x65, 0x72, 0x73, 0x12, 0x1e, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x44, + 0x69, 0x66, 0x66, 0x48, 0x75, 0x6e, 0x6b, 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x52, 0x65, + 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1f, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x44, + 0x69, 0x66, 0x66, 0x48, 0x75, 0x6e, 0x6b, 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x52, 0x65, + 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x36, 0x0a, 0x07, 0x44, 0x69, 0x66, 0x66, + 0x43, 0x75, 0x74, 0x12, 0x13, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x44, 0x69, 0x66, 0x66, 0x43, 0x75, + 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x14, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x44, + 0x69, 0x66, 0x66, 0x43, 0x75, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, + 0x42, 0x27, 0x5a, 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 ( diff --git a/internal/api/controller/pullreq/comment_create.go b/internal/api/controller/pullreq/comment_create.go index 8a7e95793..4c3616e2a 100644 --- a/internal/api/controller/pullreq/comment_create.go +++ b/internal/api/controller/pullreq/comment_create.go @@ -120,7 +120,7 @@ func (c *Controller) CommentCreate( setAsCodeComment(act, cut, in.Path, in.SourceCommitSHA) _ = act.SetPayload(&types.PullRequestActivityPayloadCodeComment{ - Title: cut.Header.Text, + Title: cut.LinesHeader, Lines: cut.Lines, AnyNew: cut.AnyNew, }) diff --git a/types/pullreq_activity.go b/types/pullreq_activity.go index 8d291293a..db5372c8d 100644 --- a/types/pullreq_activity.go +++ b/types/pullreq_activity.go @@ -30,7 +30,7 @@ type PullReqActivity struct { Created int64 `json:"created"` Updated int64 `json:"-"` // not returned, it's updated by the server internally. Clients should use EditedAt. Edited int64 `json:"edited"` - Deleted *int64 `json:"deleted"` + Deleted *int64 `json:"deleted,omitempty"` ParentID *int64 `json:"parent_id"` RepoID int64 `json:"repo_id"` @@ -48,19 +48,19 @@ type PullReqActivity struct { Metadata map[string]interface{} `json:"metadata"` 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"` - Resolver *PrincipalInfo `json:"resolver"` + Resolver *PrincipalInfo `json:"resolver,omitempty"` - Outdated *bool `json:"outdated"` - CodeCommentMergeBaseSHA *string `json:"code_comment_merge_base_sha"` - CodeCommentSourceSHA *string `json:"code_comment_source_sha"` - CodeCommentPath *string `json:"code_comment_path"` - CodeCommentLineNew *int64 `json:"code_comment_line_new"` - CodeCommentSpanNew *int64 `json:"code_comment_span_new"` - CodeCommentLineOld *int64 `json:"code_comment_line_old"` - CodeCommentSpanOld *int64 `json:"code_comment_span_old"` + 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"` } func (a *PullReqActivity) IsValidCodeComment() bool {