Skip to content

Commit c2a9364

Browse files
yiheng-kkkSamMorrowDrumsCopilot
authored
Return range coordinates for review comments (#3193)
* Return range coordinates for review comments * docs(pull-requests): describe review comment coordinates Document nullable current and original range fields and assert their serialized omission behavior for single-line and outdated comments. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: yiheng-kkk <272397091+yiheng-kkk@users.noreply.github.com> Co-authored-by: Sam Morrow <sammorrowdrums@github.com> Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent 4ee4594 commit c2a9364

5 files changed

Lines changed: 105 additions & 25 deletions

File tree

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1198,7 +1198,7 @@ The following sets of tools are available:
11981198
3. get_status - Get combined commit status of a head commit in a pull request.
11991199
4. get_files - Get the list of files changed in a pull request. Use with pagination parameters to control the number of results returned.
12001200
5. get_commits - Get the list of commits on a pull request. Use with pagination parameters to control the number of results returned.
1201-
6. get_review_comments - Get review threads on a pull request. Each thread contains logically grouped review comments made on the same code location during pull request reviews. Returns threads with metadata (isResolved, isOutdated, isCollapsed) and their associated comments. Use cursor-based pagination (perPage, after) to control results.
1201+
6. get_review_comments - Get review threads on a pull request. Each thread contains logically grouped review comments made on the same code location during pull request reviews. Returns thread metadata and comments with nullable current and original line-range coordinates (line, start_line, original_line, original_start_line). Current coordinates are omitted when unavailable, such as for outdated comments. Use cursor-based pagination (perPage, after) to control results.
12021202
7. get_reviews - Get the reviews on a pull request. When asked for review comments, use get_review_comments method. Use with pagination parameters to control the number of results returned.
12031203
8. get_comments - Get comments on a pull request. Use this if user doesn't specifically want review comments. Use with pagination parameters to control the number of results returned.
12041204
9. get_check_runs - Get check runs for the head commit of a pull request. Check runs are the individual CI/CD jobs and checks that run on the PR.

‎pkg/github/__toolsnaps__/pull_request_read.snap‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"type": "string"
1313
},
1414
"method": {
15-
"description": "Action to specify what pull request data needs to be retrieved from GitHub. \nPossible options: \n 1. get - Get details of a specific pull request.\n 2. get_diff - Get the diff of a pull request.\n 3. get_status - Get combined commit status of a head commit in a pull request.\n 4. get_files - Get the list of files changed in a pull request. Use with pagination parameters to control the number of results returned.\n 5. get_commits - Get the list of commits on a pull request. Use with pagination parameters to control the number of results returned.\n 6. get_review_comments - Get review threads on a pull request. Each thread contains logically grouped review comments made on the same code location during pull request reviews. Returns threads with metadata (isResolved, isOutdated, isCollapsed) and their associated comments. Use cursor-based pagination (perPage, after) to control results.\n 7. get_reviews - Get the reviews on a pull request. When asked for review comments, use get_review_comments method. Use with pagination parameters to control the number of results returned.\n 8. get_comments - Get comments on a pull request. Use this if user doesn't specifically want review comments. Use with pagination parameters to control the number of results returned.\n 9. get_check_runs - Get check runs for the head commit of a pull request. Check runs are the individual CI/CD jobs and checks that run on the PR.\n",
15+
"description": "Action to specify what pull request data needs to be retrieved from GitHub. \nPossible options: \n 1. get - Get details of a specific pull request.\n 2. get_diff - Get the diff of a pull request.\n 3. get_status - Get combined commit status of a head commit in a pull request.\n 4. get_files - Get the list of files changed in a pull request. Use with pagination parameters to control the number of results returned.\n 5. get_commits - Get the list of commits on a pull request. Use with pagination parameters to control the number of results returned.\n 6. get_review_comments - Get review threads on a pull request. Each thread contains logically grouped review comments made on the same code location during pull request reviews. Returns thread metadata and comments with nullable current and original line-range coordinates (line, start_line, original_line, original_start_line). Current coordinates are omitted when unavailable, such as for outdated comments. Use cursor-based pagination (perPage, after) to control results.\n 7. get_reviews - Get the reviews on a pull request. When asked for review comments, use get_review_comments method. Use with pagination parameters to control the number of results returned.\n 8. get_comments - Get comments on a pull request. Use this if user doesn't specifically want review comments. Use with pagination parameters to control the number of results returned.\n 9. get_check_runs - Get check runs for the head commit of a pull request. Check runs are the individual CI/CD jobs and checks that run on the PR.\n",
1616
"enum": [
1717
"get",
1818
"get_diff",

‎pkg/github/minimal_types.go‎

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1942,13 +1942,16 @@ type MinimalPageInfo struct {
19421942

19431943
// MinimalReviewComment is the trimmed output type for PR review comment objects.
19441944
type MinimalReviewComment struct {
1945-
Body string `json:"body,omitempty"`
1946-
Path string `json:"path"`
1947-
Line *int `json:"line,omitempty"`
1948-
Author string `json:"author,omitempty"`
1949-
CreatedAt string `json:"created_at,omitempty"`
1950-
UpdatedAt string `json:"updated_at,omitempty"`
1951-
HTMLURL string `json:"html_url"`
1945+
Body string `json:"body,omitempty"`
1946+
Path string `json:"path"`
1947+
Line *int `json:"line,omitempty"`
1948+
OriginalLine *int `json:"original_line,omitempty"`
1949+
StartLine *int `json:"start_line,omitempty"`
1950+
OriginalStartLine *int `json:"original_start_line,omitempty"`
1951+
Author string `json:"author,omitempty"`
1952+
CreatedAt string `json:"created_at,omitempty"`
1953+
UpdatedAt string `json:"updated_at,omitempty"`
1954+
HTMLURL string `json:"html_url"`
19521955
}
19531956

19541957
// MinimalReviewThread is the trimmed output type for PR review thread objects.
@@ -2287,6 +2290,18 @@ func convertToMinimalReviewComment(c reviewCommentNode) MinimalReviewComment {
22872290
line := int(*c.Line)
22882291
m.Line = &line
22892292
}
2293+
if c.OriginalLine != nil {
2294+
originalLine := int(*c.OriginalLine)
2295+
m.OriginalLine = &originalLine
2296+
}
2297+
if c.StartLine != nil {
2298+
startLine := int(*c.StartLine)
2299+
m.StartLine = &startLine
2300+
}
2301+
if c.OriginalStartLine != nil {
2302+
originalStartLine := int(*c.OriginalStartLine)
2303+
m.OriginalStartLine = &originalStartLine
2304+
}
22902305

22912306
if !c.CreatedAt.IsZero() {
22922307
m.CreatedAt = c.CreatedAt.Format(time.RFC3339)

‎pkg/github/pullrequests.go‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Possible options:
3636
3. get_status - Get combined commit status of a head commit in a pull request.
3737
4. get_files - Get the list of files changed in a pull request. Use with pagination parameters to control the number of results returned.
3838
5. get_commits - Get the list of commits on a pull request. Use with pagination parameters to control the number of results returned.
39-
6. get_review_comments - Get review threads on a pull request. Each thread contains logically grouped review comments made on the same code location during pull request reviews. Returns threads with metadata (isResolved, isOutdated, isCollapsed) and their associated comments. Use cursor-based pagination (perPage, after) to control results.
39+
6. get_review_comments - Get review threads on a pull request. Each thread contains logically grouped review comments made on the same code location during pull request reviews. Returns thread metadata and comments with nullable current and original line-range coordinates (line, start_line, original_line, original_start_line). Current coordinates are omitted when unavailable, such as for outdated comments. Use cursor-based pagination (perPage, after) to control results.
4040
7. get_reviews - Get the reviews on a pull request. When asked for review comments, use get_review_comments method. Use with pagination parameters to control the number of results returned.
4141
8. get_comments - Get comments on a pull request. Use this if user doesn't specifically want review comments. Use with pagination parameters to control the number of results returned.
4242
9. get_check_runs - Get check runs for the head commit of a pull request. Check runs are the individual CI/CD jobs and checks that run on the PR.
@@ -461,11 +461,14 @@ type reviewThreadNode struct {
461461
}
462462

463463
type reviewCommentNode struct {
464-
ID githubv4.ID
465-
Body githubv4.String
466-
Path githubv4.String
467-
Line *githubv4.Int
468-
Author struct {
464+
ID githubv4.ID
465+
Body githubv4.String
466+
Path githubv4.String
467+
Line *githubv4.Int
468+
OriginalLine *githubv4.Int
469+
StartLine *githubv4.Int
470+
OriginalStartLine *githubv4.Int
471+
Author struct {
469472
Login githubv4.String
470473
}
471474
CreatedAt githubv4.DateTime

‎pkg/github/pullrequests_test.go‎

Lines changed: 72 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2188,13 +2188,16 @@ func Test_GetPullRequestComments(t *testing.T) {
21882188
"isOutdated": false,
21892189
"isCollapsed": false,
21902190
"comments": map[string]any{
2191-
"totalCount": 2,
2191+
"totalCount": 3,
21922192
"nodes": []map[string]any{
21932193
{
2194-
"id": "PRRC_kwDOA0xdyM4AX1Y0",
2195-
"body": "This looks good",
2196-
"path": "file1.go",
2197-
"line": 5,
2194+
"id": "PRRC_kwDOA0xdyM4AX1Y0",
2195+
"body": "This looks good",
2196+
"path": "file1.go",
2197+
"line": 86,
2198+
"originalLine": 84,
2199+
"startLine": 73,
2200+
"originalStartLine": 73,
21982201
"author": map[string]any{
21992202
"login": "reviewer1",
22002203
},
@@ -2203,17 +2206,33 @@ func Test_GetPullRequestComments(t *testing.T) {
22032206
"url": "https://github.com/owner/repo/pull/42#discussion_r101",
22042207
},
22052208
{
2206-
"id": "PRRC_kwDOA0xdyM4AX1Y1",
2207-
"body": "Please fix this",
2208-
"path": "file1.go",
2209-
"line": 10,
2209+
"id": "PRRC_kwDOA0xdyM4AX1Y1",
2210+
"body": "Please fix this",
2211+
"path": "file1.go",
2212+
"line": 159,
2213+
"originalLine": 157,
22102214
"author": map[string]any{
22112215
"login": "reviewer2",
22122216
},
22132217
"createdAt": "2024-01-01T13:00:00Z",
22142218
"updatedAt": "2024-01-01T13:00:00Z",
22152219
"url": "https://github.com/owner/repo/pull/42#discussion_r102",
22162220
},
2221+
{
2222+
"id": "PRRC_kwDOA0xdyM4AX1Y2",
2223+
"body": "Comment with current coordinates unavailable",
2224+
"path": "file1.go",
2225+
"line": nil,
2226+
"originalLine": 178,
2227+
"startLine": nil,
2228+
"originalStartLine": 176,
2229+
"author": map[string]any{
2230+
"login": "reviewer3",
2231+
},
2232+
"createdAt": "2024-01-01T14:00:00Z",
2233+
"updatedAt": "2024-01-01T14:00:00Z",
2234+
"url": "https://github.com/owner/repo/pull/42#discussion_r103",
2235+
},
22172236
},
22182237
},
22192238
},
@@ -2252,13 +2271,56 @@ func Test_GetPullRequestComments(t *testing.T) {
22522271
assert.Equal(t, false, thread.IsCollapsed)
22532272

22542273
// Validate comments within thread
2255-
assert.Len(t, thread.Comments, 2)
2274+
assert.Len(t, thread.Comments, 3)
22562275

22572276
// Validate first comment
22582277
comment1 := thread.Comments[0]
22592278
assert.Equal(t, "This looks good", comment1.Body)
22602279
assert.Equal(t, "file1.go", comment1.Path)
22612280
assert.Equal(t, "reviewer1", comment1.Author)
2281+
require.NotNil(t, comment1.Line)
2282+
assert.Equal(t, 86, *comment1.Line)
2283+
require.NotNil(t, comment1.OriginalLine)
2284+
assert.Equal(t, 84, *comment1.OriginalLine)
2285+
require.NotNil(t, comment1.StartLine)
2286+
assert.Equal(t, 73, *comment1.StartLine)
2287+
require.NotNil(t, comment1.OriginalStartLine)
2288+
assert.Equal(t, 73, *comment1.OriginalStartLine)
2289+
2290+
comment2 := thread.Comments[1]
2291+
require.NotNil(t, comment2.Line)
2292+
assert.Equal(t, 159, *comment2.Line)
2293+
require.NotNil(t, comment2.OriginalLine)
2294+
assert.Equal(t, 157, *comment2.OriginalLine)
2295+
assert.Nil(t, comment2.StartLine)
2296+
assert.Nil(t, comment2.OriginalStartLine)
2297+
2298+
var raw struct {
2299+
ReviewThreads []struct {
2300+
Comments []map[string]any `json:"comments"`
2301+
} `json:"review_threads"`
2302+
}
2303+
require.NoError(t, json.Unmarshal([]byte(textContent), &raw))
2304+
require.Len(t, raw.ReviewThreads, 1)
2305+
require.Len(t, raw.ReviewThreads[0].Comments, 3)
2306+
assert.Equal(t, float64(86), raw.ReviewThreads[0].Comments[0]["line"])
2307+
assert.Equal(t, float64(84), raw.ReviewThreads[0].Comments[0]["original_line"])
2308+
assert.Equal(t, float64(73), raw.ReviewThreads[0].Comments[0]["start_line"])
2309+
assert.Equal(t, float64(73), raw.ReviewThreads[0].Comments[0]["original_start_line"])
2310+
assert.NotContains(t, raw.ReviewThreads[0].Comments[1], "start_line")
2311+
assert.NotContains(t, raw.ReviewThreads[0].Comments[1], "original_start_line")
2312+
assert.NotContains(t, raw.ReviewThreads[0].Comments[2], "line")
2313+
assert.NotContains(t, raw.ReviewThreads[0].Comments[2], "start_line")
2314+
assert.Equal(t, float64(178), raw.ReviewThreads[0].Comments[2]["original_line"])
2315+
assert.Equal(t, float64(176), raw.ReviewThreads[0].Comments[2]["original_start_line"])
2316+
2317+
comment3 := thread.Comments[2]
2318+
assert.Nil(t, comment3.Line)
2319+
require.NotNil(t, comment3.OriginalLine)
2320+
assert.Equal(t, 178, *comment3.OriginalLine)
2321+
assert.Nil(t, comment3.StartLine)
2322+
require.NotNil(t, comment3.OriginalStartLine)
2323+
assert.Equal(t, 176, *comment3.OriginalStartLine)
22622324

22632325
// Validate pagination info
22642326
assert.Equal(t, false, result.PageInfo.HasNextPage)

0 commit comments

Comments
 (0)