gitlab-system-hooks-receiver 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -3
- data/Gemfile +0 -3
- data/Rakefile +0 -9
- data/gitlab-system-hooks-receiver.gemspec +3 -2
- data/lib/gitlab-system-hooks-receiver.rb +2 -73
- data/lib/gitlab-system-hooks-receiver/version.rb +1 -1
- metadata +22 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 63b156fc442baae64bd840728ffd5679b5766bfc
|
4
|
+
data.tar.gz: d6278c9ce49d6196b084ee3cfd11238e58a39f6e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6ef5034773b36db686e8133e7401905d728ec597d3198c3a5b89fe870edd80ec336d3ee86b51b144eb2bb235f10c4ce917753278df70066df70368e72b2f8a0f
|
7
|
+
data.tar.gz: 537d25bdee0833a87deb763aea21e46f6aefbcf07e0da2dbbbb3b7ce73fcdc0800feefcf869e8bb6b66d2e434330f796404f81d4cfc61fa0bc3c9e1161b510fb
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/Rakefile
CHANGED
@@ -14,15 +14,6 @@
|
|
14
14
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
15
15
|
|
16
16
|
require "bundler/gem_helper"
|
17
|
-
|
18
|
-
module Bundler
|
19
|
-
class GemHelper
|
20
|
-
def version_tag
|
21
|
-
"#{version}"
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
17
|
require "bundler/gem_tasks"
|
27
18
|
|
28
19
|
task :default => :test
|
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
|
|
11
11
|
spec.summary = %q{Process GitLab System hooks.}
|
12
12
|
spec.description = %q{Process GitLab System hooks.}
|
13
13
|
spec.homepage = ""
|
14
|
-
spec.license = "
|
14
|
+
spec.license = "GPL-3.0+"
|
15
15
|
|
16
16
|
spec.files = `git ls-files`.split($/)
|
17
17
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
@@ -19,8 +19,9 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
21
|
spec.add_runtime_dependency "rack"
|
22
|
+
spec.add_runtime_dependency "github-web-hooks-receiver"
|
22
23
|
|
23
|
-
spec.add_development_dependency "bundler"
|
24
|
+
spec.add_development_dependency "bundler"
|
24
25
|
spec.add_development_dependency "rake"
|
25
26
|
spec.add_development_dependency "test-unit"
|
26
27
|
spec.add_development_dependency "test-unit-rr"
|
@@ -20,83 +20,12 @@ require "net/https"
|
|
20
20
|
require "webrick/httpstatus"
|
21
21
|
require "json"
|
22
22
|
|
23
|
-
|
23
|
+
require "github-web-hooks-receiver/base"
|
24
24
|
|
25
|
-
|
26
|
-
@options = symbolize_options(options)
|
27
|
-
end
|
28
|
-
|
29
|
-
def call(env)
|
30
|
-
request = Rack::Request.new(env)
|
31
|
-
response = Rack::Response.new
|
32
|
-
process(request, response)
|
33
|
-
response.to_a
|
34
|
-
end
|
25
|
+
class GitLabSystemHooksReceiver < GithubWebHooksReceiver::Base
|
35
26
|
|
36
27
|
private
|
37
28
|
|
38
|
-
def production?
|
39
|
-
ENV["RACK_ENV"] == "production"
|
40
|
-
end
|
41
|
-
|
42
|
-
def symbolize_options(options)
|
43
|
-
symbolized_options = {}
|
44
|
-
options.each do |key, value|
|
45
|
-
symbolized_options[key.to_sym] = value
|
46
|
-
end
|
47
|
-
symbolized_options
|
48
|
-
end
|
49
|
-
|
50
|
-
KEYWORD_TO_HTTP_STATUS_CODE = {}
|
51
|
-
WEBrick::HTTPStatus::StatusMessage.each do |code, message|
|
52
|
-
KEYWORD_TO_HTTP_STATUS_CODE[message.downcase.gsub(/ +/, '_').intern] = code
|
53
|
-
end
|
54
|
-
|
55
|
-
def status(keyword)
|
56
|
-
code = KEYWORD_TO_HTTP_STATUS_CODE[keyword]
|
57
|
-
if code.nil?
|
58
|
-
raise ArgumentError, "invalid status keyword: #{keyword.inspect}"
|
59
|
-
end
|
60
|
-
code
|
61
|
-
end
|
62
|
-
|
63
|
-
def set_error_response(response, status_keyword, message)
|
64
|
-
response.status = status(status_keyword)
|
65
|
-
response["Content-Type"] = "text/plain"
|
66
|
-
response.write(message)
|
67
|
-
end
|
68
|
-
|
69
|
-
def process(request, response)
|
70
|
-
unless request.post?
|
71
|
-
set_error_response(response, :method_not_allowed, "must POST")
|
72
|
-
return
|
73
|
-
end
|
74
|
-
|
75
|
-
payload = parse_payload(request, response)
|
76
|
-
return if payload.nil?
|
77
|
-
process_payload(request, response, payload)
|
78
|
-
end
|
79
|
-
|
80
|
-
def parse_payload(request, response)
|
81
|
-
if request.content_type == "application/json"
|
82
|
-
payload = request.body.read
|
83
|
-
else
|
84
|
-
payload = request["payload"]
|
85
|
-
end
|
86
|
-
if payload.nil?
|
87
|
-
set_error_response(response, :bad_request, "payload is missing")
|
88
|
-
return
|
89
|
-
end
|
90
|
-
|
91
|
-
begin
|
92
|
-
JSON.parse(payload)
|
93
|
-
rescue JSON::ParserError
|
94
|
-
set_error_response(response, :bad_request,
|
95
|
-
"invalid JSON format: <#{$!.message}>")
|
96
|
-
nil
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
29
|
def process_payload(request, response, payload)
|
101
30
|
event_name = payload["event_name"]
|
102
31
|
__send__("process_#{event_name}_event", request, response, payload)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gitlab-system-hooks-receiver
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kenji Okimoto
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-03-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -24,20 +24,34 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: github-web-hooks-receiver
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: bundler
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
30
44
|
requirements:
|
31
|
-
- - "
|
45
|
+
- - ">="
|
32
46
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
47
|
+
version: '0'
|
34
48
|
type: :development
|
35
49
|
prerelease: false
|
36
50
|
version_requirements: !ruby/object:Gem::Requirement
|
37
51
|
requirements:
|
38
|
-
- - "
|
52
|
+
- - ">="
|
39
53
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
54
|
+
version: '0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: rake
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -118,7 +132,7 @@ files:
|
|
118
132
|
- test/test-utils.rb
|
119
133
|
homepage: ''
|
120
134
|
licenses:
|
121
|
-
-
|
135
|
+
- GPL-3.0+
|
122
136
|
metadata: {}
|
123
137
|
post_install_message:
|
124
138
|
rdoc_options: []
|
@@ -136,7 +150,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
136
150
|
version: '0'
|
137
151
|
requirements: []
|
138
152
|
rubyforge_project:
|
139
|
-
rubygems_version: 2.
|
153
|
+
rubygems_version: 2.4.5
|
140
154
|
signing_key:
|
141
155
|
specification_version: 4
|
142
156
|
summary: Process GitLab System hooks.
|