Commit 5ae5d51c authored by Furkan Ayhan's avatar Furkan Ayhan Committed by Fabio Pitino

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

parent 70f764e9
......@@ -1093,6 +1093,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
......@@ -1117,6 +1119,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
......@@ -1939,6 +1939,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