Class: BitbucketPrComment::Bitbucket

Inherits:
Object
  • Object
show all
Defined in:
lib/bitbucket_pr_comment/bitbucket.rb

Instance Method Summary collapse

Constructor Details

#initialize(key, secret, repo_username, repo_slug) ⇒ Bitbucket

Returns a new instance of Bitbucket.



8
9
10
11
12
13
14
15
# File 'lib/bitbucket_pr_comment/bitbucket.rb', line 8

def initialize(key, secret, repo_username, repo_slug)
  bearer_token = "#{key}:#{secret}"
  encoded_bearer_token = Base64.strict_encode64(bearer_token)
  @auth = "Basic #{encoded_bearer_token}"
  @repo_username = repo_username
  @repo_slug = repo_slug
  authorize
end

Instance Method Details

#get_pullreq_comment_list(pullreq_id) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/bitbucket_pr_comment/bitbucket.rb', line 33

def get_pullreq_comment_list(pullreq_id)
  list = []
  page = 1
  loop do
    json = request_bitbucket('get', pullreq_path + "/#{pullreq_id}/comments", '2.0', pagelen: 50, page: page)
    list.concat(json[:values])
    page += 1
    break if json[:next].nil?
  end
  list
end

#get_pullreq_listObject



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/bitbucket_pr_comment/bitbucket.rb', line 21

def get_pullreq_list
  list = []
  page = 1
  loop do
    json = request_bitbucket('get', pullreq_path, '2.0', state: 'OPEN', pagelen: 50, page: page)
    list.concat(json[:values])
    page += 1
    break if json[:next].nil?
  end
  list
end

#get_userObject



17
18
19
# File 'lib/bitbucket_pr_comment/bitbucket.rb', line 17

def get_user
  request_bitbucket('get', '/user', '2.0')
end

#send_pullreq_comment(pullreq_id, content, comment = nil) ⇒ Object



45
46
47
48
49
50
# File 'lib/bitbucket_pr_comment/bitbucket.rb', line 45

def send_pullreq_comment(pullreq_id, content, comment = nil)
  method = comment ? 'put' : 'post'
  path = pullreq_path + "/#{pullreq_id}/comments"
  path += "/#{comment[:id]}" if comment
  request_bitbucket(method, path, '1.0', content: content)
end