Commit ab76da78 authored by Fabio Pitino's avatar Fabio Pitino

Merge branch '208692-fix-modified-paths-of-external-prs' into 'master'

Fix the problem of pipelines changes with external PRs [RUN ALL RSPEC] [RUN AS-IF-FOSS]

See merge request gitlab-org/gitlab!60736
parents 23f0fd46 5ae5d51c
......@@ -1095,6 +1095,8 @@ module Ci
merge_request.modified_paths
elsif branch_updated?
push_details.modified_paths
elsif external_pull_request? && ::Feature.enabled?(:ci_modified_paths_of_external_prs, project, default_enabled: :yaml)
external_pull_request.modified_paths
end
end
end
......@@ -1119,6 +1121,10 @@ module Ci
merge_request_id.present?
end
def external_pull_request?
external_pull_request_id.present?
end
def detached_merge_request_pipeline?
merge_request? && target_sha.nil?
end
......
......@@ -72,6 +72,10 @@ class ExternalPullRequest < ApplicationRecord
end
end
def modified_paths
project.repository.diff_stats(target_sha, source_sha).paths
end
private
def actual_source_branch_sha
......
---
name: ci_modified_paths_of_external_prs
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/60736
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/330605
milestone: '13.12'
type: development
group: group::pipeline authoring
default_enabled: false
......@@ -1948,6 +1948,30 @@ RSpec.describe Ci::Pipeline, :mailer, factory_default: :keep do
expect(pipeline.modified_paths).to match(merge_request.modified_paths)
end
end
context 'when source is an external pull request' do
let(:pipeline) do
create(:ci_pipeline, source: :external_pull_request_event, external_pull_request: external_pull_request)
end
let(:external_pull_request) do
create(:external_pull_request, project: project, target_sha: '281d3a7', source_sha: '498214d')
end
it 'returns external pull request modified paths' do
expect(pipeline.modified_paths).to match(external_pull_request.modified_paths)
end
context 'when the FF ci_modified_paths_of_external_prs is disabled' do
before do
stub_feature_flags(ci_modified_paths_of_external_prs: false)
end
it 'returns nil' do
expect(pipeline.modified_paths).to be_nil
end
end
end
end
describe '#all_worktree_paths' do
......
......@@ -3,7 +3,8 @@
require 'spec_helper'
RSpec.describe ExternalPullRequest do
let(:project) { create(:project) }
let_it_be(:project) { create(:project, :repository) }
let(:source_branch) { 'the-branch' }
let(:status) { :open }
......@@ -217,4 +218,18 @@ RSpec.describe ExternalPullRequest do
expect(pull_request).not_to be_from_fork
end
end
describe '#modified_paths' do
let(:pull_request) do
build(:external_pull_request, project: project, target_sha: '281d3a7', source_sha: '498214d')
end
subject(:modified_paths) { pull_request.modified_paths }
it 'returns modified paths' do
expect(modified_paths).to eq ['bar/branch-test.txt',
'files/js/commit.coffee',
'with space/README.md']
end
end
end
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