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:
authorAchilleas Pipinellis <axil@gitlab.com>2021-06-16 17:05:29 +0300
committerAchilleas Pipinellis <axil@gitlab.com>2021-06-16 18:14:27 +0300
commite63b471d60ff51938b3b428910a2880a5da01006 (patch)
tree829d3c88bef33fd308db18cf24325d9363ccf7cd
parent8d7b1825f9b3af99c21c2c6e5be723f882baff46 (diff)
Use the API to fetch the remote default branch
-rw-r--r--README.md1
-rw-r--r--lib/task_helpers.rb8
2 files changed, 7 insertions, 2 deletions
diff --git a/README.md b/README.md
index 706e558f..27756bfa 100644
--- a/README.md
+++ b/README.md
@@ -45,6 +45,7 @@ To preview any changes you make to GitLab documentation, you need:
- [`.tool-versions`](.tool-versions)
- Node.js, at the version specified in [`.tool-versions`](.tool-versions).
- Yarn, at the version specified in [`.tool-versions`](.tool-versions).
+- [jq](https://stedolan.github.io/jq/), needed by some Rake tasks.
- Xcode *(macOS only)*:
- Run `xcode-select --install` to install the command line tools only.
- Or download and install the entire package using the macOS's App Store.
diff --git a/lib/task_helpers.rb b/lib/task_helpers.rb
index 5614ef37..358169b4 100644
--- a/lib/task_helpers.rb
+++ b/lib/task_helpers.rb
@@ -64,6 +64,10 @@ 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", '')
+def default_branch(repo)
+ # Get the URL-encoded path of the project
+ # https://docs.gitlab.com/ee/api/README.html#namespaced-path-encoding
+ url_encoded_path = repo.sub('https://gitlab.com/', '').sub('.git', '').gsub('/', '%2F')
+
+ `curl https://gitlab.com/api/v4/projects/#{url_encoded_path} | jq --raw-output .default_branch`.tr("\n", '')
end