Page MenuHomePhabricator

Investigate whether we can/should integrate Git/Reviewers with GitLab
Closed, ResolvedPublic3 Estimated Story Points

Description

I just now became aware of this: https://www.mediawiki.org/wiki/Git/Reviewers

Probably worth thinking about what this looks like in a GitLab world - and/or whether there's some builtin GitLab feature that could handle it.

One complication that comes to mind: GitLab CE really only supports one assigned reviewer at a time.


The selected solution is to add people as @ mentions in merge request comments. According to https://docs.gitlab.com/ee/user/discussions/#mentions, All mentioned users are notified with to-do items and emails. Users can change this setting for themselves in the notification settings.

Details

TitleReferenceAuthorSource BranchDest Branch
Cache parse_Git_Reviewers() result for 5 minutes by defaultrepos/releng/gitlab-webhooks!22dancymain-Iae48f9a1c35481cc9987a45fda5aeeb32ea3bb69main
Handle GitLab watches defined in https://www.mediawiki.org/wiki/Git/Reviewersrepos/releng/gitlab-webhooks!19dancymain-I463b21be79749d4dcbb673483d78d8210373c3c6main
Customize query in GitLab

Event Timeline

Restricted Application added a subscriber: Aklapper. ยท View Herald TranscriptAug 25 2021, 5:22 PM
brennen triaged this task as Medium priority.Aug 26 2021, 5:35 PM
brennen moved this task from INBOX to Seen on the Release-Engineering-Team board.
brennen edited projects, added GitLab (Integrations); removed GitLab.
thcipriani lowered the priority of this task from Medium to Low.
thcipriani changed the point value for this task from 2 to 3.

If you're mentioned in a MR, it shows up in your Todos (https://gitlab.wikimedia.org/dashboard/todos), where you can mark them as Done. So, one option would be for the reviewer-bot to automatically edit the MR description to tag the reviewers, maybe it could create its own section like:

## Reviewers from https://www.mediawiki.org/wiki/Git/Reviewers
* @kharlan 
* @someoneElse

One complication is that you need a mapping of LDAP names to shell user names, i.e. I'm "Kosta Harlan" in gerrit reviewer tagging land, but @kharlan in our GitLab setup.

Side note โ€“ does GitLab have some equivalent to gerrit's stream-events?

Side note โ€“ does GitLab have some equivalent to gerrit's stream-events?

I have not yet found a server-wide event stream, but there is a per-project API endpoint for pull monitoring and per-project webhooks for push monitoring. There are also system level webhooks which can notify for new project creation among other things. In theory these could be used in combination to register a project level webhook when notified about the creation of each project to mimic the functionality of a full system feed.

Adding "Gerrit Reviewer Bot" here so that maybe I can find this task quicker in the future. Also pinging @valhallasw into the discussion as the author of the bot that makes this awesome magic work on Gerrit.

See T288381 for the related discussion from two years ago on Wikibugs. Long story short: No, not really, unless you pay for GitLab EE (which I think we don't).

I have no intent in porting gerrit-reviewer-bot to GitLab as the effort is too significant -- I'd say it makes more sense to just start from scratch. The design decisions were driven by what Gerrit offered (in 2012!) on the one hand and what was a convenient 'editable by everyone' system (Mediawiki). None of these decisions are necessarily valid in 2023 with GitLab.

The existing notification system in GitLab would cover most of the entries in https://www.mediawiki.org/wiki/Git/Reviewers. Special handling is still needed for entries that use a file pattern or a repo pattern that doesn't match a single group. This functionality can be added to https://gitlab.wikimedia.org/repos/releng/gitlab-phabricator as an additional "sink". Merge request events don't contain details about what files are touched (that information is only available in a separate push event that is not linked to a merge request), but we can react to MR events by querying https://gitlab.wikimedia.org/api/v4/projects/:id/merge_requests/:merge_request_iid/diffs to get the touched file list when needed.

@valhallasw Can you explain this section of ReviewerFactory._reviewer_generator() in the Gerrit reviewer bot code:
https://github.com/valhallasw/gerrit-reviewer-bot/blob/dcb31716af142494716a35a5fad239add8e368af/add_reviewer.py#L61

elif part.name == "every":
    modulo = self._tryParseInt(part.value, 1)
    if modulo < 2:
        modulo = 1

I wasn't able to find any documentation about an every template parameter. It appears that the intention is to add matching reviewers somewhat probabilistically. I notice in ReviewerFactory._filter_reviewers() that variable i is never advanced past 0 which appears to be a bug.

@valhallasw Can you explain this section of ReviewerFactory._reviewer_generator() in the Gerrit reviewer bot code:
https://github.com/valhallasw/gerrit-reviewer-bot/blob/dcb31716af142494716a35a5fad239add8e368af/add_reviewer.py#L61

elif part.name == "every":
    modulo = self._tryParseInt(part.value, 1)
    if modulo < 2:
        modulo = 1

I wasn't able to find any documentation about an every template parameter. It appears that the intention is to add matching reviewers somewhat probabilistically. I notice in ReviewerFactory._filter_reviewers() that variable i is never advanced past 0 which appears to be a bug.

The idea here was that you'd be able to only get added to half the changesets (or 1/3rd, etc) by providing a divisor. If the changeset ID is divisible by the divisor, you get added, otherwise, you're skipped. I think the i variable was probably just for testing.

FWIW, no-one seems to be using the feature, so it might as well never have existed :-)

Mentioned in SAL (#wikimedia-releng) [2024-01-29T21:01:06Z] <dancy> Created gitlab-mentions-bot account on GitLab (T289712)

dancy claimed this task.

I have deployed the updated gitlab-webhooks and updated documentation at https://www.mediawiki.org/wiki/Git/Reviewers and https://wikitech.wikimedia.org/wiki/GitLab/Webhooks