class RepoProvider::Bitbucket

API documentation: confluence.atlassian.com/display/BITBUCKET/Use+the+Bitbucket+REST+APIs

Constants

URL_PATTERNS

Public Class Methods

get_repo(url) click to toggle source
# File lib/git-issues/providers/bitbucket.rb, line 14
def self.get_repo url
  # find the url pattern that matches the url
  URL_PATTERNS.map{|p| p.match url }.compact.first
end

Public Instance Methods

issue_close(id) click to toggle source
# File lib/git-issues/providers/bitbucket.rb, line 46
def issue_close id
  res = bitbucket.issues.edit( repo['user'], repo['repo'], id, {status: 'resolved'})
  res['status'] == 'resolved'
end
issue_create(title, content) click to toggle source
# File lib/git-issues/providers/bitbucket.rb, line 32
def issue_create title, content
  ret = bitbucket.issues.create( repo['user'], repo['repo'], {
    title:    title,
    content:  content
    })
  id = ret['resource_uri'].match(/[0-9]+$/)
  id && id[0].to_i || -1
end
issue_delete(id) click to toggle source
# File lib/git-issues/providers/bitbucket.rb, line 51
def issue_delete id
  bitbucket.issues.delete( repo['user'], repo['repo'], id)
end
issue_reopen(id) click to toggle source
# File lib/git-issues/providers/bitbucket.rb, line 41
def issue_reopen id
  res = bitbucket.issues.edit( repo['user'], repo['repo'], id, {status: 'open'})
  res['status'] == 'open'
end
issues_list(opts = {}) click to toggle source
# File lib/git-issues/providers/bitbucket.rb, line 19
def issues_list opts = {}
  # get issues for this repo
  issues = bitbucket.issues.list_repo(repo['user'], repo['repo'])
  # filter closed issues if the user doesn't want all
  if not opts[:all]
    issues = issues.find_all{|i|
        'resolved' != i['status']
      }
  end
  # return issues
  format_issues( issues )
end
provider() click to toggle source
# File lib/git-issues/providers/bitbucket.rb, line 55
def provider
  bitbucket
end

Private Instance Methods

bitbucket() click to toggle source
# File lib/git-issues/providers/bitbucket.rb, line 69
def bitbucket
  init_bitbucket if @bitbucket.nil?
  @bitbucket
end
format_issues(is) click to toggle source
# File lib/git-issues/providers/bitbucket.rb, line 61
def format_issues is
  Array(is).map do |i|
    i['number'] = i['local_id']
    i['state'] = i['status']
    i
  end
end
init_bitbucket() click to toggle source
# File lib/git-issues/providers/bitbucket.rb, line 74
def init_bitbucket
  ot,os = oauth_consumer_key_and_secret
  # get configuration from oauth token and secret
  if( not ot.nil? and not os.nil? )
    @bitbucket = BitBucket.new client_id: ot, client_secret: os
  else
    # use login and password otherwise
    @bitbucket = BitBucket.new login: user, password: password
  end
end