From 71067ef77357e9b2ca55d966b529d31913e85ef2 Mon Sep 17 00:00:00 2001 From: Richard Huang Date: Sat, 24 Jun 2017 11:11:27 +0800 Subject: [PATCH] get main branch of a repo --- lib/bitbucket_rest_api/repos.rb | 18 ++++++++++++++++++ spec/bitbucket_rest_api/repos_spec.rb | 15 +++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/lib/bitbucket_rest_api/repos.rb b/lib/bitbucket_rest_api/repos.rb index e9a62a1..808b67a 100644 --- a/lib/bitbucket_rest_api/repos.rb +++ b/lib/bitbucket_rest_api/repos.rb @@ -119,6 +119,24 @@ def branches(user_name, repo_name, params={}) alias :list_branches :branches + # Get main branch + # + # = Examples + # + # bitbucket = BitBucket.new + # bibucket.repos.main_branch 'user-name', 'repo-name' + # + # repos = BitBucket::Repos.new + # repos.main_branch 'user-name', 'repo-name' + # + def main_branch(user_name, repo_name, params={}) + _update_user_repo_params(user_name, repo_name) + _validate_user_repo_params(user, repo) unless (user? && repo?) + normalize! params + + get_request("/1.0/repositories/#{user}/#{repo.downcase}/main-branch", params) + end + # FIXME: 'POST a new repository' is a deprecated feature of the API # Create a new repository for the authenticated user. # diff --git a/spec/bitbucket_rest_api/repos_spec.rb b/spec/bitbucket_rest_api/repos_spec.rb index 822e02d..b3465ce 100644 --- a/spec/bitbucket_rest_api/repos_spec.rb +++ b/spec/bitbucket_rest_api/repos_spec.rb @@ -65,6 +65,21 @@ end end + describe '.main_branch' do + before do + expect(repo).to receive(:request).with( + :get, + '/1.0/repositories/mock_username/mock_repo/main-branch', + {}, + {} + ) + end + + it 'should send a GET request for the main branch' do + repo.main_branch('mock_username', 'mock_repo') + end + end + describe '.edit' do before do expect(repo).to receive(:request).with(