2020-06-02 05:08:01 -04:00
|
|
|
#!/usr/bin/env ruby
|
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'gitlab'
|
2020-08-25 11:10:17 -04:00
|
|
|
require 'test_file_finder'
|
2020-06-02 05:08:01 -04:00
|
|
|
|
|
|
|
gitlab_token = ENV.fetch('DANGER_GITLAB_API_TOKEN', '')
|
|
|
|
|
|
|
|
Gitlab.configure do |config|
|
|
|
|
config.endpoint = 'https://gitlab.com/api/v4'
|
|
|
|
config.private_token = gitlab_token
|
|
|
|
end
|
|
|
|
|
|
|
|
output_file = ARGV.shift
|
|
|
|
|
|
|
|
mr_project_path = ENV.fetch('CI_MERGE_REQUEST_PROJECT_PATH')
|
|
|
|
mr_iid = ENV.fetch('CI_MERGE_REQUEST_IID')
|
|
|
|
|
|
|
|
mr_changes = Gitlab.merge_request_changes(mr_project_path, mr_iid)
|
|
|
|
changed_files = mr_changes.changes.map { |change| change['new_path'] }
|
|
|
|
|
2020-08-25 11:10:17 -04:00
|
|
|
mapping = TestFileFinder::Mapping.load('tests.yml')
|
|
|
|
test_files = TestFileFinder::FileFinder.new(paths: changed_files, mapping: mapping).test_files
|
2020-06-02 05:08:01 -04:00
|
|
|
|
2020-08-25 11:10:17 -04:00
|
|
|
File.write(output_file, test_files.uniq.join(' '))
|