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: ...@@ -331,11 +331,10 @@ rspec foss-impact:
extends: extends:
- .rspec-base - .rspec-base
- .as-if-foss - .as-if-foss
- .rails:rules:ee-canonical-mr-only - .rails:rules:ee-mr-only
- .use-pg11 - .use-pg11
script: script:
- git fetch origin $CI_MERGE_REQUEST_TARGET_BRANCH_NAME - install_gitlab_gem
- git fetch origin $CI_MERGE_REQUEST_SOURCE_BRANCH_NAME
- run_timed_command "scripts/gitaly-test-build" - run_timed_command "scripts/gitaly-test-build"
- run_timed_command "scripts/gitaly-test-spawn" - run_timed_command "scripts/gitaly-test-spawn"
- source scripts/rspec_helpers.sh - source scripts/rspec_helpers.sh
......
...@@ -446,13 +446,13 @@ ...@@ -446,13 +446,13 @@
- <<: *if-master-refs - <<: *if-master-refs
changes: *code-backstage-patterns changes: *code-backstage-patterns
.rails:rules:ee-canonical-mr-only: .rails:rules:ee-mr-only:
rules: rules:
- <<: *if-not-ee - <<: *if-not-ee
when: never when: never
- <<: *if-not-canonical-namespace - <<: *if-security-merge-request
when: never changes: *code-backstage-patterns
- <<: *if-merge-request - <<: *if-dot-com-gitlab-org-merge-request
changes: *code-backstage-patterns changes: *code-backstage-patterns
.rails:rules:downtime_check: .rails:rules:downtime_check:
......
...@@ -4,20 +4,22 @@ ...@@ -4,20 +4,22 @@
require_relative '../../lib/gitlab/popen' require_relative '../../lib/gitlab/popen'
require_relative '../lib/tooling/test_file_finder' require_relative '../lib/tooling/test_file_finder'
output_file = ARGV.shift require 'gitlab'
source = ENV.fetch('CI_MERGE_REQUEST_SOURCE_BRANCH_NAME')
target = ENV.fetch('CI_MERGE_REQUEST_TARGET_BRANCH_NAME')
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? Gitlab.configure do |config|
warn "**** #{git_diff.cmd.join(' ')} had the following error(s):" config.endpoint = 'https://gitlab.com/api/v4'
warn git_diff.stderr config.private_token = gitlab_token
exit git_diff.status.exitstatus
end 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| tests_to_run = changed_files.flat_map do |file|
test_files = Tooling::TestFileFinder.new(file, foss_test_only: true).test_files 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