-
Notifications
You must be signed in to change notification settings - Fork 61
fix: get correct location data for comments efficiently #582
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jakubbortlik
wants to merge
5
commits into
harrisoncramer:develop
Choose a base branch
from
jakubbortlik:fix-getting-modification-type
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+654
−653
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
cabf86b
fix: creating comments
jakubbortlik 4fad14d
docs: add missing fields to annotation class
jakubbortlik 6d78f64
fix: only strip new lines from system output
jakubbortlik 34dc85e
fix: enforce spaces before empty diff lines
jakubbortlik 20a18c2
docs: replace number with integer in type annotations
jakubbortlik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| package app | ||
|
|
||
| import ( | ||
| "testing" | ||
| ) | ||
|
|
||
| func TestBuildCommentPosition(t *testing.T) { | ||
| makePositionData := func(startType string, startOld, startNew int64, endType string, endOld, endNew int64) PositionData { | ||
| return PositionData{ | ||
| FileName: "file.txt", | ||
| HeadCommitSHA: "head-sha", | ||
| BaseCommitSHA: "base-sha", | ||
| StartCommitSHA: "start-sha", | ||
| Type: "text", | ||
| LineRange: &LineRange{ | ||
| Start: &PositionInfo{Type: startType, OldLine: startOld, NewLine: startNew}, | ||
| End: &PositionInfo{Type: endType, OldLine: endOld, NewLine: endNew}, | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| t.Run("zeroes NewLine for a deleted (\"old\") line, keeping LineCode's real pair", func(t *testing.T) { | ||
| positionData := makePositionData("", 4, 4, "old", 5, 5) | ||
| opt := buildCommentPosition(CommentWithPosition{PositionData: positionData}) | ||
|
|
||
| assert(t, *opt.LineRange.End.OldLine, int64(5)) | ||
| assert(t, *opt.LineRange.End.NewLine, int64(0)) | ||
| assert(t, *opt.LineRange.End.LineCode, "5436437fa01a7d3e41d46741da54b451446774ca_5_5") | ||
| }) | ||
|
|
||
| t.Run("zeroes OldLine for an added (\"new\") line, keeping LineCode's real pair", func(t *testing.T) { | ||
| positionData := makePositionData("", 4, 4, "new", 5, 5) | ||
| opt := buildCommentPosition(CommentWithPosition{PositionData: positionData}) | ||
|
|
||
| assert(t, *opt.LineRange.End.OldLine, int64(0)) | ||
| assert(t, *opt.LineRange.End.NewLine, int64(5)) | ||
| assert(t, *opt.LineRange.End.LineCode, "5436437fa01a7d3e41d46741da54b451446774ca_5_5") | ||
| }) | ||
|
|
||
| t.Run("keeps both lines real for an unmodified (\"\") line", func(t *testing.T) { | ||
| positionData := makePositionData("", 4, 4, "", 5, 6) | ||
| opt := buildCommentPosition(CommentWithPosition{PositionData: positionData}) | ||
|
|
||
| assert(t, *opt.LineRange.End.OldLine, int64(5)) | ||
| assert(t, *opt.LineRange.End.NewLine, int64(6)) | ||
| }) | ||
|
|
||
| t.Run("keeps both lines real for an expanded line", func(t *testing.T) { | ||
| positionData := makePositionData("", 4, 4, "expanded", 59, 61) | ||
| opt := buildCommentPosition(CommentWithPosition{PositionData: positionData}) | ||
|
|
||
| assert(t, *opt.LineRange.End.OldLine, int64(59)) | ||
| assert(t, *opt.LineRange.End.NewLine, int64(61)) | ||
| }) | ||
|
|
||
| t.Run("zeroes the start and end independently", func(t *testing.T) { | ||
| positionData := makePositionData("new", 0, 50, "", 60, 62) | ||
| opt := buildCommentPosition(CommentWithPosition{PositionData: positionData}) | ||
|
|
||
| assert(t, *opt.LineRange.Start.OldLine, int64(0)) | ||
| assert(t, *opt.LineRange.Start.NewLine, int64(50)) | ||
| assert(t, *opt.LineRange.End.OldLine, int64(60)) | ||
| assert(t, *opt.LineRange.End.NewLine, int64(62)) | ||
| }) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding this.
What I didn't think of in the initial review: GitLab's position object has a third
position_type,file, which carries paths and no line numbers at all. In their generated OpenAPI spec the only required members are:base_shastart_shahead_shaposition_typeOptional:
new_line,old_lineline_rangeThat is what a file-level comment looks like on the wire. Since the tag makes
file_nameimplyline_range, we would now reject such a payload. Nothing sends it today -lua/gitlab/actions/comment.lua:102hardcodestype = "text"- but we should take it into consideration when we add file-level comments.Minor, while I was in there: it seems no test currently covers
file_nameset withline_rangemissing.