Merge flowdock monkeypatch into the inlined gem
This commit is contained in:
parent
8d3222925e
commit
27e9ed7a4c
|
@ -1,53 +1,5 @@
|
||||||
# frozen_string_literal: true
|
# 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
|
class FlowdockService < Service
|
||||||
prop_accessor :token
|
prop_accessor :token
|
||||||
validates :token, presence: true, if: :activated?
|
validates :token, presence: true, if: :activated?
|
||||||
|
|
|
@ -1,39 +1,36 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
require "multi_json"
|
require 'multi_json'
|
||||||
require "cgi"
|
require 'cgi'
|
||||||
require "flowdock"
|
require 'flowdock'
|
||||||
require "flowdock/git/builder"
|
require 'flowdock/git/builder'
|
||||||
|
|
||||||
module Flowdock
|
module Flowdock
|
||||||
class Git
|
class Git
|
||||||
TokenError = Class.new(StandardError)
|
TokenError = Class.new(StandardError)
|
||||||
|
|
||||||
|
DEFAULT_PERMANENT_REFS = [
|
||||||
|
Regexp.new('refs/heads/master')
|
||||||
|
].freeze
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
def post(ref, from, to, options = {})
|
def post(ref, from, to, options = {})
|
||||||
Git.new(ref, from, to, options).post
|
Git.new(ref, from, to, options).post
|
||||||
end
|
end
|
||||||
|
|
||||||
def background_post(ref, from, to, options = {})
|
|
||||||
Git.new(ref, from, to, options).background_post
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def initialize(ref, from, to, options = {})
|
def initialize(ref, from, to, options = {})
|
||||||
|
raise TokenError.new("Flowdock API token not found") unless options[:token]
|
||||||
|
|
||||||
@ref = ref
|
@ref = ref
|
||||||
@from = from
|
@from = from
|
||||||
@to = to
|
@to = to
|
||||||
@options = options
|
@options = options
|
||||||
@token = options[:token] || config["flowdock.token"] || raise(TokenError.new("Flowdock API token not found"))
|
@token = options[:token]
|
||||||
@commit_url = options[:commit_url] || config["flowdock.commit-url-pattern"] || nil
|
@commit_url = options[:commit_url]
|
||||||
@diff_url = options[:diff_url] || config["flowdock.diff-url-pattern"] || nil
|
@diff_url = options[:diff_url]
|
||||||
@repo_url = options[:repo_url] || config["flowdock.repository-url"] || nil
|
@repo_url = options[:repo_url]
|
||||||
@repo_name = options[:repo_name] || config["flowdock.repository-name"] || nil
|
@repo_name = options[:repo_name]
|
||||||
|
@permanent_refs = options.fetch(:permanent_refs, DEFAULT_PERMANENT_REFS)
|
||||||
refs = options[:permanent_refs] || config["flowdock.permanent-references"] || "refs/heads/master"
|
|
||||||
@permanent_refs = refs
|
|
||||||
.split(",")
|
|
||||||
.map(&:strip)
|
|
||||||
.map {|exp| Regexp.new(exp) }
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Send git push notification to Flowdock
|
# Send git push notification to Flowdock
|
||||||
|
@ -43,29 +40,14 @@ module Flowdock
|
||||||
end
|
end
|
||||||
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
|
def repo
|
||||||
@repo ||= Grit::Repo.new(
|
@options[:repo]
|
||||||
@options[:repo] || Dir.pwd,
|
|
||||||
is_bare: @options[:is_bare] || false
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def messages
|
def messages
|
||||||
Git::Builder.new(repo: @repo,
|
Git::Builder.new(repo: repo,
|
||||||
ref: @ref,
|
ref: @ref,
|
||||||
before: @from,
|
before: @from,
|
||||||
after: @to,
|
after: @to,
|
||||||
|
@ -81,18 +63,7 @@ module Flowdock
|
||||||
|
|
||||||
# Flowdock tags attached to the push notification
|
# Flowdock tags attached to the push notification
|
||||||
def tags
|
def tags
|
||||||
tags =
|
Array(@options[:tags]).map { |tag| CGI.escape(tag) }
|
||||||
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)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
require "grit"
|
|
||||||
require 'cgi'
|
require 'cgi'
|
||||||
require "securerandom"
|
require 'securerandom'
|
||||||
|
|
||||||
module Flowdock
|
module Flowdock
|
||||||
class Git
|
class Git
|
||||||
|
@ -93,12 +92,12 @@ module Flowdock
|
||||||
def commits
|
def commits
|
||||||
@repo.commits_between(@before, @after).map do |commit|
|
@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,
|
id: commit.sha,
|
||||||
message: commit.message,
|
message: commit.message,
|
||||||
author: {
|
author: {
|
||||||
name: commit.author.name,
|
name: commit.author_name,
|
||||||
email: commit.author.email
|
email: commit.author_email
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue