Reproduce Repository X-Ray functionality - Introduce config file parser
What does this MR do and why?
Background
The Repository X-Ray is a tool that searches for dependency manager configuration files (aka "lock files") and then extracts a list of libraries from the content.
In #474306 (comment 2025085630), we decided to migrate the Repository X-Ray functionality into the GitLab Rails monolith. This gives us two main benefits: (i) it will eventually allow us to run the service outside of the CI pipeline, and (ii) we can maintain the parsing logic centrally so that other domains can utilize it.
This MR
This MR is the next step in the migration progress. In the last MR !162313 (merged), we introduced the LockFiles::Base
class (later renamed to ConfigFiles::Base
) where the intention is for each dependency config file to be represented by a child class.
In this MR, we introduce the ConfigFileParser
library class which searches through the project repository for dependency config files and parses them. It will later be utilized by a new service and worker in #476180 (closed).
Resolves part of #476177 (closed).
MR acceptance checklist
Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
How to set up and validate locally
- Create a new blank project and commit these two files to the repo:
subdir/Gemfile.lock
:
GEM
remote: https://rubygems.org/
specs:
bcrypt (3.1.20)
logger (1.5.3)
my_lib (1.0.2)
PLATFORMS
ruby
DEPENDENCIES
bcrypt (~> 3.1, >= 3.1.14)
logger (~> 1.5.3)
BUNDLED WITH
2.5.16
pom.xml
:
invalid content
- Run the parser in the Rails console:
project = Project.last # Should be the project you created in Step 1
result = Ai::Context::Dependencies::ConfigFileParser.new(project).extract_config_files
- Observe that the payloads of each config file object is as expected:
result.map { |c| { lang: c.class.lang, valid: c.valid?, error_message: c.error_message, payload: c.payload } }
Related to #476177 (closed)