2018-08-10 06:45:01 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2013-10-03 13:29:13 +00:00
|
|
|
require "flowdock-git-hook"
|
|
|
|
|
2018-04-20 11:02:42 +00:00
|
|
|
# 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
|
|
|
|
|
2013-08-19 09:11:36 +00:00
|
|
|
class FlowdockService < Service
|
2014-09-08 00:54:18 +00:00
|
|
|
prop_accessor :token
|
2013-08-19 09:11:36 +00:00
|
|
|
validates :token, presence: true, if: :activated?
|
|
|
|
|
|
|
|
def title
|
|
|
|
'Flowdock'
|
|
|
|
end
|
|
|
|
|
|
|
|
def description
|
|
|
|
'Flowdock is a collaboration web app for technical teams.'
|
|
|
|
end
|
|
|
|
|
2016-12-27 12:44:24 +00:00
|
|
|
def self.to_param
|
2013-08-19 09:11:36 +00:00
|
|
|
'flowdock'
|
|
|
|
end
|
|
|
|
|
|
|
|
def fields
|
|
|
|
[
|
2017-05-22 10:07:12 +00:00
|
|
|
{ type: 'text', name: 'token', placeholder: 'Flowdock Git source token', required: true }
|
2013-08-19 09:11:36 +00:00
|
|
|
]
|
|
|
|
end
|
|
|
|
|
2016-12-27 12:44:24 +00:00
|
|
|
def self.supported_events
|
2015-02-28 16:33:18 +00:00
|
|
|
%w(push)
|
|
|
|
end
|
|
|
|
|
2015-02-20 13:49:26 +00:00
|
|
|
def execute(data)
|
2015-02-28 16:33:18 +00:00
|
|
|
return unless supported_events.include?(data[:object_kind])
|
2015-02-19 05:02:57 +00:00
|
|
|
|
2013-08-19 09:11:36 +00:00
|
|
|
Flowdock::Git.post(
|
2015-02-20 13:49:26 +00:00
|
|
|
data[:ref],
|
|
|
|
data[:before],
|
|
|
|
data[:after],
|
2013-08-19 09:11:36 +00:00
|
|
|
token: token,
|
2018-04-20 11:02:42 +00:00
|
|
|
repo: project.repository,
|
2017-07-20 09:34:09 +00:00
|
|
|
repo_url: "#{Gitlab.config.gitlab.url}/#{project.full_path}",
|
|
|
|
commit_url: "#{Gitlab.config.gitlab.url}/#{project.full_path}/commit/%s",
|
|
|
|
diff_url: "#{Gitlab.config.gitlab.url}/#{project.full_path}/compare/%s...%s"
|
2015-12-15 02:53:52 +00:00
|
|
|
)
|
2013-08-19 09:11:36 +00:00
|
|
|
end
|
|
|
|
end
|