diff options
author | Achilleas Pipinellis <axil@gitlab.com> | 2023-03-07 00:34:34 +0300 |
---|---|---|
committer | Achilleas Pipinellis <axil@gitlab.com> | 2023-03-07 00:34:34 +0300 |
commit | 1d7cd13a682000137c45dcba0bd705ad241b1f0a (patch) | |
tree | 714328dbe297ad45e3e9b007dd7e263ac4d46c7b /lib | |
parent | 9b000e8962ddd364f68eb96113189a6472099349 (diff) | |
parent | 261f4745646f144c74652e3715947eca473a5904 (diff) |
Merge branch 't2003-support-review-apps-from-forks' into 'main'
Support Review App Pipelines for MRs from Forks
See merge request https://gitlab.com/gitlab-org/gitlab-docs/-/merge_requests/3594
Merged-by: Achilleas Pipinellis <axil@gitlab.com>
Co-authored-by: Niklas van Schrick <mc.taucher2003@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/tasks/build_site.rake | 11 | ||||
-rw-r--r-- | lib/tasks/task_helpers.rb | 13 |
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 576a25a4..52445d2f 100644 --- a/lib/tasks/task_helpers.rb +++ b/lib/tasks/task_helpers.rb @@ -30,12 +30,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" @@ -53,6 +60,8 @@ class TaskHelpers else default_branch(products[slug].fetch('repo')) end + + return stable_branch, "heads/#{stable_branch}" end def git_workdir_dirty? |