debian-mirror-gitlab/tooling/bin/find_tests

32 lines
970 B
Plaintext
Raw Normal View History

2020-06-23 00:09:42 +05:30
#!/usr/bin/env ruby
# frozen_string_literal: true
require 'gitlab'
2020-11-24 15:15:51 +05:30
require 'test_file_finder'
2020-06-23 00:09:42 +05:30
gitlab_token = ENV.fetch('DANGER_GITLAB_API_TOKEN', '')
2021-10-27 15:23:28 +05:30
gitlab_endpoint = ENV.fetch('CI_API_V4_URL')
2020-06-23 00:09:42 +05:30
Gitlab.configure do |config|
2021-10-27 15:23:28 +05:30
config.endpoint = gitlab_endpoint
2020-06-23 00:09:42 +05:30
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'] }
2021-02-22 17:27:13 +05:30
tff = TestFileFinder::FileFinder.new(paths: changed_files).tap do |file_finder|
file_finder.use TestFileFinder::MappingStrategies::PatternMatching.load('tests.yml')
2020-06-23 00:09:42 +05:30
2021-02-22 17:27:13 +05:30
if ENV['RSPEC_TESTS_MAPPING_ENABLED']
file_finder.use TestFileFinder::MappingStrategies::DirectMatching.load_json(ENV['RSPEC_TESTS_MAPPING_PATH'])
end
end
File.write(output_file, tff.test_files.uniq.join(' '))