diff options
author | Achilleas Pipinellis <axil@gitlab.com> | 2021-05-31 09:42:37 +0300 |
---|---|---|
committer | Marcel Amirault <4155490-marcel.amirault@users.noreply.gitlab.com> | 2021-05-31 09:42:37 +0300 |
commit | 93512617b70788c810ca98531f65b095ff062121 (patch) | |
tree | 1fc6dc75bdfbcb8314e5d92616e73ec517fdc21a /lib | |
parent | 390b7ec18d80d10e04db10465a812614f03711ea (diff) |
Switch master branch occurrences to default branch (main)
Diffstat (limited to 'lib')
-rw-r--r-- | lib/helpers/edit_on_gitlab.rb | 4 | ||||
-rw-r--r-- | lib/task_helpers.rb | 15 |
2 files changed, 10 insertions, 9 deletions
diff --git a/lib/helpers/edit_on_gitlab.rb b/lib/helpers/edit_on_gitlab.rb index 7ca37957..883954c3 100644 --- a/lib/helpers/edit_on_gitlab.rb +++ b/lib/helpers/edit_on_gitlab.rb @@ -28,8 +28,8 @@ module Nanoc::Helpers gitlab_ide_url = "https://gitlab.com/-/ide/project/gitlab-org/gitlab/edit/master/-/doc/#{docs_content_filename}" else # gitlab-docs pages - gitlab_url = "https://gitlab.com/gitlab-org/gitlab-docs/blob/master/#{@item[:content_filename]}" - gitlab_ide_url = "https://gitlab.com/-/ide/project/gitlab-org/gitlab-docs/edit/master/-/#{@item[:content_filename]}" + gitlab_url = "https://gitlab.com/gitlab-org/gitlab-docs/blob/main/#{@item[:content_filename]}" + gitlab_ide_url = "https://gitlab.com/-/ide/project/gitlab-org/gitlab-docs/edit/main/-/#{@item[:content_filename]}" end case editor diff --git a/lib/task_helpers.rb b/lib/task_helpers.rb index 8a8735f5..54f3caf6 100644 --- a/lib/task_helpers.rb +++ b/lib/task_helpers.rb @@ -18,9 +18,9 @@ def products end def retrieve_branch(slug) - # If CI_COMMIT_REF_NAME is not defined, set it to master. + # If CI_COMMIT_REF_NAME is not defined (run locally), set it to the default branch. if ENV["CI_COMMIT_REF_NAME"].nil? - 'master' + default_branch(products['repo_url']) # If we're on a gitlab-docs stable branch according to the regex, catch the # version and assign the product stable branches correctly. elsif version = ENV["CI_COMMIT_REF_NAME"].match(VERSION_FORMAT) @@ -35,14 +35,11 @@ def retrieve_branch(slug) when 'charts' chart = chart_version(ENV["CI_COMMIT_REF_NAME"]).match(VERSION_FORMAT) "#{chart[:major]}-#{chart[:minor]}-stable" - # For all other products use master - else - 'master' end # If we're NOT on a gitlab-docs stable branch, fetch the BRANCH_* environment - # variable, and if not assigned, set to master. + # variable, and if not assigned, set to the default branch. else - ENV.fetch("BRANCH_#{slug.upcase}", 'master') + ENV.fetch("BRANCH_#{slug.upcase}", default_branch(products['repo_url'])) end end @@ -66,3 +63,7 @@ def chart_version(gitlab_version) config.fetch(gitlab_version) end + +def default_branch(remote_url) + `git remote show #{remote_url} | grep 'HEAD branch' | cut -d' ' -f5`.tr("\n", '') +end |