Merge flowdock monkeypatch into the inlined gem
This commit is contained in:
parent
8d3222925e
commit
27e9ed7a4c
|
@ -1,53 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'flowdock/git'
|
||||
|
||||
# Flow dock depends on Grit to compute the number of commits between two given
|
||||
# commits. To make this depend on Gitaly, a monkey patch is applied
|
||||
module Flowdock
|
||||
class Git
|
||||
# pass down a Repository all the way down
|
||||
def repo
|
||||
@options[:repo]
|
||||
end
|
||||
|
||||
def config
|
||||
{}
|
||||
end
|
||||
|
||||
def messages
|
||||
Git::Builder.new(repo: repo,
|
||||
ref: @ref,
|
||||
before: @from,
|
||||
after: @to,
|
||||
commit_url: @commit_url,
|
||||
branch_url: @branch_url,
|
||||
diff_url: @diff_url,
|
||||
repo_url: @repo_url,
|
||||
repo_name: @repo_name,
|
||||
permanent_refs: @permanent_refs,
|
||||
tags: tags
|
||||
).to_hashes
|
||||
end
|
||||
|
||||
class Builder
|
||||
def commits
|
||||
@repo.commits_between(@before, @after).map do |commit|
|
||||
{
|
||||
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
|
||||
}
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class FlowdockService < Service
|
||||
prop_accessor :token
|
||||
validates :token, presence: true, if: :activated?
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue