summaryrefslogtreecommitdiff
path: root/lib/bitbucket
diff options
context:
space:
mode:
authorDouglas Barbosa Alexandre <dbalexandre@gmail.com>2016-08-22 16:09:25 -0300
committerStan Hu <stanhu@gmail.com>2016-11-21 16:47:26 -0800
commit3dd15d3f753a5a71522275a37393bfa56d6e3517 (patch)
tree6eb9c5ca568acf362f6515010bc56d2f9590d6c5 /lib/bitbucket
parent267e27b0cd543e8eeaa04686ad4678c4f553c479 (diff)
downloadgitlab-ce-3dd15d3f753a5a71522275a37393bfa56d6e3517.tar.gz
Add an endpoint to get a list of issues for a repo
Diffstat (limited to 'lib/bitbucket')
-rw-r--r--lib/bitbucket/client.rb7
-rw-r--r--lib/bitbucket/representation/issue.rb49
2 files changed, 56 insertions, 0 deletions
diff --git a/lib/bitbucket/client.rb b/lib/bitbucket/client.rb
index 24984ca0793..ac6e91bb526 100644
--- a/lib/bitbucket/client.rb
+++ b/lib/bitbucket/client.rb
@@ -4,6 +4,13 @@ module Bitbucket
@connection = options.fetch(:connection, Connection.new(options))
end
+ def issues(repo)
+ relative_path = "/repositories/#{repo}/issues"
+ paginator = Paginator.new(connection, relative_path, :issue)
+
+ Collection.new(paginator)
+ end
+
def repo(name)
parsed_response = connection.get("/repositories/#{name}")
diff --git a/lib/bitbucket/representation/issue.rb b/lib/bitbucket/representation/issue.rb
new file mode 100644
index 00000000000..48647ad51f6
--- /dev/null
+++ b/lib/bitbucket/representation/issue.rb
@@ -0,0 +1,49 @@
+module Bitbucket
+ module Representation
+ class Issue < Representation::Base
+ CLOSED_STATUS = %w(resolved invalid duplicate wontfix closed).freeze
+
+ def iid
+ raw['id']
+ end
+
+ def author
+ reporter.fetch('username', 'Anonymous')
+ end
+
+ def description
+ raw.dig('content', 'raw')
+ end
+
+ def state
+ closed? ? 'closed' : 'opened'
+ end
+
+ def title
+ raw['title']
+ end
+
+ def created_at
+ raw['created_on']
+ end
+
+ def updated_at
+ raw['edited_on']
+ end
+
+ def to_s
+ iid
+ end
+
+ private
+
+ def closed?
+ CLOSED_STATUS.include?(raw['state'])
+ end
+
+ def reporter
+ raw.fetch('reporter', {})
+ end
+ end
+ end
+end