murmurs 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +7 -0
  2. data/bin/murmurs +1 -0
  3. data/lib/murmurs.rb +28 -16
  4. metadata +24 -16
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f318e8f7a6753605c905258d8693312f7241a5ad
4
+ data.tar.gz: 2c1d6a0ca1dc3f11b705f0131f220ee78487762b
5
+ SHA512:
6
+ metadata.gz: 3da1f95bdc0c56c0ce2a8884bece1bcc4e3b9bf79bf0f624d6e23090f6e9d8ec28be865991f6cc856a68d870ce225be0563ca1cebf73264023510117b5e7163d
7
+ data.tar.gz: 103e6c1a8715c6a2e67ab90953bd769c0b802bbc9cb3069863e025e82c4b35071d9422b06675277d1af739c45fd1fc87cb4b977fa16e678303699407538353ec
data/bin/murmurs CHANGED
@@ -40,6 +40,7 @@ opts = OptionParser.new do |opts|
40
40
 
41
41
  opts.on_tail('-g', '--git', 'Process standard input of Git hook post-receive, and murmur each commits; default is false') do
42
42
  options[:git] = true
43
+ options[:log_level] = :info
43
44
  end
44
45
 
45
46
  opts.on("-b", "--git_branch GIT_BRANCH", "Murmur Git commits in branch, default is master") do |v|
data/lib/murmurs.rb CHANGED
@@ -2,29 +2,36 @@ require 'net/http'
2
2
  require 'net/https'
3
3
  require 'time'
4
4
  require 'api-auth'
5
+ require 'json'
5
6
 
6
7
  module Murmurs
8
+ class InvalidMurmursURLError < StandardError; end
9
+
7
10
  def murmur(url, msg, options={})
8
11
  if options[:git]
9
- msg = git_commits_murmur(msg, options[:git_branch])
12
+ Array(git_commits(msg, options[:git_branch])).each do |msg|
13
+ murmur(url, msg, options.merge(:git => false))
14
+ end
15
+ else
16
+ validate_murmurs_url!(url)
17
+ if msg.nil? || msg.empty?
18
+ log(options[:log_level], "Nothing to murmur.")
19
+ else
20
+ log(options[:log_level], msg)
21
+ http_post(url, {:murmur => {:body => msg}}, options)
22
+ end
10
23
  end
24
+ end
11
25
 
12
- if url.to_s !~ /\Ahttps?\:\/\/.+\/projects\/[^\/]+\/murmurs/
13
- raise "Invalid murmurs URL: #{url.inspect}"
14
- end
15
- if msg.nil? || msg.empty?
16
- puts "Nothing to murmur." unless options[:git]
17
- return
18
- end
19
- t = 20
20
- Array(msg).each do |m|
21
- git_log(options[:git], m)
22
- http_post(url, {'murmur[body]' => m}, options)
26
+ def validate_murmurs_url!(url)
27
+ if url.to_s !~ /\Ahttps?\:\/\/.+\/murmurs/
28
+ raise InvalidMurmursURLError, "Invalid murmurs URL: #{url.inspect}"
23
29
  end
24
30
  end
25
31
 
26
- def git_log(log, m)
27
- if log
32
+ def log(level, m)
33
+ if level == :info
34
+ t = 20
28
35
  if m.size > t
29
36
  puts "murmur #{m[0..t]}..."
30
37
  else
@@ -35,7 +42,7 @@ module Murmurs
35
42
 
36
43
  # input: git post receive stdin string
37
44
  # branch: git branch
38
- def git_commits_murmur(input, branch)
45
+ def git_commits(input, branch)
39
46
  data = input.split("\n").map do |l|
40
47
  l.split
41
48
  end.find do |l|
@@ -69,9 +76,14 @@ module Murmurs
69
76
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE
70
77
  end
71
78
  end
79
+ body = params.to_json
72
80
 
73
81
  request = Net::HTTP::Post.new(uri.request_uri)
74
- request.form_data = params if params
82
+ request.body = body
83
+
84
+ request['Content-Type'] = 'application/json'
85
+ request['Content-Length'] = body.bytesize
86
+
75
87
 
76
88
  if options[:access_key_id]
77
89
  ApiAuth.sign!(request, options[:access_key_id], options[:access_secret_key])
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: murmurs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
5
- prerelease:
4
+ version: 0.0.2
6
5
  platform: ruby
7
6
  authors:
8
7
  - ThoughtWorks Mingle Team
@@ -14,24 +13,34 @@ dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: api-auth
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - '='
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
19
  version: 1.1.0
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - '='
24
+ - - ">="
28
25
  - !ruby/object:Gem::Version
29
26
  version: 1.1.0
30
- description: ! 'Use HMAC to create murmur in Mingle project.
31
-
27
+ - !ruby/object:Gem::Dependency
28
+ name: json
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.8.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 1.8.1
41
+ description: |
42
+ Use HMAC to create murmur in Mingle project.
32
43
  Git post-receive hook to post murmurs when new commits pushed to Git server.
33
-
34
- '
35
44
  email:
36
45
  - mingle-dev@thoughtworks.com
37
46
  executables:
@@ -47,26 +56,25 @@ files:
47
56
  homepage: https://github.com/ThoughtWorksStudios/murmurs
48
57
  licenses:
49
58
  - MIT
59
+ metadata: {}
50
60
  post_install_message:
51
61
  rdoc_options: []
52
62
  require_paths:
53
63
  - lib
54
64
  required_ruby_version: !ruby/object:Gem::Requirement
55
- none: false
56
65
  requirements:
57
- - - ! '>='
66
+ - - ">="
58
67
  - !ruby/object:Gem::Version
59
68
  version: '0'
60
69
  required_rubygems_version: !ruby/object:Gem::Requirement
61
- none: false
62
70
  requirements:
63
- - - ! '>='
71
+ - - ">="
64
72
  - !ruby/object:Gem::Version
65
73
  version: '0'
66
74
  requirements: []
67
75
  rubyforge_project:
68
- rubygems_version: 1.8.23
76
+ rubygems_version: 2.2.0
69
77
  signing_key:
70
- specification_version: 3
78
+ specification_version: 4
71
79
  summary: Post murmur to Mingle project murmurs
72
80
  test_files: []