Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-docs.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNiklas <mc.taucher2003@gmail.com>2023-03-07 00:34:33 +0300
committerAchilleas Pipinellis <axil@gitlab.com>2023-03-07 00:34:33 +0300
commit261f4745646f144c74652e3715947eca473a5904 (patch)
tree5361f89bb72ee79235c964bee7836776bfc24ef5
parent99fb9cf88cdd20f46e765eae7e44290e19744172 (diff)
Support Review App Pipelines for MRs from Forks
-rw-r--r--lib/tasks/build_site.rake11
-rw-r--r--lib/tasks/task_helpers.rb13
2 files changed, 20 insertions, 4 deletions
diff --git a/lib/tasks/build_site.rake b/lib/tasks/build_site.rake
index 7b1fdadf..f9e1b807 100644
--- a/lib/tasks/build_site.rake
+++ b/lib/tasks/build_site.rake
@@ -9,7 +9,7 @@ task_helpers = TaskHelpers.new
desc 'Clone Git repositories of documentation projects, keeping only the most recent commit'
task :clone_repositories do
task_helpers.products.each_value do |product|
- branch = task_helpers.retrieve_branch(product['slug'])
+ branch, refspec = task_helpers.retrieve_branch(product['slug'])
# Limit the pipeline to pull only the repo where the MR is, not all 4, to save time/space.
# First we check if the branch on the docs repo is other than the default branch and
@@ -41,7 +41,14 @@ task :clone_repositories do
end
end
- `git clone --branch #{branch} --single-branch #{product['repo']} --depth 1 #{product['project_dir']}`
+ Dir.mkdir(product['project_dir'])
+
+ Dir.chdir(product['project_dir']) do
+ `git -c init.defaultBranch=#{branch} init`
+ `git remote add origin #{product['repo']}`
+ `git fetch --depth 1 origin #{refspec}`
+ `git -c advice.detachedHead=false checkout FETCH_HEAD`
+ end
latest_commit = `git -C #{product['project_dir']} log --oneline -n 1`
diff --git a/lib/tasks/task_helpers.rb b/lib/tasks/task_helpers.rb
index fd64afe6..d25ef043 100644
--- a/lib/tasks/task_helpers.rb
+++ b/lib/tasks/task_helpers.rb
@@ -32,12 +32,19 @@ class TaskHelpers
# If we're NOT on a gitlab-docs stable branch, fetch the BRANCH_* environment
# variable, and if not assigned, set to the default branch.
#
- return ENV.fetch("BRANCH_#{slug.upcase}", default_branch(products[slug].fetch('repo'))) if stable_branch_name.nil?
+ if stable_branch_name.nil?
+ merge_request_iid = ENV["MERGE_REQUEST_IID_#{slug.upcase}"]
+ branch_name = ENV.fetch("BRANCH_#{slug.upcase}", default_branch(products[slug].fetch('repo')))
+
+ return branch_name, "heads/#{branch_name}" if merge_request_iid.nil?
+
+ return branch_name, "merge-requests/#{merge_request_iid}/head"
+ end
#
# Check the project slug to determine the branch name
#
- case slug
+ stable_branch = case slug
when 'ee'
"#{stable_branch_name}-ee"
@@ -55,6 +62,8 @@ class TaskHelpers
else
default_branch(products[slug].fetch('repo'))
end
+
+ return stable_branch, "heads/#{stable_branch}"
end
def git_workdir_dirty?