-
-
Notifications
You must be signed in to change notification settings - Fork 397
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create branches.rb. Move branch related actions there. Add new method…
…s for (un)protecting branches and creating new branches - which requires Gitlab 6.8-stable or newer. Added tests for new methods and fixed old tests looking for methods in old locations.
- Loading branch information
Showing
10 changed files
with
187 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
class Gitlab::Client | ||
# Defines methods related to repositories. | ||
module Branches | ||
# Gets a list of project repositiory branches. | ||
# | ||
# @example | ||
# Gitlab.branches(42) | ||
# | ||
# @param [Integer] project The ID of a project. | ||
# @param [Hash] options A customizable set of options. | ||
# @option options [Integer] :page The page number. | ||
# @option options [Integer] :per_page The number of results per page. | ||
# @return [Array<Gitlab::ObjectifiedHash>] | ||
def branches(project, options={}) | ||
get("/projects/#{project}/repository/branches", :query => options) | ||
end | ||
alias_method :repo_branches, :branches | ||
|
||
# Gets information about a repository branch. | ||
# | ||
# @example | ||
# Gitlab.branch(3, 'api') | ||
# Gitlab.repo_branch(5, 'master') | ||
# | ||
# @param [Integer] project The ID of a project. | ||
# @param [String] branch The name of the branch. | ||
# @return [Gitlab::ObjectifiedHash] | ||
def branch(project, branch) | ||
get("/projects/#{project}/repository/branches/#{branch}") | ||
end | ||
|
||
alias_method :repo_branch, :branch | ||
|
||
# Protects a repository branch. | ||
# | ||
# @example | ||
# Gitlab.protect_branch(3, 'api') | ||
# Gitlab.repo_protect_branch(5, 'master') | ||
# | ||
# @param [Integer] project The ID of a project. | ||
# @param [String] branch The name of the branch. | ||
# @return [Gitlab::ObjectifiedHash] | ||
def protect_branch(project, branch) | ||
put("/projects/#{project}/repository/branches/#{branch}/protect") | ||
end | ||
alias_method :repo_protect_branch, :protect_branch | ||
|
||
# Unprotects a repository branch. | ||
# | ||
# @example | ||
# Gitlab.unprotect_branch(3, 'api') | ||
# Gitlab.repo_unprotect_branch(5, 'master') | ||
# | ||
# @param [Integer] project The ID of a project. | ||
# @param [String] branch The name of the branch. | ||
# @return [Gitlab::ObjectifiedHash] | ||
def unprotect_branch(project, branch) | ||
put("/projects/#{project}/repository/branches/#{branch}/unprotect") | ||
end | ||
alias_method :repo_unprotect_branch, :unprotect_branch | ||
|
||
# Creates a repository branch. Requires Gitlab >= 6.8.x | ||
# | ||
# @example | ||
# Gitlab.create_branch(3, 'api') | ||
# Gitlab.repo_create_branch(5, 'master') | ||
# | ||
# @param [Integer] project The ID of a project. | ||
# @param [String] branch The name of the new branch. | ||
# @param [String] ref Create branch from commit sha or existing branch | ||
# @return [Gitlab::ObjectifiedHash] | ||
def create_branch(project, branch, ref) | ||
post("/projects/#{project}/repository/branches",:body => {:branch_name => branch, :ref => ref}) | ||
end | ||
alias_method :repo_create_branch, :create_branch | ||
|
||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"name":"api","commit":{"id":"f7dd067490fe57505f7226c3b54d3127d2f7fd46","parents":[{"id":"949b1df930bedace1dbd755aaa4a82e8c451a616"}],"tree":"f8c4b21c036339f92fcc5482aa28a41250553b27","message":"API: expose issues project id","author":{"name":"Nihad Abbasov","email":"narkoz.2008@gmail.com"},"committer":{"name":"Nihad Abbasov","email":"narkoz.2008@gmail.com"},"authored_date":"2012-07-25T04:22:21-07:00","committed_date":"2012-07-25T04:22:21-07:00"},"protected": true} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"name":"api","commit":{ "id":"f7dd067490fe57505f7226c3b54d3127d2f7fd46","message":"API: expose issues project id","parent_ids":["949b1df930bedace1dbd755aaa4a82e8c451a616"],"authored_date":"2012-07-25T04:22:21-07:00","author_name":"Nihad Abbasov","author_email":"narkoz.2008@gmail.com","committed_date":"2012-07-25T04:22:21-07:00","committer_name":"Nihad Abbasov","committer_email":"narkoz.2008@gmail.com"},"protected": false} |
2 changes: 1 addition & 1 deletion
2
spec/fixtures/project_branch.json → spec/fixtures/protect_branch.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"name":"api","commit":{"id":"f7dd067490fe57505f7226c3b54d3127d2f7fd46","parents":[{"id":"949b1df930bedace1dbd755aaa4a82e8c451a616"}],"tree":"f8c4b21c036339f92fcc5482aa28a41250553b27","message":"API: expose issues project id","author":{"name":"Nihad Abbasov","email":"narkoz.2008@gmail.com"},"committer":{"name":"Nihad Abbasov","email":"narkoz.2008@gmail.com"},"authored_date":"2012-07-25T04:22:21-07:00","committed_date":"2012-07-25T04:22:21-07:00"}} | ||
{"name":"api","commit":{"id":"f7dd067490fe57505f7226c3b54d3127d2f7fd46","parents":[{"id":"949b1df930bedace1dbd755aaa4a82e8c451a616"}],"tree":"f8c4b21c036339f92fcc5482aa28a41250553b27","message":"API: expose issues project id","author":{"name":"Nihad Abbasov","email":"narkoz.2008@gmail.com"},"committer":{"name":"Nihad Abbasov","email":"narkoz.2008@gmail.com"},"authored_date":"2012-07-25T04:22:21-07:00","committed_date":"2012-07-25T04:22:21-07:00"},"protected":true} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"name":"api","commit":{"id":"f7dd067490fe57505f7226c3b54d3127d2f7fd46","parents":[{"id":"949b1df930bedace1dbd755aaa4a82e8c451a616"}],"tree":"f8c4b21c036339f92fcc5482aa28a41250553b27","message":"API: expose issues project id","author":{"name":"Nihad Abbasov","email":"narkoz.2008@gmail.com"},"committer":{"name":"Nihad Abbasov","email":"narkoz.2008@gmail.com"},"authored_date":"2012-07-25T04:22:21-07:00","committed_date":"2012-07-25T04:22:21-07:00"},"protected":false} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
require 'spec_helper' | ||
|
||
describe Gitlab::Client do | ||
it { should respond_to :repo_branches } | ||
it { should respond_to :repo_branch } | ||
it { should respond_to :repo_protect_branch } | ||
it { should respond_to :repo_unprotect_branch } | ||
|
||
describe ".branches" do | ||
before do | ||
stub_get("/projects/3/repository/branches", "branches") | ||
@branches = Gitlab.branches(3) | ||
end | ||
|
||
it "should get the correct resource" do | ||
a_get("/projects/3/repository/branches").should have_been_made | ||
end | ||
|
||
it "should return an array of repository branches" do | ||
@branches.should be_an Array | ||
@branches.first.name.should == "api" | ||
end | ||
end | ||
|
||
describe ".branch" do | ||
before do | ||
stub_get("/projects/3/repository/branches/api", "branch") | ||
@branch = Gitlab.branch(3, "api") | ||
end | ||
|
||
it "should get the correct resource" do | ||
a_get("/projects/3/repository/branches/api").should have_been_made | ||
end | ||
|
||
it "should return information about a repository branch" do | ||
@branch.name.should == "api" | ||
end | ||
end | ||
|
||
describe ".protect_branch" do | ||
before do | ||
stub_put("/projects/3/repository/branches/api/protect", "protect_branch") | ||
@branch = Gitlab.protect_branch(3, "api") | ||
end | ||
|
||
it "should get the correct resource" do | ||
a_put("/projects/3/repository/branches/api/protect").should have_been_made | ||
end | ||
|
||
it "should return information about a protected repository branch" do | ||
@branch.name.should == "api" | ||
@branch.protected.should == true | ||
end | ||
end | ||
|
||
describe ".unprotect_branch" do | ||
before do | ||
stub_put("/projects/3/repository/branches/api/unprotect", "unprotect_branch") | ||
@branch = Gitlab.unprotect_branch(3, "api") | ||
end | ||
|
||
it "should get the correct resource" do | ||
a_put("/projects/3/repository/branches/api/unprotect").should have_been_made | ||
end | ||
|
||
it "should return information about an unprotected repository branch" do | ||
@branch.name.should == "api" | ||
@branch.protected.should == false | ||
end | ||
end | ||
|
||
describe ".create_branch" do | ||
context "with branch name" do | ||
before do | ||
stub_post("/projects/3/repository/branches", "create_branch") | ||
@branch = Gitlab.create_branch(3, "api","master") | ||
end | ||
|
||
it "should get the correct resource" do | ||
a_post("/projects/3/repository/branches").should have_been_made | ||
end | ||
|
||
it "should return information about a new repository branch" do | ||
@branch.name.should == "api" | ||
end | ||
end | ||
context "with commit hash" do | ||
before do | ||
stub_post("/projects/3/repository/branches", "create_branch") | ||
@branch = Gitlab.create_branch(3, "api","949b1df930bedace1dbd755aaa4a82e8c451a616") | ||
end | ||
|
||
it "should get the correct resource" do | ||
a_post("/projects/3/repository/branches").should have_been_made | ||
end | ||
|
||
it "should return information about a new repository branch" do | ||
@branch.name.should == "api" | ||
end | ||
end | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters