Retrieve all MR notes when looking for a comment
Calling gitlab.v4.objects.ProjectMergeRequestNoteManager.list() without specifying get_all=True or iterator=True returns a maximum of 20 items. Combined with the fact that the current code retrieves merge request comments from GitLab in ascending "created at" order, this may prevent an existing Hazard-posted merge request comment from being found. Consider the following scenario:
-
Hazard creates a comment shortly after the merge request is created.
-
Work on the merge request continues. Users post numerous new comments on the merge request.
-
One of the subsequent code revisions does not elicit any Hazard feedback. The comment created in step 1 is removed.
-
Another code revision is pushed that does elicit some Hazard feedback. A new comment is posted.
-
Yet another code revision is pushed that also elicits some Hazard feedback. However, since the comment posted in step 4 is not present among the first 20 items retrieved from the merge request in ascending "created by" order, the code assumes that there is no existing merge request comment to update, so it posts another, duplicate comment instead of editing the existing one (posted in step 4).
Fix by iterating through all merge request notes when searching for a previously-posted comment. To improve the odds of finding one quickly, retrieve the notes in descending "updated at" order as the comments posted by Hazard are expected to always be among the most recently created/updated ones.