-
Notifications
You must be signed in to change notification settings - Fork 3
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
fix: comment list pagination #21
Merged
kitagry
merged 8 commits into
hirosassa:main
from
yokomotod:fix-comment-list-pagination
Apr 11, 2024
Merged
Changes from 3 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
704fff0
fix: comment list pagination
yokomotod a307254
update aqua
yokomotod 12e1dac
fix lint
yokomotod 8c229a4
Merge branch 'main' into fix-comment-list-pagination
hirosassa adc1099
Merge branch 'hirosassa:main' into fix-comment-list-pagination
yokomotod 078e160
fix conflict
yokomotod 7045205
fix review work
yokomotod 7e3413a
add test case for pagination sentinel
yokomotod 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 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 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 |
---|---|---|
|
@@ -6,6 +6,11 @@ import ( | |
gitlab "github.com/xanzy/go-gitlab" | ||
) | ||
|
||
const ( | ||
listPerPage = 100 | ||
maxPages = 100 | ||
) | ||
|
||
// CommentService handles communication with the comment related | ||
// methods of GitLab API | ||
type CommentService service | ||
|
@@ -59,9 +64,36 @@ func (g *CommentService) Patch(note int, body string, opt PostOptions) error { | |
|
||
// List lists comments on GitLab merge requests | ||
func (g *CommentService) List(number int) ([]*gitlab.Note, error) { | ||
comments, _, err := g.client.API.ListMergeRequestNotes( | ||
number, | ||
&gitlab.ListMergeRequestNotesOptions{}, | ||
) | ||
return comments, err | ||
allComments := make([]*gitlab.Note, 0) | ||
|
||
opt := &gitlab.ListMergeRequestNotesOptions{ | ||
ListOptions: gitlab.ListOptions{ | ||
Page: 1, | ||
PerPage: listPerPage, | ||
}, | ||
} | ||
|
||
for sentinel := 1; ; sentinel++ { | ||
comments, resp, err := g.client.API.ListMergeRequestNotes( | ||
number, | ||
opt, | ||
) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
allComments = append(allComments, comments...) | ||
|
||
if resp.NextPage == 0 { | ||
break | ||
} | ||
|
||
opt.Page = resp.NextPage | ||
|
||
if sentinel > maxPages { | ||
return nil, fmt.Errorf("gitlab.comment.list: too many pages, something went wrong") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it is not necessary to return error. It is better to print log. |
||
} | ||
} | ||
|
||
return allComments, nil | ||
} |
This file contains 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 |
---|---|---|
|
@@ -70,6 +70,16 @@ func TestCommentPost(t *testing.T) { | |
func TestCommentList(t *testing.T) { | ||
t.Parallel() | ||
comments := []*gitlab.Note{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you this variables as inline in testcase? |
||
// page1 | ||
{ | ||
ID: 371748792, | ||
Body: "comment 1", | ||
}, | ||
{ | ||
ID: 371765743, | ||
Body: "comment 2", | ||
}, | ||
// page2 | ||
{ | ||
ID: 371748792, | ||
Body: "comment 1", | ||
|
This file contains 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.
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.
I got a error and resolved by update aqua: https://github.com/hirosassa/tfcmt-gitlab/actions/runs/8629098634/job/23652549544