Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump faraday, faraday_middleware and Bitbucket API versions #98

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions bitbucket_rest_api.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ Gem::Specification.new do |gem|
gem.require_paths = %w[ lib ]

gem.add_dependency 'hashie'
gem.add_dependency 'faraday', '~> 0.9.0'
gem.add_dependency 'faraday', '~> 1'
gem.add_dependency 'multi_json', '>= 1.7.5', '< 2.0'
gem.add_dependency 'faraday_middleware', '~> 0.9.0'
gem.add_dependency 'faraday_middleware', '~> 1'
gem.add_dependency 'nokogiri', '>= 1.5.2'
gem.add_dependency 'simple_oauth'

Expand Down
1 change: 1 addition & 0 deletions lib/bitbucket_rest_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def lookup_constant(const_name)
:Result => 'result',

:Repos => 'repos',
:Workspaces => 'workspaces',
#:Error => 'error',
:Issues => 'issues',
:User => 'user',
Expand Down
4 changes: 4 additions & 0 deletions lib/bitbucket_rest_api/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ def repos(options = {})
end
alias :repositories :repos

def workspaces(options = {})
@workspaces ||= ApiFactory.new 'Workspaces', options
end

def search(options = {})
raise "Unimplemented"
#@search ||= ApiFactory.new 'Search', options
Expand Down
2 changes: 1 addition & 1 deletion lib/bitbucket_rest_api/invitations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def invite(user_name, repo_name, emailaddress, perm)
_validate_presence_of emailaddress
perm ||= "write"

post_request("/1.0/invitations/#{user}/#{repo.downcase}/#{emailaddress}",
post_request("/2.0/invitations/#{user}/#{repo.downcase}/#{emailaddress}",
permission: perm)
end
end
Expand Down
16 changes: 8 additions & 8 deletions lib/bitbucket_rest_api/issues.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def milestones
# bitbucket = BitBucket.new :user => 'user-name', :repo => 'repo-name'
# bitbucket.issues.list_repo :filter => 'kind=bug&kind=enhancement'
#
def list_repo(user_name, repo_name, params={ })
def list_repo(user_name, repo_name, params = {})
_update_user_repo_params(user_name, repo_name)
_validate_user_repo_params(user, repo) unless user? && repo?

Expand All @@ -82,9 +82,9 @@ def list_repo(user_name, repo_name, params={ })
# _merge_mime_type(:issue, params)
assert_valid_values(VALID_ISSUE_PARAM_VALUES, params)

response = get_request("/1.0/repositories/#{user}/#{repo.downcase}/issues", params)
return response.issues unless block_given?
response.issues.each { |el| yield el }
response = get_request("/2.0/repositories/#{user}/#{repo.downcase}/issues", params)
return response unless block_given?
response["values"].each { |el| yield el }
end

alias :list_repository :list_repo
Expand All @@ -103,7 +103,7 @@ def get(user_name, repo_name, issue_id, params={ })
normalize! params
# _merge_mime_type(:issue, params)

get_request("/1.0/repositories/#{user}/#{repo.downcase}/issues/#{issue_id}", params)
get_request("/2.0/repositories/#{user}/#{repo.downcase}/issues/#{issue_id}", params)
end

alias :find :get
Expand All @@ -122,7 +122,7 @@ def delete(user_name, repo_name, issue_id, params={ })
normalize! params
# _merge_mime_type(:issue, params)

delete_request("/1.0/repositories/#{user}/#{repo}/issues/#{issue_id}", params)
delete_request("/2.0/repositories/#{user}/#{repo}/issues/#{issue_id}", params)
end

# Create an issue
Expand Down Expand Up @@ -173,7 +173,7 @@ def create(user_name, repo_name, params={ })
filter! VALID_ISSUE_PARAM_NAMES, params
assert_required_keys(%w[ title ], params)

post_request("/1.0/repositories/#{user}/#{repo.downcase}/issues/", params)
post_request("/2.0/repositories/#{user}/#{repo.downcase}/issues/", params)
end

# Edit an issue
Expand Down Expand Up @@ -223,7 +223,7 @@ def edit(user_name, repo_name, issue_id, params={ })
# _merge_mime_type(:issue, params)
filter! VALID_ISSUE_PARAM_NAMES, params

put_request("/1.0/repositories/#{user}/#{repo.downcase}/issues/#{issue_id}/", params)
put_request("/2.0/repositories/#{user}/#{repo.downcase}/issues/#{issue_id}/", params)
end

end # Issues
Expand Down
10 changes: 5 additions & 5 deletions lib/bitbucket_rest_api/issues/comments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def list(user_name, repo_name, issue_id, params={})
normalize! params
# _merge_mime_type(:issue_comment, params)

response = get_request("/1.0/repositories/#{user}/#{repo.downcase}/issues/#{issue_id}/comments/", params)
response = get_request("/2.0/repositories/#{user}/#{repo.downcase}/issues/#{issue_id}/comments/", params)
return response unless block_given?
response.each { |el| yield el }
end
Expand All @@ -47,7 +47,7 @@ def get(user_name, repo_name, comment_id, params={})
normalize! params
# _merge_mime_type(:issue_comment, params)

get_request("/1.0/repositories/#{user}/#{repo.downcase}/issues/comments/#{comment_id}", params)
get_request("/2.0/repositories/#{user}/#{repo.downcase}/issues/comments/#{comment_id}", params)
end
alias :find :get

Expand All @@ -71,7 +71,7 @@ def create(user_name, repo_name, issue_id, params={})
filter! VALID_ISSUE_COMMENT_PARAM_NAME, params
assert_required_keys(%w[ content ], params)

post_request("/1.0/repositories/#{user}/#{repo.downcase}/issues/#{issue_id}/comments/", params)
post_request("/2.0/repositories/#{user}/#{repo.downcase}/issues/#{issue_id}/comments/", params)
end

# Edit a comment
Expand All @@ -94,7 +94,7 @@ def edit(user_name, repo_name, comment_id, params={})
filter! VALID_ISSUE_COMMENT_PARAM_NAME, params
assert_required_keys(%w[ content ], params)

put_request("/1.0/repositories/#{user}/#{repo.downcase}/issues/comments/#{comment_id}", params)
put_request("/2.0/repositories/#{user}/#{repo.downcase}/issues/comments/#{comment_id}", params)
end

# Delete a comment
Expand All @@ -111,7 +111,7 @@ def delete(user_name, repo_name, comment_id, params={})
normalize! params
# _merge_mime_type(:issue_comment, params)

delete_request("/1.0/repositories/#{user}/#{repo.downcase}/issues/comments/#{comment_id}", params)
delete_request("/2.0/repositories/#{user}/#{repo.downcase}/issues/comments/#{comment_id}", params)
end

end # Issues::Comments
Expand Down
10 changes: 5 additions & 5 deletions lib/bitbucket_rest_api/issues/components.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def list(user_name, repo_name, params={})
_validate_user_repo_params(user, repo) unless user? && repo?
normalize! params

response = get_request("/1.0/repositories/#{user}/#{repo.downcase}/issues/components", params)
response = get_request("/2.0/repositories/#{user}/#{repo.downcase}/issues/components", params)
return response unless block_given?
response.each { |el| yield el }
end
Expand All @@ -39,7 +39,7 @@ def get(user_name, repo_name, component_id, params={})
_validate_presence_of component_id
normalize! params

get_request("/1.0/repositories/#{user}/#{repo.downcase}/issues/components/#{component_id}", params)
get_request("/2.0/repositories/#{user}/#{repo.downcase}/issues/components/#{component_id}", params)
end
alias :find :get

Expand All @@ -60,7 +60,7 @@ def create(user_name, repo_name, params={})
filter! VALID_COMPONENT_INPUTS, params
assert_required_keys(VALID_COMPONENT_INPUTS, params)

post_request("/1.0/repositories/#{user}/#{repo.downcase}/issues/components", params)
post_request("/2.0/repositories/#{user}/#{repo.downcase}/issues/components", params)
end

# Update a component
Expand All @@ -82,7 +82,7 @@ def update(user_name, repo_name, component_id, params={})
filter! VALID_COMPONENT_INPUTS, params
assert_required_keys(VALID_COMPONENT_INPUTS, params)

put_request("/1.0/repositories/#{user}/#{repo.downcase}/issues/components/#{component_id}", params)
put_request("/2.0/repositories/#{user}/#{repo.downcase}/issues/components/#{component_id}", params)
end
alias :edit :update

Expand All @@ -99,7 +99,7 @@ def delete(user_name, repo_name, component_id, params={})
_validate_presence_of component_id
normalize! params

delete_request("/1.0/repositories/#{user}/#{repo.downcase}/issues/components/#{component_id}", params)
delete_request("/2.0/repositories/#{user}/#{repo.downcase}/issues/components/#{component_id}", params)
end

end # Issues::Components
Expand Down
10 changes: 5 additions & 5 deletions lib/bitbucket_rest_api/issues/milestones.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def list(user_name, repo_name, params={})

normalize! params

response = get_request("/1.0/repositories/#{user}/#{repo.downcase}/issues/milestones", params)
response = get_request("/2.0/repositories/#{user}/#{repo.downcase}/issues/milestones", params)
return response unless block_given?
response.each { |el| yield el }
end
Expand All @@ -42,7 +42,7 @@ def get(user_name, repo_name, milestone_id, params={})
_validate_presence_of milestone_id
normalize! params

get_request("/1.0/repositories/#{user}/#{repo.downcase}/issues/milestones/#{milestone_id}", params)
get_request("/2.0/repositories/#{user}/#{repo.downcase}/issues/milestones/#{milestone_id}", params)
end
alias :find :get

Expand All @@ -63,7 +63,7 @@ def create(user_name, repo_name, params={})
filter! VALID_MILESTONE_INPUTS, params
assert_required_keys(%w[ name ], params)

post_request("/1.0/repositories/#{user}/#{repo.downcase}/issues/milestones", params)
post_request("/2.0/repositories/#{user}/#{repo.downcase}/issues/milestones", params)
end

# Update a milestone
Expand All @@ -85,7 +85,7 @@ def update(user_name, repo_name, milestone_id, params={})
filter! VALID_MILESTONE_INPUTS, params
assert_required_keys(%w[ name ], params)

put_request("/1.0/repositories/#{user}/#{repo.downcase}/issues/milestones/#{milestone_id}", params)
put_request("/2.0/repositories/#{user}/#{repo.downcase}/issues/milestones/#{milestone_id}", params)
end

# Delete a milestone
Expand All @@ -100,7 +100,7 @@ def delete(user_name, repo_name, milestone_id, params={})
_validate_presence_of milestone_id
normalize! params

delete_request("/1.0/repositories/#{user}/#{repo.downcase}/issues/milestones/#{milestone_id}", params)
delete_request("/2.0/repositories/#{user}/#{repo.downcase}/issues/milestones/#{milestone_id}", params)
end

end # Issues::Milestones
Expand Down
64 changes: 44 additions & 20 deletions lib/bitbucket_rest_api/repos.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,20 @@ class Repos < API

# Load all the modules after initializing Repos to avoid superclass mismatch
autoload_all 'bitbucket_rest_api/repos',
:Changesets => 'changesets',
:Keys => 'keys',
:Services => 'services',
:Following => 'following',
:Sources => 'sources',
:Forks => 'forks',
:Commits => 'commits',
:Download => 'download',
:Webhooks => 'webhooks',
:PullRequest => 'pull_request',
:DefaultReviewers => 'default_reviewers',
:Components => 'components'
:Changesets => 'changesets',
:Keys => 'keys',
:Services => 'services',
:Following => 'following',
:Sources => 'sources',
:Forks => 'forks',
:Commits => 'commits',
:BranchRestrictions => 'branch_restrictions',
:Pipelines => 'pipelines',
:Download => 'download',
:Webhooks => 'webhooks',
:PullRequest => 'pull_request',
:DefaultReviewers => 'default_reviewers',
:Components => 'components'

DEFAULT_REPO_OPTIONS = {
"website" => "",
Expand Down Expand Up @@ -80,6 +82,14 @@ def download
@download ||=ApiFactory.new "Repos::Download"
end

def branch_restrictions
@branch_restrictions ||= ApiFactory.new "Repos::BranchRestrictions"
end

def pipelines
@pipelines ||= ApiFactory.new "Repos::Pipelines"
end

# Access to Repos::PullRequests API
def pull_request
@pull_request ||= ApiFactory.new 'Repos::PullRequest'
Expand Down Expand Up @@ -112,7 +122,7 @@ def branches(user_name, repo_name, params={})
_validate_user_repo_params(user, repo) unless (user? && repo?)
normalize! params

response = get_request("/1.0/repositories/#{user}/#{repo.downcase}/branches/", params)
response = get_request("/2.0/repositories/#{user}/#{repo.downcase}/refs/branches/", params)
return response unless block_given?
response.each { |el| yield el }
end
Expand Down Expand Up @@ -154,7 +164,7 @@ def create(*args)
assert_required_keys(%w[ name ], params)

# Requires authenticated user
post_request("/1.0/repositories/", DEFAULT_REPO_OPTIONS.merge(params))
post_request("/2.0/repositories/", DEFAULT_REPO_OPTIONS.merge(params))
end

# Edit a repository
Expand Down Expand Up @@ -184,7 +194,7 @@ def edit(user_name, repo_name, params={ })
normalize! params
filter! VALID_REPO_OPTIONS, params

put_request("/1.0/repositories/#{user}/#{repo.downcase}/", DEFAULT_REPO_OPTIONS.merge(params))
put_request("/2.0/repositories/#{user}/#{repo.downcase}/", DEFAULT_REPO_OPTIONS.merge(params))
end

# Get a repository
Expand All @@ -198,7 +208,7 @@ def get(user_name, repo_name, params={ })
_validate_user_repo_params(user, repo) unless user? && repo?
normalize! params

get_request("/1.0/repositories/#{user}/#{repo.downcase}", params)
get_request("/2.0/repositories/#{user}/#{repo.downcase}", params)
end

alias :find :get
Expand All @@ -214,7 +224,7 @@ def delete(user_name, repo_name)
_update_user_repo_params(user_name, repo_name)
_validate_user_repo_params(user, repo) unless user? && repo?

delete_request("/1.0/repositories/#{user}/#{repo.downcase}")
delete_request("/2.0/repositories/#{user}/#{repo.downcase}")
end

# List repositories for the authenticated user
Expand All @@ -233,12 +243,26 @@ def delete(user_name, repo_name)
def list(*args)
params = args.extract_options!
normalize! params
_merge_user_into_params!(params) unless params.has_key?('user')

if params.has_key?('user') && params.has_key?('workspace')
raise StandardError, "Can't pass both the user and the workspace params."
end

path = "/2.0/repositories"

if params.has_key?('user')
path << "/#{params['user']}"
elsif params.has_key?('workspace')
path << "/#{params['workspace']}"
else
_merge_user_into_params!(params)
end

params.merge!('pagelen' => 100) unless params.has_key?('pagelen')

filter! %w[ user role pagelen ], params

response = get_request("/2.0/repositories", params)
response = get_request(path, params)

response = response[:values]
return response unless block_given?
Expand All @@ -259,7 +283,7 @@ def tags(user_name, repo_name, params={ })
_validate_user_repo_params(user, repo) unless user? && repo?
normalize! params

response = get_request("/1.0/repositories/#{user}/#{repo.downcase}/tags/", params)
response = get_request("/2.0/repositories/#{user}/#{repo.downcase}/tags/", params)
return response unless block_given?
response.each { |el| yield el }
end
Expand Down
Loading