Get all comments of a pull request¶
GET /api/v5/repos/{owner}/{repo}/pulls/{number}/comments
This endpoint retrieves all comments of a pull request in the specified repository. You can filter by code line comments and regular PR comments, and paginate and sort with the page number, page size, and ascending/descending parameters. The response returns the comment body, the user who posted it, the file position, the reply list, and other information.
Access token support¶
- AtomGit user access tokens (AtomGit user access tokens)
Whether anonymous access is allowed¶
This endpoint allows anonymous access.
Request parameters¶
| Parameter | Location | Type | Required | Description |
|---|---|---|---|---|
owner |
path | string | Yes | The namespace address the repository belongs to (the address path of an organization or personal namespace) |
repo |
path | string | Yes | Repository path (path) |
number |
path | integer | Yes | Which PR, that is, the ordinal number of the PR in this repository |
page |
query | integer | No | Current page number; defaults to 1 |
per_page |
query | integer | No | Number of items per page, up to 100; defaults to 20 |
direction |
query | string | No | Optional. Ascending/descending (asc/desc) |
comment_type |
query | string | No | Optional. Filter by comment type. Code line comment/regular PR comment: diff_comment/pr_comment |
Response parameters¶
The response body is an array of comment objects, each element structured as follows:
| Field | Type | Always returned | Nullable | Description |
|---|---|---|---|---|
id |
integer | Yes | No | Comment ID |
discussion_id |
string | Yes | No | Discussion id |
body |
string | Yes | No | Comment body |
created_at |
string | Yes | No | Creation time |
updated_at |
string | Yes | No | Update time |
user |
object | Yes | No | Information about the user who posted the comment |
comment_type |
string | Yes | No | Comment type |
resolved |
boolean | Yes | No | Whether the comment is resolved |
diff_file |
string | Yes | No | File the comment is in |
diff_position |
object | Yes | No | Position information of the code line comment |
reply |
object[] | No | Yes | Reply list of the comment |
user object
| Field | Type | Always returned | Nullable | Description |
|---|---|---|---|---|
user.id |
string | Yes | No | User ID |
user.login |
string | Yes | No | Login name |
user.name |
string | Yes | No | User nickname |
user.avatar_url |
string | Yes | No | User avatar URL |
user.html_url |
string | Yes | No | User home page URL |
diff_position object
| Field | Type | Always returned | Nullable | Description |
|---|---|---|---|---|
diff_position.start_new_line |
integer | No | Yes | Start line number in the new file |
diff_position.end_new_line |
integer | No | Yes | End line number in the new file |
diff_position.start_old_line |
integer | No | Yes | Start line number in the old file |
diff_position.end_old_line |
integer | No | Yes | End line number in the old file |
diff_position.position_type |
string | No | Yes | Position type: binary means a file-level comment, text means a code line comment |
reply object (array element)¶
| Field | Type | Always returned | Nullable | Description |
|---|---|---|---|---|
reply.id |
integer | No | Yes | Reply ID |
reply.body |
string | No | Yes | Reply body |
reply.created_at |
string | No | Yes | Reply creation time |
reply.updated_at |
string | No | Yes | Reply update time |
reply.user |
object | No | Yes | Reply user information |
reply.user object¶
| Field | Type | Always returned | Nullable | Description |
|---|---|---|---|---|
reply.user.id |
string | No | Yes | User ID |
reply.user.login |
string | No | Yes | Login name |
reply.user.name |
string | No | Yes | User nickname |
reply.user.avatar_url |
string | No | Yes | User avatar URL |
reply.user.html_url |
string | No | Yes | User home page URL |
Error responses¶
A
200/success response alone is not enough: callers need to know what a failure looks like in order to write error handling.
400 Bad request
{
"error": "invalid_request",
"message": "The number parameter cannot be empty",
"field": "number"
}
401 Unauthenticated
Note: The error field names are subject to what the backend actually returns; the reference documentation does not provide further failure response examples.
HTTP response status codes¶
| Status code | Description |
|---|---|
200 |
Success (OK) |
304 |
Not modified (Not modified) |
400 |
Parameter error (Bad request) |
401 |
Authentication required (Requires authentication) |
403 |
Forbidden (Forbidden) |
404 |
Resource does not exist (Not found) |
429 |
Too many requests (Too many requests) |
500 |
Internal system error (Internal server error) |
Request example¶
Parameter descriptions¶
This endpoint allows anonymous access, so no access token is required; if you need authentication, you can also append ?access_token=<token> to the request.
<owner>is replaced with the namespace address the repository belongs to (the address path of an organization or personal namespace);<repo>with the repository path (path);<number>with the number of the PR, that is, the ordinal number of the PR in this repository.
cURL¶
curl -X GET 'https://api.atomgit.com/api/v5/repos/<owner>/<repo>/pulls/<number>/comments?page=1&per_page=20&direction=asc&comment_type=diff_comment' \
-H 'Accept: application/json'
JavaScript¶
// Native fetch (Node.js 18+ / browser)
const response = await fetch("https://api.atomgit.com/api/v5/repos/<owner>/<repo>/pulls/<number>/comments?page=1&per_page=20&direction=asc&comment_type=diff_comment", {
headers: {
"Accept": "application/json",
},
});
if (!response.ok) {
throw new Error(`Request failed: ${response.status}`);
}
const data = await response.json();
console.log(data);
Python¶
import requests
resp = requests.get(
"https://api.atomgit.com/api/v5/repos/<owner>/<repo>/pulls/<number>/comments",
params={
"page": 1,
"per_page": 20,
"direction": "asc",
"comment_type": "diff_comment",
},
headers={
"Accept": "application/json",
},
timeout=10,
)
resp.raise_for_status()
print(resp.json())
Response example¶
Status code: 200
[
{
"id": 100,
"discussion_id": "de772738e6dab92174c0e86c052ccf9bed24f747",
"body": "111",
"created_at": "2024-04-19T07:48:59.755+00:00",
"updated_at": "2024-04-19T07:48:59.755+00:00",
"user": {
"id": "708",
"login": "Lzm_0916",
"name": "Lzm_0916",
"avatar_url": "https://api.atomgit.com/avatar.png",
"html_url": "https://api.atomgit.com/Lzm_0916"
},
"comment_type": "diff_comment",
"resolved": true,
"diff_file": "src/main/java/Example.java",
"diff_position": {
"start_new_line": 10,
"end_new_line": 12,
"start_old_line": 0,
"end_old_line": 0,
"position_type": "text"
},
"reply": [
{
"id": 101,
"body": "Modified",
"created_at": "2024-04-19T08:00:00.000+00:00",
"updated_at": "2024-04-19T08:00:00.000+00:00",
"user": {
"id": "709",
"login": "octocat",
"name": "octocat",
"avatar_url": "https://api.atomgit.com/avatar.png",
"html_url": "https://api.atomgit.com/octocat"
}
}
]
}
]
Error codes¶
| Error code | Description |
|---|---|
400 |
Parameter error or the request cannot be parsed |
401 |
Unauthenticated or invalid credentials (missing/invalid access credentials) |
403 |
Insufficient permission; access forbidden |
404 |
Request path does not exist |
429 |
Too many requests; rate limit triggered |
500 |
Internal system error |
Markdown source: View on AtomGit·Content from the open-source project gitcode-dev/atomgit-api-doc