summaryrefslogtreecommitdiff
path: root/lib/flowdock
diff options
context:
space:
mode:
authorNick Thomas <nick@gitlab.com>2018-10-15 17:25:35 +0100
committerNick Thomas <nick@gitlab.com>2018-10-16 11:54:55 +0100
commit8d3222925eca278fc7641bdf319cc79c008a722a (patch)
treea0a5c0c66178f11531e7f0c1eec79455999a09de /lib/flowdock
parent04aaf71932646efd99f2abd74fc59e3129fcbe1d (diff)
downloadgitlab-ce-8d3222925eca278fc7641bdf319cc79c008a722a.tar.gz
Rubocop improvements
Diffstat (limited to 'lib/flowdock')
-rw-r--r--lib/flowdock/git.rb30
-rw-r--r--lib/flowdock/git/builder.rb29
2 files changed, 30 insertions, 29 deletions
diff --git a/lib/flowdock/git.rb b/lib/flowdock/git.rb
index 43e729c27d7..d5e97dad3cf 100644
--- a/lib/flowdock/git.rb
+++ b/lib/flowdock/git.rb
@@ -1,4 +1,4 @@
-
+# frozen_string_literal: true
require "multi_json"
require "cgi"
require "flowdock"
@@ -6,7 +6,7 @@ require "flowdock/git/builder"
module Flowdock
class Git
- class TokenError < StandardError; end
+ TokenError = Class.new(StandardError)
class << self
def post(ref, from, to, options = {})
@@ -28,11 +28,12 @@ module Flowdock
@diff_url = options[:diff_url] || config["flowdock.diff-url-pattern"] || nil
@repo_url = options[:repo_url] || config["flowdock.repository-url"] || nil
@repo_name = options[:repo_name] || config["flowdock.repository-name"] || nil
- @permanent_refs = options[:permanent_refs] ||
- (config["flowdock.permanent-references"] || "refs/heads/master")
- .split(",")
- .map(&:strip)
- .map {|exp| Regexp.new(exp) }
+
+ refs = options[:permanent_refs] || config["flowdock.permanent-references"] || "refs/heads/master"
+ @permanent_refs = refs
+ .split(",")
+ .map(&:strip)
+ .map {|exp| Regexp.new(exp) }
end
# Send git push notification to Flowdock
@@ -80,13 +81,14 @@ module Flowdock
# Flowdock tags attached to the push notification
def tags
- if @options[:tags]
- @options[:tags]
- else
- config["flowdock.tags"].to_s.split(",").map(&:strip)
- end.map do |t|
- CGI.escape(t)
- end
+ tags =
+ if @options[:tags]
+ @options[:tags]
+ else
+ config["flowdock.tags"].to_s.split(",").map(&:strip)
+ end
+
+ tags.map { |t| CGI.escape(t) }
end
def config
diff --git a/lib/flowdock/git/builder.rb b/lib/flowdock/git/builder.rb
index 4aec6a86df1..3cb086f65b8 100644
--- a/lib/flowdock/git/builder.rb
+++ b/lib/flowdock/git/builder.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
require "grit"
require 'cgi'
require "securerandom"
@@ -31,7 +32,8 @@ module Flowdock
private
def encode(hash)
- return hash unless "".respond_to? :encode
+ return hash unless "".respond_to?(:encode)
+
encode_as_utf8(hash)
end
@@ -46,8 +48,8 @@ module Flowdock
encode_as_utf8(val)
end
elsif obj.is_a?(String) && obj.encoding != Encoding::UTF_8
- if !obj.force_encoding("UTF-8").valid_encoding?
- obj.force_encoding("ISO-8859-1").encode!(Encoding::UTF_8, :invalid => :replace, :undef => :replace)
+ unless obj.force_encoding("UTF-8").valid_encoding?
+ obj.force_encoding("ISO-8859-1").encode!(Encoding::UTF_8, invalid: :replace, undef: :replace)
end
end
end
@@ -78,6 +80,8 @@ module Flowdock
# Class used to build Git payload
class Builder
+ include ::Gitlab::Utils::StrongMemoize
+
def initialize(opts)
@repo = opts[:repo]
@ref = opts[:ref]
@@ -101,7 +105,7 @@ module Flowdock
end
def ref_name
- @ref.to_s.sub(/\Arefs\/(heads|tags)\//, '')
+ @ref.to_s.sub(%r{\Arefs/(heads|tags)/}, '')
end
def to_hashes
@@ -120,20 +124,15 @@ module Flowdock
end
def permanent?
- @permanent ||= @opts[:permanent_refs].select do |regex|
- regex.match(@ref)
- end.size > 0
+ strong_memoize(:permanent) do
+ @opts[:permanent_refs].any? { |regex| regex.match(@ref) }
+ end
end
def thread_title
- action = if permanent?
- "updated"
- end
- type = if @ref.match(%r(^refs/heads/))
- "branch"
- else
- "tag"
- end
+ action = "updated" if permanent?
+ type = @ref =~ %r(^refs/heads/) ? "branch" : "tag"
+
[@opts[:repo_name], type, ref_name, action].compact.join(" ")
end