From f1f5863bfc5727dba4767a54a299b0cf526b025a Mon Sep 17 00:00:00 2001 From: Douglas Barbosa Alexandre Date: Mon, 22 Aug 2016 15:45:29 -0300 Subject: Add an endpoint to get the Bitbucket user profile --- lib/bitbucket/representation/base.rb | 13 +++++++++++++ lib/bitbucket/representation/user.rb | 9 +++++++++ 2 files changed, 22 insertions(+) create mode 100644 lib/bitbucket/representation/base.rb create mode 100644 lib/bitbucket/representation/user.rb (limited to 'lib/bitbucket/representation') diff --git a/lib/bitbucket/representation/base.rb b/lib/bitbucket/representation/base.rb new file mode 100644 index 00000000000..7b639492d38 --- /dev/null +++ b/lib/bitbucket/representation/base.rb @@ -0,0 +1,13 @@ +module Bitbucket + module Representation + class Base + def initialize(raw) + @raw = raw + end + + private + + attr_reader :raw + end + end +end diff --git a/lib/bitbucket/representation/user.rb b/lib/bitbucket/representation/user.rb new file mode 100644 index 00000000000..ba6b7667b49 --- /dev/null +++ b/lib/bitbucket/representation/user.rb @@ -0,0 +1,9 @@ +module Bitbucket + module Representation + class User < Representation::Base + def username + raw['username'] + end + end + end +end -- cgit v1.2.1 From 6418c6f88efe9015c8bc2ebd4f7db1a7277a4dc9 Mon Sep 17 00:00:00 2001 From: Douglas Barbosa Alexandre Date: Mon, 22 Aug 2016 15:53:46 -0300 Subject: Add an endpoint to get the user's repositories --- lib/bitbucket/representation/repo.rb | 57 ++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 lib/bitbucket/representation/repo.rb (limited to 'lib/bitbucket/representation') diff --git a/lib/bitbucket/representation/repo.rb b/lib/bitbucket/representation/repo.rb new file mode 100644 index 00000000000..fe5cda66ab9 --- /dev/null +++ b/lib/bitbucket/representation/repo.rb @@ -0,0 +1,57 @@ +module Bitbucket + module Representation + class Repo < Representation::Base + attr_reader :owner, :slug + + def initialize(raw) + super(raw) + + if full_name && full_name.split('/').size == 2 + @owner, @slug = full_name.split('/') + end + end + + def clone_url(token = nil) + url = raw['links']['clone'].find { |link| link['name'] == 'https' }.fetch('href') + + if token.present? + url.sub(/^[^\@]*/, "https://x-token-auth:#{token}") + else + url + end + end + + def description + raw['description'] + end + + def full_name + raw['full_name'] + end + + def has_issues? + raw['has_issues'] + end + + def name + raw['name'] + end + + def valid? + raw['scm'] == 'git' + end + + def visibility_level + if raw['is_private'] + Gitlab::VisibilityLevel::PRIVATE + else + Gitlab::VisibilityLevel::PUBLIC + end + end + + def to_s + full_name + end + end + end +end -- cgit v1.2.1 From 3dd15d3f753a5a71522275a37393bfa56d6e3517 Mon Sep 17 00:00:00 2001 From: Douglas Barbosa Alexandre Date: Mon, 22 Aug 2016 16:09:25 -0300 Subject: Add an endpoint to get a list of issues for a repo --- lib/bitbucket/representation/issue.rb | 49 +++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 lib/bitbucket/representation/issue.rb (limited to 'lib/bitbucket/representation') 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 -- cgit v1.2.1 From 3f59d25d263d1ac9db76cd2d3d4d025fb6d6dff4 Mon Sep 17 00:00:00 2001 From: Douglas Barbosa Alexandre Date: Mon, 22 Aug 2016 16:10:29 -0300 Subject: Add an endpoint to get a list of issue comments --- lib/bitbucket/representation/comment.rb | 27 +++++++++++++++++++++++++++ lib/bitbucket/representation/url.rb | 9 +++++++++ 2 files changed, 36 insertions(+) create mode 100644 lib/bitbucket/representation/comment.rb create mode 100644 lib/bitbucket/representation/url.rb (limited to 'lib/bitbucket/representation') diff --git a/lib/bitbucket/representation/comment.rb b/lib/bitbucket/representation/comment.rb new file mode 100644 index 00000000000..94bc18cbfab --- /dev/null +++ b/lib/bitbucket/representation/comment.rb @@ -0,0 +1,27 @@ +module Bitbucket + module Representation + class Comment < Representation::Base + def author + user.fetch('username', 'Anonymous') + end + + def note + raw.dig('content', 'raw') + end + + def created_at + raw['created_on'] + end + + def updated_at + raw['updated_on'] || raw['created_on'] + end + + private + + def user + raw.fetch('user', {}) + end + end + end +end diff --git a/lib/bitbucket/representation/url.rb b/lib/bitbucket/representation/url.rb new file mode 100644 index 00000000000..24ae1048013 --- /dev/null +++ b/lib/bitbucket/representation/url.rb @@ -0,0 +1,9 @@ +module Bitbucket + module Representation + class Url < Representation::Base + def to_s + raw.dig('links', 'self', 'href') + end + end + end +end -- cgit v1.2.1 From 64722a15e39436820a0636804179cf8c8957197e Mon Sep 17 00:00:00 2001 From: Douglas Barbosa Alexandre Date: Mon, 22 Aug 2016 16:15:15 -0300 Subject: Add an endpoint to get a list of pull requests for a repo --- lib/bitbucket/representation/pull_request.rb | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 lib/bitbucket/representation/pull_request.rb (limited to 'lib/bitbucket/representation') diff --git a/lib/bitbucket/representation/pull_request.rb b/lib/bitbucket/representation/pull_request.rb new file mode 100644 index 00000000000..7cbad91e9c8 --- /dev/null +++ b/lib/bitbucket/representation/pull_request.rb @@ -0,0 +1,6 @@ +module Bitbucket + module Representation + class PullRequest < Representation::Base + end + end +end -- cgit v1.2.1 From 704115c726999d6f0467bbf70087db3ae690d3ab Mon Sep 17 00:00:00 2001 From: Douglas Barbosa Alexandre Date: Mon, 22 Aug 2016 16:15:39 -0300 Subject: Import opened pull request from Bitbucket --- lib/bitbucket/representation/pull_request.rb | 59 ++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) (limited to 'lib/bitbucket/representation') diff --git a/lib/bitbucket/representation/pull_request.rb b/lib/bitbucket/representation/pull_request.rb index 7cbad91e9c8..e7b1f99e9a6 100644 --- a/lib/bitbucket/representation/pull_request.rb +++ b/lib/bitbucket/representation/pull_request.rb @@ -1,6 +1,65 @@ module Bitbucket module Representation class PullRequest < Representation::Base + def author + raw.fetch('author', {}).fetch('username', 'Anonymous') + end + + def description + raw['description'] + end + + def iid + raw['id'] + end + + def state + if raw['state'] == 'MERGED' + 'merged' + elsif raw['state'] == 'DECLINED' + 'closed' + else + 'opened' + end + end + + def created_at + raw['created_on'] + end + + def updated_at + raw['updated_on'] + end + + def title + raw['title'] + end + + def source_branch_name + source_branch.dig('branch', 'name') + end + + def source_branch_sha + source_branch.dig('commit', 'hash') + end + + def target_branch_name + target_branch.dig('branch', 'name') + end + + def target_branch_sha + target_branch.dig('commit', 'hash') + end + + private + + def source_branch + raw['source'] + end + + def target_branch + raw['destination'] + end end end end -- cgit v1.2.1 From ea393e6f308e5dcdd5c48433285594db0539b203 Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Wed, 16 Nov 2016 00:13:17 -0800 Subject: Import pull request comments --- .../representation/pull_request_comment.rb | 39 ++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 lib/bitbucket/representation/pull_request_comment.rb (limited to 'lib/bitbucket/representation') diff --git a/lib/bitbucket/representation/pull_request_comment.rb b/lib/bitbucket/representation/pull_request_comment.rb new file mode 100644 index 00000000000..94719edbf38 --- /dev/null +++ b/lib/bitbucket/representation/pull_request_comment.rb @@ -0,0 +1,39 @@ +module Bitbucket + module Representation + class PullRequestComment < Comment + def iid + raw['id'] + end + + def file_path + inline.fetch('path', nil) + end + + def old_pos + inline.fetch('from', nil) || 1 + end + + def new_pos + inline.fetch('to', nil) || 1 + end + + def parent_id + raw.fetch('parent', {}).fetch('id', nil) + end + + def inline? + raw.has_key?('inline') + end + + def has_parent? + raw.has_key?('parent') + end + + private + + def inline + raw.fetch('inline', {}) + end + end + end +end -- cgit v1.2.1 From 4d7303a98e970c29079cc03a449c71f3cdaa1214 Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Fri, 18 Nov 2016 21:35:03 -0800 Subject: Clean up owner and slug representation --- lib/bitbucket/representation/repo.rb | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'lib/bitbucket/representation') diff --git a/lib/bitbucket/representation/repo.rb b/lib/bitbucket/representation/repo.rb index fe5cda66ab9..b291dfe0441 100644 --- a/lib/bitbucket/representation/repo.rb +++ b/lib/bitbucket/representation/repo.rb @@ -5,10 +5,18 @@ module Bitbucket def initialize(raw) super(raw) + end - if full_name && full_name.split('/').size == 2 - @owner, @slug = full_name.split('/') - end + def owner_and_slug + @owner_and_slug ||= full_name.split('/', 2) + end + + def owner + owner_and_slug.first + end + + def slug + owner_and_slug.last end def clone_url(token = nil) -- cgit v1.2.1 From 54221b5a3b9a2489f979944c77298c4adf004984 Mon Sep 17 00:00:00 2001 From: Valery Sizov Date: Mon, 5 Dec 2016 20:34:11 +0200 Subject: Fix inline comment importing for 1:1 diff type --- lib/bitbucket/representation/pull_request_comment.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/bitbucket/representation') diff --git a/lib/bitbucket/representation/pull_request_comment.rb b/lib/bitbucket/representation/pull_request_comment.rb index 94719edbf38..38090188919 100644 --- a/lib/bitbucket/representation/pull_request_comment.rb +++ b/lib/bitbucket/representation/pull_request_comment.rb @@ -14,7 +14,7 @@ module Bitbucket end def new_pos - inline.fetch('to', nil) || 1 + inline.fetch('to', nil) || old_pos || 1 end def parent_id -- cgit v1.2.1 From 84f2c219aa33de4890c7681372dd03309f216795 Mon Sep 17 00:00:00 2001 From: Valery Sizov Date: Tue, 6 Dec 2016 13:46:59 +0200 Subject: Fix importing inline comment for any diff type --- lib/bitbucket/representation/pull_request_comment.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/bitbucket/representation') diff --git a/lib/bitbucket/representation/pull_request_comment.rb b/lib/bitbucket/representation/pull_request_comment.rb index 38090188919..c63d749cba7 100644 --- a/lib/bitbucket/representation/pull_request_comment.rb +++ b/lib/bitbucket/representation/pull_request_comment.rb @@ -10,11 +10,11 @@ module Bitbucket end def old_pos - inline.fetch('from', nil) || 1 + inline.fetch('from', nil) end def new_pos - inline.fetch('to', nil) || old_pos || 1 + inline.fetch('to', nil) end def parent_id -- cgit v1.2.1 From 67b7637e5d7d3cf3e3f5cde6e7f984ece368c48c Mon Sep 17 00:00:00 2001 From: Valery Sizov Date: Wed, 7 Dec 2016 11:33:32 +0200 Subject: Apply review comments. Iteration 1 --- lib/bitbucket/representation/issue.rb | 6 +----- lib/bitbucket/representation/pull_request_comment.rb | 2 +- lib/bitbucket/representation/repo.rb | 6 ++++-- 3 files changed, 6 insertions(+), 8 deletions(-) (limited to 'lib/bitbucket/representation') diff --git a/lib/bitbucket/representation/issue.rb b/lib/bitbucket/representation/issue.rb index 48647ad51f6..dc034c19750 100644 --- a/lib/bitbucket/representation/issue.rb +++ b/lib/bitbucket/representation/issue.rb @@ -8,7 +8,7 @@ module Bitbucket end def author - reporter.fetch('username', 'Anonymous') + raw.dig('reporter', 'username') || 'Anonymous' end def description @@ -40,10 +40,6 @@ module Bitbucket def closed? CLOSED_STATUS.include?(raw['state']) end - - def reporter - raw.fetch('reporter', {}) - end end end end diff --git a/lib/bitbucket/representation/pull_request_comment.rb b/lib/bitbucket/representation/pull_request_comment.rb index c63d749cba7..ae2b069d6a2 100644 --- a/lib/bitbucket/representation/pull_request_comment.rb +++ b/lib/bitbucket/representation/pull_request_comment.rb @@ -18,7 +18,7 @@ module Bitbucket end def parent_id - raw.fetch('parent', {}).fetch('id', nil) + raw.dig('parent', 'id') end def inline? diff --git a/lib/bitbucket/representation/repo.rb b/lib/bitbucket/representation/repo.rb index b291dfe0441..8969ecd1c19 100644 --- a/lib/bitbucket/representation/repo.rb +++ b/lib/bitbucket/representation/repo.rb @@ -23,7 +23,9 @@ module Bitbucket url = raw['links']['clone'].find { |link| link['name'] == 'https' }.fetch('href') if token.present? - url.sub(/^[^\@]*/, "https://x-token-auth:#{token}") + clone_url = URI::parse(url) + clone_url.user = "x-token-auth:#{token}" + clone_url.to_s else url end @@ -37,7 +39,7 @@ module Bitbucket raw['full_name'] end - def has_issues? + def issues_enabled? raw['has_issues'] end -- cgit v1.2.1 From b12d6541835024eb74384551b84bf0e74747d0c3 Mon Sep 17 00:00:00 2001 From: Valery Sizov Date: Wed, 7 Dec 2016 14:00:06 +0200 Subject: BitBuckpet importer. Refactoring. Iteration 2 --- lib/bitbucket/representation/base.rb | 4 ++++ lib/bitbucket/representation/url.rb | 9 --------- 2 files changed, 4 insertions(+), 9 deletions(-) delete mode 100644 lib/bitbucket/representation/url.rb (limited to 'lib/bitbucket/representation') diff --git a/lib/bitbucket/representation/base.rb b/lib/bitbucket/representation/base.rb index 7b639492d38..94adaacc9b5 100644 --- a/lib/bitbucket/representation/base.rb +++ b/lib/bitbucket/representation/base.rb @@ -5,6 +5,10 @@ module Bitbucket @raw = raw end + def self.decorate(entries) + entries.map { |entry| new(entry)} + end + private attr_reader :raw diff --git a/lib/bitbucket/representation/url.rb b/lib/bitbucket/representation/url.rb deleted file mode 100644 index 24ae1048013..00000000000 --- a/lib/bitbucket/representation/url.rb +++ /dev/null @@ -1,9 +0,0 @@ -module Bitbucket - module Representation - class Url < Representation::Base - def to_s - raw.dig('links', 'self', 'href') - end - end - end -end -- cgit v1.2.1 From 00cd864237d6c7ec57ecb49d304ca8dfa9e41d31 Mon Sep 17 00:00:00 2001 From: Valery Sizov Date: Wed, 7 Dec 2016 18:04:02 +0200 Subject: BitBucket importer: import issues with labels --- lib/bitbucket/representation/issue.rb | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lib/bitbucket/representation') diff --git a/lib/bitbucket/representation/issue.rb b/lib/bitbucket/representation/issue.rb index dc034c19750..6c8e9a4c244 100644 --- a/lib/bitbucket/representation/issue.rb +++ b/lib/bitbucket/representation/issue.rb @@ -7,6 +7,10 @@ module Bitbucket raw['id'] end + def kind + raw['kind'] + end + def author raw.dig('reporter', 'username') || 'Anonymous' end -- cgit v1.2.1 From a2be395401f6320d2722bbd98de0c046d05f0480 Mon Sep 17 00:00:00 2001 From: Valery Sizov Date: Mon, 12 Dec 2016 20:41:55 +0200 Subject: specs for bitbucket representers --- lib/bitbucket/representation/pull_request_comment.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib/bitbucket/representation') diff --git a/lib/bitbucket/representation/pull_request_comment.rb b/lib/bitbucket/representation/pull_request_comment.rb index ae2b069d6a2..4f3809fbcea 100644 --- a/lib/bitbucket/representation/pull_request_comment.rb +++ b/lib/bitbucket/representation/pull_request_comment.rb @@ -6,15 +6,15 @@ module Bitbucket end def file_path - inline.fetch('path', nil) + inline.fetch('path') end def old_pos - inline.fetch('from', nil) + inline.fetch('from') end def new_pos - inline.fetch('to', nil) + inline.fetch('to') end def parent_id -- cgit v1.2.1 From e39f024029b46322c1bf24409fd5ce7bfcef2da5 Mon Sep 17 00:00:00 2001 From: Valery Sizov Date: Tue, 13 Dec 2016 21:28:04 +0200 Subject: BB importer: Adding created_by only when used is not found[ci skip] --- lib/bitbucket/representation/base.rb | 4 ++++ lib/bitbucket/representation/comment.rb | 2 +- lib/bitbucket/representation/issue.rb | 2 +- lib/bitbucket/representation/pull_request.rb | 2 +- lib/bitbucket/representation/user.rb | 6 +++++- 5 files changed, 12 insertions(+), 4 deletions(-) (limited to 'lib/bitbucket/representation') diff --git a/lib/bitbucket/representation/base.rb b/lib/bitbucket/representation/base.rb index 94adaacc9b5..fd622d333da 100644 --- a/lib/bitbucket/representation/base.rb +++ b/lib/bitbucket/representation/base.rb @@ -5,6 +5,10 @@ module Bitbucket @raw = raw end + def user_representation(raw) + User.new(raw) + end + def self.decorate(entries) entries.map { |entry| new(entry)} end diff --git a/lib/bitbucket/representation/comment.rb b/lib/bitbucket/representation/comment.rb index 94bc18cbfab..bc40f891cd3 100644 --- a/lib/bitbucket/representation/comment.rb +++ b/lib/bitbucket/representation/comment.rb @@ -2,7 +2,7 @@ module Bitbucket module Representation class Comment < Representation::Base def author - user.fetch('username', 'Anonymous') + user_representation(user) end def note diff --git a/lib/bitbucket/representation/issue.rb b/lib/bitbucket/representation/issue.rb index 6c8e9a4c244..90adfa3331a 100644 --- a/lib/bitbucket/representation/issue.rb +++ b/lib/bitbucket/representation/issue.rb @@ -12,7 +12,7 @@ module Bitbucket end def author - raw.dig('reporter', 'username') || 'Anonymous' + user_representation(raw.fetch('reporter', {})) end def description diff --git a/lib/bitbucket/representation/pull_request.rb b/lib/bitbucket/representation/pull_request.rb index e7b1f99e9a6..96992003d24 100644 --- a/lib/bitbucket/representation/pull_request.rb +++ b/lib/bitbucket/representation/pull_request.rb @@ -2,7 +2,7 @@ module Bitbucket module Representation class PullRequest < Representation::Base def author - raw.fetch('author', {}).fetch('username', 'Anonymous') + user_representation(raw.fetch('author', {})) end def description diff --git a/lib/bitbucket/representation/user.rb b/lib/bitbucket/representation/user.rb index ba6b7667b49..6025a9f0653 100644 --- a/lib/bitbucket/representation/user.rb +++ b/lib/bitbucket/representation/user.rb @@ -2,7 +2,11 @@ module Bitbucket module Representation class User < Representation::Base def username - raw['username'] + raw['username'] || 'Anonymous' + end + + def uuid + raw['uuid'] end end end -- cgit v1.2.1 From 8f0cef0b6e5e950efdf3ebfe8f9f846095fff9d9 Mon Sep 17 00:00:00 2001 From: Valery Sizov Date: Wed, 14 Dec 2016 12:35:10 +0200 Subject: BB importer: Refactoring user importing logic[ci skip] --- lib/bitbucket/representation/base.rb | 4 ---- lib/bitbucket/representation/comment.rb | 2 +- lib/bitbucket/representation/issue.rb | 2 +- lib/bitbucket/representation/pull_request.rb | 2 +- lib/bitbucket/representation/user.rb | 6 +----- 5 files changed, 4 insertions(+), 12 deletions(-) (limited to 'lib/bitbucket/representation') diff --git a/lib/bitbucket/representation/base.rb b/lib/bitbucket/representation/base.rb index fd622d333da..94adaacc9b5 100644 --- a/lib/bitbucket/representation/base.rb +++ b/lib/bitbucket/representation/base.rb @@ -5,10 +5,6 @@ module Bitbucket @raw = raw end - def user_representation(raw) - User.new(raw) - end - def self.decorate(entries) entries.map { |entry| new(entry)} end diff --git a/lib/bitbucket/representation/comment.rb b/lib/bitbucket/representation/comment.rb index bc40f891cd3..3c75e9368fa 100644 --- a/lib/bitbucket/representation/comment.rb +++ b/lib/bitbucket/representation/comment.rb @@ -2,7 +2,7 @@ module Bitbucket module Representation class Comment < Representation::Base def author - user_representation(user) + user['username'] end def note diff --git a/lib/bitbucket/representation/issue.rb b/lib/bitbucket/representation/issue.rb index 90adfa3331a..ffe8a65d839 100644 --- a/lib/bitbucket/representation/issue.rb +++ b/lib/bitbucket/representation/issue.rb @@ -12,7 +12,7 @@ module Bitbucket end def author - user_representation(raw.fetch('reporter', {})) + raw.dig('reporter', 'username') end def description diff --git a/lib/bitbucket/representation/pull_request.rb b/lib/bitbucket/representation/pull_request.rb index 96992003d24..e37c9a62c0e 100644 --- a/lib/bitbucket/representation/pull_request.rb +++ b/lib/bitbucket/representation/pull_request.rb @@ -2,7 +2,7 @@ module Bitbucket module Representation class PullRequest < Representation::Base def author - user_representation(raw.fetch('author', {})) + raw.dig('author', 'username') end def description diff --git a/lib/bitbucket/representation/user.rb b/lib/bitbucket/representation/user.rb index 6025a9f0653..ba6b7667b49 100644 --- a/lib/bitbucket/representation/user.rb +++ b/lib/bitbucket/representation/user.rb @@ -2,11 +2,7 @@ module Bitbucket module Representation class User < Representation::Base def username - raw['username'] || 'Anonymous' - end - - def uuid - raw['uuid'] + raw['username'] end end end -- cgit v1.2.1 From e0ef9dc83ebfe102aaf980495b14fd6a06a24fd1 Mon Sep 17 00:00:00 2001 From: Valery Sizov Date: Fri, 16 Dec 2016 12:12:53 +0200 Subject: BB importer: Milestone importer --- lib/bitbucket/representation/issue.rb | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lib/bitbucket/representation') diff --git a/lib/bitbucket/representation/issue.rb b/lib/bitbucket/representation/issue.rb index ffe8a65d839..3af731753d1 100644 --- a/lib/bitbucket/representation/issue.rb +++ b/lib/bitbucket/representation/issue.rb @@ -27,6 +27,10 @@ module Bitbucket raw['title'] end + def milestone + raw.dig('milestone', 'name') + end + def created_at raw['created_on'] end -- cgit v1.2.1 From a3be4aeb7a71cc940394a5f13d09e79fcafdb1d5 Mon Sep 17 00:00:00 2001 From: Douglas Barbosa Alexandre Date: Fri, 16 Dec 2016 19:51:40 -0200 Subject: Avoid use of Hash#dig to keep compatibility with Ruby 2.1 --- lib/bitbucket/representation/comment.rb | 2 +- lib/bitbucket/representation/issue.rb | 6 +++--- lib/bitbucket/representation/pull_request.rb | 10 +++++----- lib/bitbucket/representation/pull_request_comment.rb | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) (limited to 'lib/bitbucket/representation') diff --git a/lib/bitbucket/representation/comment.rb b/lib/bitbucket/representation/comment.rb index 3c75e9368fa..4937aa9728f 100644 --- a/lib/bitbucket/representation/comment.rb +++ b/lib/bitbucket/representation/comment.rb @@ -6,7 +6,7 @@ module Bitbucket end def note - raw.dig('content', 'raw') + raw.fetch('content', {}).fetch('raw', nil) end def created_at diff --git a/lib/bitbucket/representation/issue.rb b/lib/bitbucket/representation/issue.rb index 3af731753d1..054064395c3 100644 --- a/lib/bitbucket/representation/issue.rb +++ b/lib/bitbucket/representation/issue.rb @@ -12,11 +12,11 @@ module Bitbucket end def author - raw.dig('reporter', 'username') + raw.fetch('reporter', {}).fetch('username', nil) end def description - raw.dig('content', 'raw') + raw.fetch('content', {}).fetch('raw', nil) end def state @@ -28,7 +28,7 @@ module Bitbucket end def milestone - raw.dig('milestone', 'name') + raw['milestone']['name'] if raw['milestone'].present? end def created_at diff --git a/lib/bitbucket/representation/pull_request.rb b/lib/bitbucket/representation/pull_request.rb index e37c9a62c0e..eebf8093380 100644 --- a/lib/bitbucket/representation/pull_request.rb +++ b/lib/bitbucket/representation/pull_request.rb @@ -2,7 +2,7 @@ module Bitbucket module Representation class PullRequest < Representation::Base def author - raw.dig('author', 'username') + raw.fetch('author', {}).fetch('username', nil) end def description @@ -36,19 +36,19 @@ module Bitbucket end def source_branch_name - source_branch.dig('branch', 'name') + source_branch.fetch('branch', {}).fetch('name', nil) end def source_branch_sha - source_branch.dig('commit', 'hash') + source_branch.fetch('commit', {}).fetch('hash', nil) end def target_branch_name - target_branch.dig('branch', 'name') + target_branch.fetch('branch', {}).fetch('name', nil) end def target_branch_sha - target_branch.dig('commit', 'hash') + target_branch.fetch('commit', {}).fetch('hash', nil) end private diff --git a/lib/bitbucket/representation/pull_request_comment.rb b/lib/bitbucket/representation/pull_request_comment.rb index 4f3809fbcea..4f8efe03bae 100644 --- a/lib/bitbucket/representation/pull_request_comment.rb +++ b/lib/bitbucket/representation/pull_request_comment.rb @@ -18,7 +18,7 @@ module Bitbucket end def parent_id - raw.dig('parent', 'id') + raw.fetch('parent', {}).fetch('id', nil) end def inline? -- cgit v1.2.1