Commit b8b973fb authored by Albert Salim's avatar Albert Salim

Fetch MR change using API

This enables rspec foss-impact job to run
in community and security forks
parent 8c71cbde
......@@ -331,11 +331,10 @@ rspec foss-impact:
extends:
- .rspec-base
- .as-if-foss
- .rails:rules:ee-canonical-mr-only
- .rails:rules:ee-mr-only
- .use-pg11
script:
- git fetch origin $CI_MERGE_REQUEST_TARGET_BRANCH_NAME
- git fetch origin $CI_MERGE_REQUEST_SOURCE_BRANCH_NAME
- install_gitlab_gem
- run_timed_command "scripts/gitaly-test-build"
- run_timed_command "scripts/gitaly-test-spawn"
- source scripts/rspec_helpers.sh
......
......@@ -446,13 +446,13 @@
- <<: *if-master-refs
changes: *code-backstage-patterns
.rails:rules:ee-canonical-mr-only:
.rails:rules:ee-mr-only:
rules:
- <<: *if-not-ee
when: never
- <<: *if-not-canonical-namespace
when: never
- <<: *if-merge-request
- <<: *if-security-merge-request
changes: *code-backstage-patterns
- <<: *if-dot-com-gitlab-org-merge-request
changes: *code-backstage-patterns
.rails:rules:downtime_check:
......
......@@ -4,20 +4,22 @@
require_relative '../../lib/gitlab/popen'
require_relative '../lib/tooling/test_file_finder'
output_file = ARGV.shift
source = ENV.fetch('CI_MERGE_REQUEST_SOURCE_BRANCH_NAME')
target = ENV.fetch('CI_MERGE_REQUEST_TARGET_BRANCH_NAME')
require 'gitlab'
git_diff = Gitlab::Popen.popen_with_detail(%w[git diff --name-only] + ["origin/#{target}...origin/#{source}"])
gitlab_token = ENV.fetch('DANGER_GITLAB_API_TOKEN', '')
unless git_diff.status.success?
warn "**** #{git_diff.cmd.join(' ')} had the following error(s):"
warn git_diff.stderr
exit git_diff.status.exitstatus
Gitlab.configure do |config|
config.endpoint = 'https://gitlab.com/api/v4'
config.private_token = gitlab_token
end
changed_files = git_diff.stdout.split("\n")
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'] }
tests_to_run = changed_files.flat_map do |file|
test_files = Tooling::TestFileFinder.new(file, foss_test_only: true).test_files
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment