Class: BitbucketClient

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/pronto/clients/bitbucket_client.rb

Instance Method Summary collapse

Constructor Details

#initialize(username, password) ⇒ BitbucketClient

Returns a new instance of BitbucketClient.



5
6
7
# File 'lib/pronto/clients/bitbucket_client.rb', line 5

def initialize(username, password)
  self.class.basic_auth(username, password)
end

Instance Method Details

#approve_pull_request(slug, pull_id) ⇒ Object



43
44
45
# File 'lib/pronto/clients/bitbucket_client.rb', line 43

def approve_pull_request(slug, pull_id)
  self.class.post("/#{slug}/pullrequests/#{pull_id}/approve")
end

#commit_comments(slug, sha) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/pronto/clients/bitbucket_client.rb', line 9

def commit_comments(slug, sha)
  response = get("/#{slug}/commit/#{sha}/comments?pagelen=100")
  result = parse_comments(openstruct(response))
  while (response['next'])
    response = get response['next']
    result.concat(parse_comments(openstruct(response)))
  end
  result
end

#create_commit_comment(slug, sha, body, path, position) ⇒ Object



19
20
21
# File 'lib/pronto/clients/bitbucket_client.rb', line 19

def create_commit_comment(slug, sha, body, path, position)
  post("/#{slug}/commit/#{sha}/comments", body, path, position)
end

#create_pull_comment(slug, pull_id, body, path, position) ⇒ Object



39
40
41
# File 'lib/pronto/clients/bitbucket_client.rb', line 39

def create_pull_comment(slug, pull_id, body, path, position)
  post("/#{slug}/pullrequests/#{pull_id}/comments", body, path, position)
end

#pull_comments(slug, pull_id) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/pronto/clients/bitbucket_client.rb', line 23

def pull_comments(slug, pull_id)
  response = get("/#{slug}/pullrequests/#{pull_id}/comments?pagelen=100")
  parse_comments(openstruct(response))
  result = parse_comments(openstruct(response))
  while (response['next'])
    response = get response['next']
    result.concat(parse_comments(openstruct(response)))
  end
  result
end

#pull_requests(slug) ⇒ Object



34
35
36
37
# File 'lib/pronto/clients/bitbucket_client.rb', line 34

def pull_requests(slug)
  response = get("/#{slug}/pullrequests?state=OPEN")
  openstruct(response)
end

#unapprove_pull_request(slug, pull_id) ⇒ Object



47
48
49
# File 'lib/pronto/clients/bitbucket_client.rb', line 47

def unapprove_pull_request(slug, pull_id)
  self.class.delete("/#{slug}/pullrequests/#{pull_id}/approve")
end