Skip to content

Add require for Rails in gems/gitlab-http

Rémy Coutable requested to merge add-require-to-various-gems into master

What does this MR do and why?

I needed to make these changes to be able to use the gitlab-http gem outside of the monolith codebase, for gitlab-org/quality/engineering-productivity/team!186 (merged).

In the meantime, I changed the strategy I use to actually clone the whole gitlab repo so it works without these changes, but I think it still makes sense to ensure that internal gems can be used externally without relying on the monolith gems autoloading.

observation 1: We need to explicitly require rails in the gem so that it can be used outside of the monolith. I actually have the need at the moment for gitlab-org/quality/engineering-productivity/team!186 (diffs) where I use the gitlab-http gem from the monolith and then run the gitlab-housekeeper gem, without loading the whole GitLab Rails environment. This is a step towards a better isolation of the gem, and a potential standalone use of it.

In this MR, I added require 'rails' in all the files that use Rails, but we could also just require it in gems/gitlab-http/lib/gitlab-http.rb or gems/gitlab-http/lib/gitlab/http_v2.rb.

observation 2: Gitlab::HTTP comes from lib/gitlab.rb and is a wrapper around Gitlab::HTTP_V2 which comes from the gems/gitlab-http gem. I think it makes more sense to make files under keeps/ (especially the helpers) to not rely on GitLab's internal code (i.e. lib/), but to rely on an isolated gem instead.

This also means that if we extract our Keep helpers outside of the monolith one day, we'll only have to pull the gitlab-http gem instead of the specific lib/gitlab/http.rb file from the monolith.

Edited by Rémy Coutable

Merge request reports