Class: Flowdock::Git
- Inherits:
-
Object
- Object
- Flowdock::Git
- Defined in:
- lib/flowdock/git.rb,
lib/flowdock/git/builder.rb
Defined Under Namespace
Classes: Builder, TokenError
Constant Summary collapse
- API_ENDPOINT =
"https://api.flowdock.com/v1/git"
Class Method Summary collapse
Instance Method Summary collapse
-
#background_post(data) ⇒ Object
Create and post notification in background process.
-
#initialize(options = {}) ⇒ Git
constructor
A new instance of Git.
-
#post(data) ⇒ Object
Send git push notification to Flowdock.
- #repo ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Git
Returns a new instance of Git.
24 25 26 27 28 29 30 |
# File 'lib/flowdock/git.rb', line 24 def initialize( = {}) @options = @token = [:token] || config["flowdock.token"] || raise(TokenError.new("Flowdock API token not found")) @commit_url = [:commit_url] || config["flowdock.commit-url-pattern"] || nil @diff_url = [:diff_url] || config["flowdock.diff-url-pattern"] || nil @repo_url = [:repo_url] || config["flowdock.repository-url"] || nil end |
Class Method Details
Instance Method Details
#background_post(data) ⇒ Object
Create and post notification in background process. Avoid blocking the push notification.
62 63 64 65 66 67 68 69 70 71 |
# File 'lib/flowdock/git.rb', line 62 def background_post(data) pid = Process.fork if pid.nil? Grit::Git.with_timeout(600) do post(data) # Child end else Process.detach(pid) # Parent end end |
#post(data) ⇒ Object
Send git push notification to Flowdock
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/flowdock/git.rb', line 33 def post(data) uri = URI.parse("#{API_ENDPOINT}/#{([@token] + ).join('+')}") req = Net::HTTP::Post.new(uri.path) payload_hash = data.to_hash if @repo_url payload_hash[:repository][:url] = @repo_url end if @commit_url payload_hash[:commits].each do |commit| commit[:url] = @commit_url % commit[:id] end end if @diff_url payload_hash[:compare] = @diff_url % [payload_hash[:before], payload_hash[:after]] end req.set_form_data(:payload => MultiJson.encode(payload_hash)) http = Net::HTTP.new(uri.host, uri.port) if uri.scheme == 'https' http.verify_mode = OpenSSL::SSL::VERIFY_NONE http.use_ssl = true end http.start { |http| http.request(req) } end |
#repo ⇒ Object
73 74 75 |
# File 'lib/flowdock/git.rb', line 73 def repo @repo ||= Grit::Repo.new(@options[:repo] || Dir.pwd) end |