summaryrefslogtreecommitdiff
path: root/lib/flowdock
diff options
context:
space:
mode:
authorNick Thomas <nick@gitlab.com>2018-10-15 17:31:32 +0100
committerNick Thomas <nick@gitlab.com>2018-10-16 12:53:30 +0100
commit27e9ed7a4ce2b1d97b7b8093ecde02f7c591349b (patch)
tree13d0218961f3020528edb125efc1b17b18695393 /lib/flowdock
parent8d3222925eca278fc7641bdf319cc79c008a722a (diff)
downloadgitlab-ce-27e9ed7a4ce2b1d97b7b8093ecde02f7c591349b.tar.gz
Merge flowdock monkeypatch into the inlined gem
Diffstat (limited to 'lib/flowdock')
-rw-r--r--lib/flowdock/git.rb67
-rw-r--r--lib/flowdock/git/builder.rb9
2 files changed, 23 insertions, 53 deletions
diff --git a/lib/flowdock/git.rb b/lib/flowdock/git.rb
index d5e97dad3cf..a1ecbe08884 100644
--- a/lib/flowdock/git.rb
+++ b/lib/flowdock/git.rb
@@ -1,39 +1,36 @@
# frozen_string_literal: true
-require "multi_json"
-require "cgi"
-require "flowdock"
-require "flowdock/git/builder"
+require 'multi_json'
+require 'cgi'
+require 'flowdock'
+require 'flowdock/git/builder'
module Flowdock
class Git
TokenError = Class.new(StandardError)
+ DEFAULT_PERMANENT_REFS = [
+ Regexp.new('refs/heads/master')
+ ].freeze
+
class << self
def post(ref, from, to, options = {})
Git.new(ref, from, to, options).post
end
-
- def background_post(ref, from, to, options = {})
- Git.new(ref, from, to, options).background_post
- end
end
def initialize(ref, from, to, options = {})
+ raise TokenError.new("Flowdock API token not found") unless options[:token]
+
@ref = ref
@from = from
@to = to
@options = options
- @token = options[:token] || config["flowdock.token"] || raise(TokenError.new("Flowdock API token not found"))
- @commit_url = options[:commit_url] || config["flowdock.commit-url-pattern"] || nil
- @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
-
- refs = options[:permanent_refs] || config["flowdock.permanent-references"] || "refs/heads/master"
- @permanent_refs = refs
- .split(",")
- .map(&:strip)
- .map {|exp| Regexp.new(exp) }
+ @token = options[:token]
+ @commit_url = options[:commit_url]
+ @diff_url = options[:diff_url]
+ @repo_url = options[:repo_url]
+ @repo_name = options[:repo_name]
+ @permanent_refs = options.fetch(:permanent_refs, DEFAULT_PERMANENT_REFS)
end
# Send git push notification to Flowdock
@@ -43,29 +40,14 @@ module Flowdock
end
end
- # Create and post notification in background process. Avoid blocking the push notification.
- def background_post
- pid = Process.fork
- if pid.nil?
- Grit::Git.with_timeout(600) do
- post
- end
- else
- Process.detach(pid) # Parent
- end
- end
-
def repo
- @repo ||= Grit::Repo.new(
- @options[:repo] || Dir.pwd,
- is_bare: @options[:is_bare] || false
- )
+ @options[:repo]
end
private
def messages
- Git::Builder.new(repo: @repo,
+ Git::Builder.new(repo: repo,
ref: @ref,
before: @from,
after: @to,
@@ -81,18 +63,7 @@ module Flowdock
# Flowdock tags attached to the push notification
def tags
- 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
- @config ||= Grit::Config.new(repo)
+ Array(@options[:tags]).map { |tag| CGI.escape(tag) }
end
end
end
diff --git a/lib/flowdock/git/builder.rb b/lib/flowdock/git/builder.rb
index 3cb086f65b8..1ef9b66e747 100644
--- a/lib/flowdock/git/builder.rb
+++ b/lib/flowdock/git/builder.rb
@@ -1,7 +1,6 @@
# frozen_string_literal: true
-require "grit"
require 'cgi'
-require "securerandom"
+require 'securerandom'
module Flowdock
class Git
@@ -93,12 +92,12 @@ module Flowdock
def commits
@repo.commits_between(@before, @after).map do |commit|
{
- url: if @opts[:commit_url] then @opts[:commit_url] % [commit.sha] end,
+ url: @opts[:commit_url] ? @opts[:commit_url] % [commit.sha] : nil,
id: commit.sha,
message: commit.message,
author: {
- name: commit.author.name,
- email: commit.author.email
+ name: commit.author_name,
+ email: commit.author_email
}
}
end