diff options
Diffstat (limited to 'lib/bitbucket_server')
-rw-r--r-- | lib/bitbucket_server/client.rb | 4 | ||||
-rw-r--r-- | lib/bitbucket_server/collection.rb | 4 | ||||
-rw-r--r-- | lib/bitbucket_server/connection.rb | 32 | ||||
-rw-r--r-- | lib/bitbucket_server/page.rb | 6 | ||||
-rw-r--r-- | lib/bitbucket_server/representation/activity.rb | 20 | ||||
-rw-r--r-- | lib/bitbucket_server/representation/comment.rb | 22 | ||||
-rw-r--r-- | lib/bitbucket_server/representation/pull_request.rb | 36 | ||||
-rw-r--r-- | lib/bitbucket_server/representation/pull_request_comment.rb | 32 | ||||
-rw-r--r-- | lib/bitbucket_server/representation/repo.rb | 20 |
9 files changed, 88 insertions, 88 deletions
diff --git a/lib/bitbucket_server/client.rb b/lib/bitbucket_server/client.rb index 6a608058813..dfe70fe4910 100644 --- a/lib/bitbucket_server/client.rb +++ b/lib/bitbucket_server/client.rb @@ -32,7 +32,7 @@ module BitbucketServer payload = { name: branch_name, startPoint: sha, - message: 'GitLab temporary branch for import' + message: "GitLab temporary branch for import", } connection.post("/projects/#{project_key}/repos/#{repo}/branches", payload.to_json) @@ -41,7 +41,7 @@ module BitbucketServer def delete_branch(project_key, repo, branch_name, sha) payload = { name: Gitlab::Git::BRANCH_REF_PREFIX + branch_name, - dryRun: false + dryRun: false, } connection.delete(:branches, "/projects/#{project_key}/repos/#{repo}/branches", payload.to_json) diff --git a/lib/bitbucket_server/collection.rb b/lib/bitbucket_server/collection.rb index 7e4b2277bbe..2ef5d71ddaf 100644 --- a/lib/bitbucket_server/collection.rb +++ b/lib/bitbucket_server/collection.rb @@ -37,9 +37,9 @@ module BitbucketServer end def method_missing(method, *args) - return super unless self.respond_to?(method) + return super unless respond_to?(method) - self.__send__(method, *args) do |item| # rubocop:disable GitlabSecurity/PublicSend + __send__(method, *args) do |item| # rubocop:disable GitlabSecurity/PublicSend block_given? ? yield(item) : item end end diff --git a/lib/bitbucket_server/connection.rb b/lib/bitbucket_server/connection.rb index fbd451efb23..272c8f9968d 100644 --- a/lib/bitbucket_server/connection.rb +++ b/lib/bitbucket_server/connection.rb @@ -4,8 +4,8 @@ module BitbucketServer class Connection include ActionView::Helpers::SanitizeHelper - DEFAULT_API_VERSION = '1.0' - SEPARATOR = '/' + DEFAULT_API_VERSION = "1.0" + SEPARATOR = "/" NETWORK_ERRORS = [ SocketError, @@ -15,7 +15,7 @@ module BitbucketServer Errno::EHOSTUNREACH, Net::OpenTimeout, Net::ReadTimeout, - Gitlab::HTTP::BlockedUrlError + Gitlab::HTTP::BlockedUrlError, ].freeze attr_reader :api_version, :base_uri, :username, :token @@ -31,9 +31,9 @@ module BitbucketServer def get(path, extra_query = {}) response = Gitlab::HTTP.get(build_url(path), - basic_auth: auth, - headers: accept_headers, - query: extra_query) + basic_auth: auth, + headers: accept_headers, + query: extra_query) check_errors!(response) @@ -44,9 +44,9 @@ module BitbucketServer def post(path, body) response = Gitlab::HTTP.post(build_url(path), - basic_auth: auth, - headers: post_headers, - body: body) + basic_auth: auth, + headers: post_headers, + body: body) check_errors!(response) @@ -63,9 +63,9 @@ module BitbucketServer url = delete_url(resource, path) response = Gitlab::HTTP.delete(url, - basic_auth: auth, - headers: post_headers, - body: body) + basic_auth: auth, + headers: post_headers, + body: body) check_errors!(response) @@ -82,7 +82,7 @@ module BitbucketServer return if response.code >= 200 && response.code < 300 - details = sanitize(response.parsed_response.dig('errors', 0, 'message')) + details = sanitize(response.parsed_response.dig("errors", 0, "message")) message = "Error #{response.code}" message += ": #{details}" if details @@ -92,15 +92,15 @@ module BitbucketServer end def auth - @auth ||= { username: username, password: token } + @auth ||= {username: username, password: token} end def accept_headers - @accept_headers ||= { 'Accept' => 'application/json' } + @accept_headers ||= {"Accept" => "application/json"} end def post_headers - @post_headers ||= accept_headers.merge({ 'Content-Type' => 'application/json' }) + @post_headers ||= accept_headers.merge({"Content-Type" => "application/json"}) end def build_url(path) diff --git a/lib/bitbucket_server/page.rb b/lib/bitbucket_server/page.rb index 5d9a3168876..a15fe9d88ee 100644 --- a/lib/bitbucket_server/page.rb +++ b/lib/bitbucket_server/page.rb @@ -20,13 +20,13 @@ module BitbucketServer private def parse_attrs(raw) - raw.slice('size', 'nextPageStart', 'isLastPage').symbolize_keys + raw.slice("size", "nextPageStart", "isLastPage").symbolize_keys end def parse_values(raw, bitbucket_rep_class) - return [] unless raw['values'] && raw['values'].is_a?(Array) + return [] unless raw["values"]&.is_a?(Array) - bitbucket_rep_class.decorate(raw['values']) + bitbucket_rep_class.decorate(raw["values"]) end def representation_class(type) diff --git a/lib/bitbucket_server/representation/activity.rb b/lib/bitbucket_server/representation/activity.rb index 08bf30a5d1e..ec1e3d148f3 100644 --- a/lib/bitbucket_server/representation/activity.rb +++ b/lib/bitbucket_server/representation/activity.rb @@ -4,7 +4,7 @@ module BitbucketServer module Representation class Activity < Representation::Base def comment? - action == 'COMMENTED' + action == "COMMENTED" end def inline_comment? @@ -24,25 +24,25 @@ module BitbucketServer # TODO Move this into MergeEvent def merge_event? - action == 'MERGED' + action == "MERGED" end def committer_user - commit.dig('committer', 'displayName') + commit.dig("committer", "displayName") end def committer_email - commit.dig('committer', 'emailAddress') + commit.dig("committer", "emailAddress") end def merge_timestamp - timestamp = commit['committerTimestamp'] + timestamp = commit["committerTimestamp"] self.class.convert_timestamp(timestamp) end def merge_commit - commit['id'] + commit["id"] end def created_at @@ -52,19 +52,19 @@ module BitbucketServer private def commit - raw.fetch('commit', {}) + raw.fetch("commit", {}) end def action - raw['action'] + raw["action"] end def comment_anchor - raw['commentAnchor'] + raw["commentAnchor"] end def created_date - raw['createdDate'] + raw["createdDate"] end end end diff --git a/lib/bitbucket_server/representation/comment.rb b/lib/bitbucket_server/representation/comment.rb index 99b97a3b181..fdd8316cc6b 100644 --- a/lib/bitbucket_server/representation/comment.rb +++ b/lib/bitbucket_server/representation/comment.rb @@ -34,19 +34,19 @@ module BitbucketServer end def id - raw_comment['id'] + raw_comment["id"] end def author_username - author['displayName'] + author["displayName"] end def author_email - author['emailAddress'] + author["emailAddress"] end def note - raw_comment['text'] + raw_comment["text"] end def created_at @@ -85,7 +85,7 @@ module BitbucketServer # insert that node into the workset. # b. Parse that note into a Comment structure and add it to a flat list. def flatten_comments - comments = raw_comment['comments'] + comments = raw_comment["comments"] workset = if comments [CommentNode.new(comments, self)] @@ -100,8 +100,8 @@ module BitbucketServer parent = node.parent node.raw_comments.each do |comment| - new_comments = comment.delete('comments') - current_comment = Comment.new({ 'comment' => comment }, parent_comment: parent) + new_comments = comment.delete("comments") + current_comment = Comment.new({"comment" => comment}, parent_comment: parent) all_comments << current_comment workset << CommentNode.new(new_comments, current_comment) if new_comments end @@ -111,19 +111,19 @@ module BitbucketServer end def raw_comment - raw.fetch('comment', {}) + raw.fetch("comment", {}) end def author - raw_comment['author'] + raw_comment["author"] end def created_date - raw_comment['createdDate'] + raw_comment["createdDate"] end def updated_date - raw_comment['updatedDate'] + raw_comment["updatedDate"] end end end diff --git a/lib/bitbucket_server/representation/pull_request.rb b/lib/bitbucket_server/representation/pull_request.rb index c3e927d8de7..9475b2dff7e 100644 --- a/lib/bitbucket_server/representation/pull_request.rb +++ b/lib/bitbucket_server/representation/pull_request.rb @@ -4,34 +4,34 @@ module BitbucketServer module Representation class PullRequest < Representation::Base def author - raw.dig('author', 'user', 'name') + raw.dig("author", "user", "name") end def author_email - raw.dig('author', 'user', 'emailAddress') + raw.dig("author", "user", "emailAddress") end def description - raw['description'] + raw["description"] end def iid - raw['id'] + raw["id"] end def state - case raw['state'] - when 'MERGED' - 'merged' - when 'DECLINED' - 'closed' + case raw["state"] + when "MERGED" + "merged" + when "DECLINED" + "closed" else - 'opened' + "opened" end end def merged? - state == 'merged' + state == "merged" end def created_at @@ -43,33 +43,33 @@ module BitbucketServer end def title - raw['title'] + raw["title"] end def source_branch_name - raw.dig('fromRef', 'id') + raw.dig("fromRef", "id") end def source_branch_sha - raw.dig('fromRef', 'latestCommit') + raw.dig("fromRef", "latestCommit") end def target_branch_name - raw.dig('toRef', 'id') + raw.dig("toRef", "id") end def target_branch_sha - raw.dig('toRef', 'latestCommit') + raw.dig("toRef", "latestCommit") end private def created_date - raw['createdDate'] + raw["createdDate"] end def updated_date - raw['updatedDate'] + raw["updatedDate"] end end end diff --git a/lib/bitbucket_server/representation/pull_request_comment.rb b/lib/bitbucket_server/representation/pull_request_comment.rb index a2b3873a397..66dca57a0f8 100644 --- a/lib/bitbucket_server/representation/pull_request_comment.rb +++ b/lib/bitbucket_server/representation/pull_request_comment.rb @@ -19,27 +19,27 @@ module BitbucketServer # More details in https://docs.atlassian.com/bitbucket-server/rest/5.12.0/bitbucket-rest.html. class PullRequestComment < Comment def from_sha - comment_anchor['fromHash'] + comment_anchor["fromHash"] end def to_sha - comment_anchor['toHash'] + comment_anchor["toHash"] end def to? - file_type == 'TO' + file_type == "TO" end def from? - file_type == 'FROM' + file_type == "FROM" end def added? - line_type == 'ADDED' + line_type == "ADDED" end def removed? - line_type == 'REMOVED' + line_type == "REMOVED" end # There are three line comment types: added, removed, or context. @@ -63,17 +63,17 @@ module BitbucketServer end def file_path - comment_anchor.fetch('path') + comment_anchor.fetch("path") end private def file_type - comment_anchor['fileType'] + comment_anchor["fileType"] end def line_type - comment_anchor['lineType'] + comment_anchor["lineType"] end # Each comment contains the following information about the diff: @@ -94,12 +94,12 @@ module BitbucketServer # entries until we find this comment ID. def line_position @line_position ||= diff_hunks.each do |hunk| - segments = hunk.fetch('segments', []) + segments = hunk.fetch("segments", []) segments.each do |segment| - lines = segment.fetch('lines', []) + lines = segment.fetch("lines", []) lines.each do |line| - if line['commentIds']&.include?(id) - return [line['source'], line['destination']] + if line["commentIds"]&.include?(id) + return [line["source"], line["destination"]] end end end @@ -107,15 +107,15 @@ module BitbucketServer end def comment_anchor - raw.fetch('commentAnchor', {}) + raw.fetch("commentAnchor", {}) end def diff - raw.fetch('diff', {}) + raw.fetch("diff", {}) end def diff_hunks - diff.fetch('hunks', []) + diff.fetch("hunks", []) end end end diff --git a/lib/bitbucket_server/representation/repo.rb b/lib/bitbucket_server/representation/repo.rb index 6c494b79166..d67b11fd50b 100644 --- a/lib/bitbucket_server/representation/repo.rb +++ b/lib/bitbucket_server/representation/repo.rb @@ -8,29 +8,29 @@ module BitbucketServer end def project_key - raw.dig('project', 'key') + raw.dig("project", "key") end def project_name - raw.dig('project', 'name') + raw.dig("project", "name") end def slug - raw['slug'] + raw["slug"] end def browse_url # The JSON reponse contains an array of 1 element. Not sure if there # are cases where multiple links would be provided. - raw.dig('links', 'self').first.fetch('href') + raw.dig("links", "self").first.fetch("href") end def clone_url - raw['links']['clone'].find { |link| link['name'].starts_with?('http') }.fetch('href') + raw["links"]["clone"].find { |link| link["name"].starts_with?("http") }.fetch("href") end def description - project['description'] + project["description"] end def full_name @@ -42,15 +42,15 @@ module BitbucketServer end def name - raw['name'] + raw["name"] end def valid? - raw['scmId'] == 'git' + raw["scmId"] == "git" end def visibility_level - if project['public'] + if project["public"] Gitlab::VisibilityLevel::PUBLIC else Gitlab::VisibilityLevel::PRIVATE @@ -58,7 +58,7 @@ module BitbucketServer end def project - raw['project'] + raw["project"] end def to_s |