Class: Flowdock::Git

Inherits:
Object
  • Object
show all
Defined in:
lib/flowdock/git.rb,
lib/flowdock/git/builder.rb

Defined Under Namespace

Classes: Builder, Commit, TokenError

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ref, from, to, options = {}) ⇒ Git

Returns a new instance of Git.



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/flowdock/git.rb', line 20

def initialize(ref, from, to, options = {})
  @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
  @permanent_refs = options[:permanent_refs] ||
                    (config["flowdock.permanent-references"] || "refs/heads/master")
                      .split(",")
                      .map(&:strip)
                      .map {|exp| Regexp.new(exp) }
end

Class Method Details

.background_post(ref, from, to, options = {}) ⇒ Object



15
16
17
# File 'lib/flowdock/git.rb', line 15

def background_post(ref, from, to, options = {})
  Git.new(ref, from, to, options).background_post
end

.post(ref, from, to, options = {}) ⇒ Object



11
12
13
# File 'lib/flowdock/git.rb', line 11

def post(ref, from, to, options = {})
  Git.new(ref, from, to, options).post
end

Instance Method Details

#background_postObject

Create and post notification in background process. Avoid blocking the push notification.



45
46
47
48
49
50
51
52
53
54
# File 'lib/flowdock/git.rb', line 45

def background_post
  pid = Process.fork
  if pid.nil?
    Grit::Git.with_timeout(600) do
      post
    end
  else
    Process.detach(pid) # Parent
  end
end

#postObject

Send git push notification to Flowdock



38
39
40
41
42
# File 'lib/flowdock/git.rb', line 38

def post
  messages.each do |message|
    Flowdock::Client.new(flow_token: @token).post_to_thread(message)
  end
end

#repoObject



56
57
58
# File 'lib/flowdock/git.rb', line 56

def repo
  @repo ||= Grit::Repo.new(@options[:repo] || Dir.pwd)
end