class Sah::API
Attributes
config[RW]
conn[RW]
Public Class Methods
new(config)
click to toggle source
# File lib/sah/api.rb, line 9 def initialize(config) @config = config base_url = (config.url).to_s.sub(/#{config.url.path}$/, '') @conn = Faraday.new(url: base_url) do |faraday| faraday.response :json faraday.response :logger if config.verbose faraday.adapter Faraday.default_adapter faraday.basic_auth config.user, config.password end end
Public Instance Methods
create_pull_request(source, target, title="", description="", reviewers=[])
click to toggle source
# File lib/sah/api.rb, line 85 def create_pull_request(source, target, title="", description="", reviewers=[]) @conn.post do |req| req.url @config.url.path + "/rest/api/1.0/projects/#{target[:project]}/repos/#{target[:repository]}/pull-requests" req.headers['Content-Type'] = 'application/json' req.body = { title: title, description: description, state: "OPEN", closed: false, fromRef: { id: "refs/heads/#{source[:branch]}", repository: { slug: source[:repository], name: nil, project: { key: source[:project] } } }, toRef: { id: "refs/heads/#{target[:branch]}", repository: { slug: target[:repository], name: nil, project: { key: target[:project] } } }, locked: false, reviewers: reviewers.map{ |r| { user: { name: r } } } }.to_json end end
create_repository(project, repo)
click to toggle source
# File lib/sah/api.rb, line 38 def create_repository(project, repo) @conn.post do |req| req.url @config.url.path + "/rest/api/1.0/projects/#{project}/repos" req.headers['Content-Type'] = 'application/json' req.body = {name: repo, scmId: "git", forkable: true}.to_json end end
fork_repository(project, repo, name=nil)
click to toggle source
# File lib/sah/api.rb, line 27 def fork_repository(project, repo, name=nil) body = {slug: repo} body = body.merge(name: name) if name @conn.post do |req| req.url @config.url.path + "/rest/api/1.0/projects/#{project}/repos/#{repo}" req.headers['Content-Type'] = 'application/json' req.body = body.to_json end end
list_project()
click to toggle source
# File lib/sah/api.rb, line 46 def list_project @conn.get do |req| req.url @config.url.path + "/rest/api/1.0/projects" req.params['limit'] = 1000 end end
list_repository(project)
click to toggle source
# File lib/sah/api.rb, line 72 def list_repository(project) @conn.get do |req| req.url @config.url.path + "/rest/api/1.0/projects/#{project}/repos" req.params['limit'] = 1000 end end
list_user()
click to toggle source
# File lib/sah/api.rb, line 59 def list_user @conn.get do |req| req.url @config.url.path + "/rest/api/1.0/users" req.params['limit'] = 1000 end end
show_branches(project, repository)
click to toggle source
# File lib/sah/api.rb, line 21 def show_branches(project, repository) @conn.get do |req| req.url @config.url.path + "/rest/api/1.0/projects/#{project}/repos/#{repository}/branches" end end
show_project(project)
click to toggle source
# File lib/sah/api.rb, line 53 def show_project(project) @conn.get do |req| req.url @config.url.path + "/rest/api/1.0/projects/#{project}" end end
show_repository(project, repository)
click to toggle source
# File lib/sah/api.rb, line 79 def show_repository(project, repository) @conn.get do |req| req.url @config.url.path + "/rest/api/1.0/projects/#{project}/repos/#{repository}" end end
show_user(user)
click to toggle source
# File lib/sah/api.rb, line 66 def show_user(user) @conn.get do |req| req.url @config.url.path + "/rest/api/1.0/users/#{user}" end end