API: Retrieve label events by project

At the moment, our REST API retrieves label events by issue 👉 https://docs.gitlab.com/ee/api/resource_label_events.html. However, this is not available at the project level.

Issue for the GraphQL API 👉 #299251

Implementation Guide

  • We have a module LabelEventable which only applies to Noteables (issues, merge requests, epics). Since this will be an aggregate of things that are eventable - a project isn't an eventable thing as we've defined it, we'll need to define an endpoint for it.
  • If we built an endpoint resource_label_events in a project, I could imagine they'd want to filter out merge request events. So we'd need to add the ability to filter by type
  • resource_label_events table might be one of our biggest tables (not sure) so there may be some possibly tricky SQL to make sure it's performant.
  • lib/api/resource_label_events.rb would be a decent place to start

An example of how to get started (including diff) is in #357773 (comment 900388558)

We also probably want a finder of some sort rather than the direct ResourceLabelEvent.joins(eventable).where.not("#{eventable}_id" => nil).where("#{eventable}.project_id = ?", id) line demonstrated in the diff. But that would be added once it is working in this form 🙂

We'd also have to be wary of N+1s 👉 https://docs.gitlab.com/ee/development/api_styleguide.html#avoiding-n1-problems.

Edited by 🤖 GitLab Bot 🤖