Skip to content
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
merged 8 commits into from
Apr 11, 2024

Conversation

yokomotod
Copy link
Collaborator

@yokomotod yokomotod commented Apr 10, 2024

currently tfcmt-gitlab fetches only 20 comments. if there are more comments, those won't be patched but posted as new comment. (and increase comment and ....)


there can be same issues for other listings, but I think only comment list has problem because

  • ListCommits: It seems that we use only last commit, so first page is enough
  • ListMergeRequestsByCommit: no pagination function? and single page may enough

related document: https://docs.gitlab.com/ee/api/rest/index.html#pagination

Comment on lines 89 to 91
if sentinel > 100 {
return nil, fmt.Errorf("gitlab.comment.list: too many pages, something went wrong")
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pagination from example https://github.com/xanzy/go-gitlab/blob/main/examples/pagination.go

plus sentinel. I think 100 * 100 = 10,000 comments are insane.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can change to break with waring message instead err, if it's your preference design

with:
aqua_version: v2.10.1
aqua_version: v2.27.0
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yokomotod
Copy link
Collaborator Author

@hirosassa 🙇

I could confirm that a MR which has 60+ comments are patched properly with this fix.

Without this fix, it had grown to 360+ comments by running CI multiple times 😅

@yokomotod
Copy link
Collaborator Author

@hirosassa @kitagry resolved conflict

@@ -125,6 +125,16 @@ func TestCommentPost(t *testing.T) {
func TestCommentList(t *testing.T) {
t.Parallel()
comments := []*gitlab.Note{
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you this variables as inline in testcase?

opt.Page = resp.NextPage

if sentinel > maxPages {
return nil, fmt.Errorf("gitlab.comment.list: too many pages, something went wrong")
Copy link
Collaborator

Choose a reason for hiding this comment

The 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.

@yokomotod
Copy link
Collaborator Author

@kitagry fixed according to your review

plus, add one more test case for sentinel logic 7e3413a (and found bug 🙃 )


client.API = createMockGitLabAPI(mockCtrl)

_, err = client.Comment.List(1) // no assert res, only assert `.MaxTimes(100)`
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds enough ?

Copy link
Collaborator

@kitagry kitagry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@kitagry kitagry merged commit 0cb63c9 into hirosassa:main Apr 11, 2024
1 check passed
@yokomotod yokomotod deleted the fix-comment-list-pagination branch April 11, 2024 13:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants