gitlab-system-hooks-receiver 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 63b156fc442baae64bd840728ffd5679b5766bfc
4
- data.tar.gz: d6278c9ce49d6196b084ee3cfd11238e58a39f6e
3
+ metadata.gz: f5fe4d659361db7d6b98a21c19bad64a1a78cc09
4
+ data.tar.gz: 2c475654bc0b027755cf33847a75aebffa670d69
5
5
  SHA512:
6
- metadata.gz: 6ef5034773b36db686e8133e7401905d728ec597d3198c3a5b89fe870edd80ec336d3ee86b51b144eb2bb235f10c4ce917753278df70066df70368e72b2f8a0f
7
- data.tar.gz: 537d25bdee0833a87deb763aea21e46f6aefbcf07e0da2dbbbb3b7ce73fcdc0800feefcf869e8bb6b66d2e434330f796404f81d4cfc61fa0bc3c9e1161b510fb
6
+ metadata.gz: effa46f8aa9f8c1ff3fc17a410a329a8b6e4829316da730f8786baaa9a5a216f39165ec0e78e9d29cee4b57b77a76ae11d0e8ee6556457e13881f04252de78e0
7
+ data.tar.gz: 7fee3b405413f3ec2c144d5a78e0da6d597f6910d7cc99ebf72b668eeba4af506bac4af223212192bbd44d32c52bd879c124f6f2bb1247e9f0a3562eca3ff007
data/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ [![Build Status](https://travis-ci.org/clear-code/gitlab-system-hooks-receiver.svg?branch=master)](https://travis-ci.org/clear-code/gitlab-system-hooks-receiver)
2
+
1
3
  # GitLabSystemHooksReceiver
2
4
 
3
5
  Process GitLab system hooks.
@@ -20,25 +22,18 @@ Or install it yourself as:
20
22
 
21
23
  ## Usage
22
24
 
23
- ### Use part of git-utils/github-post-receiver
24
-
25
- You can use this web application with [clear-code/git-utils](https://github.com/clear-code/git-utils "clear-code/git-utils").
25
+ ### Use with github-web-hooks-receiver
26
26
 
27
- Clone [clear-code/git-utils](https://github.com/clear-code/git-utils "clear-code/git-utils").
28
-
29
- ```
30
- $ git clone https://github.com/clear-code/git-utils.git
31
- ```
27
+ You can use this web application with [clear-code/github-web-hooks-receiver](https://github.com/clear-code/github-web-hooks-receiver "clear-code/github-web-hooks-receiver").
32
28
 
33
29
  Add Gemfile.
34
30
 
35
31
  ```
36
32
  source "https://rubygems.org/"
37
33
 
38
- gem "rack"
39
- gem "racknga"
40
- gem "unicorn"
34
+ gem "github-web-hooks-receiver"
41
35
  gem "gitlab-system-hooks-receiver"
36
+ gem "unicorn"
42
37
  ```
43
38
 
44
39
  NOTE: You can use passenger instead of unicorn.
@@ -57,21 +52,6 @@ end
57
52
 
58
53
  Configure your web server if you need.
59
54
 
60
- ### Use standalone
61
-
62
- You can use this web application standalone.
63
-
64
- Clone this repository.
65
-
66
- ```
67
- $ git clone https://github.com/clear-code/gitlab-system-hooks-receiver.git
68
- $ cd gitlab-system-hooks-receiver
69
- $ bundle install --path vendor/bundle
70
- $ bundle exec unicorn
71
- ```
72
-
73
- Configure your web server if you need.
74
-
75
55
  ### Configuration
76
56
 
77
57
  Add your config.yaml as followings.
data/config.ru CHANGED
@@ -47,5 +47,5 @@ notifiers = [Racknga::ExceptionMailNotifier.new(notifier_options)]
47
47
  use Racknga::Middleware::ExceptionNotifier, :notifiers => notifiers
48
48
 
49
49
  map "/system-hooks-receiver/" do
50
- run GitLabSystemHooksReceiver.new(options)
50
+ run GitLabSystemHooksReceiver::App.new(options)
51
51
  end
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["okimoto@clear-code.com"]
11
11
  spec.summary = %q{Process GitLab System hooks.}
12
12
  spec.description = %q{Process GitLab System hooks.}
13
- spec.homepage = ""
13
+ spec.homepage = "https://github.com/clear-code/gitlab-system-hooks-receiver"
14
14
  spec.license = "GPL-3.0+"
15
15
 
16
16
  spec.files = `git ls-files`.split($/)
@@ -22,54 +22,7 @@ require "json"
22
22
 
23
23
  require "github-web-hooks-receiver/base"
24
24
 
25
- class GitLabSystemHooksReceiver < GithubWebHooksReceiver::Base
26
-
27
- private
28
-
29
- def process_payload(request, response, payload)
30
- event_name = payload["event_name"]
31
- __send__("process_#{event_name}_event", request, response, payload)
32
- end
33
-
34
- def process_project_create_event(request, response, payload)
35
- # TODO notify to owner
36
- owner_email = payload["owner_email"]
37
- project_id = payload["project_id"]
38
- @options[:web_hooks].each do |web_hook|
39
- add_project_hook(project_id, web_hook)
40
- end
41
- end
42
-
43
- def method_missing(name, *args)
44
- if name =~ /\Aprocess_.*_event\z/
45
- puts name
46
- else
47
- super
48
- end
49
- end
50
-
51
- #
52
- # POST #{GitLabURI}/projects/:id/hooks
53
- #
54
- def add_project_hook(project_id, hook_uri)
55
- api_end_point_uri = URI.parse(@options[:api_end_point])
56
- path = File.join(api_end_point_uri.path, "projects", project_id.to_s, "hooks")
57
- post_request = Net::HTTP::Post.new(path)
58
- # push_events is enabled by default
59
- post_request.set_form_data("url" => hook_uri,
60
- "private_token" => @options[:private_token])
61
- http = Net::HTTP.new(api_end_point_uri.host, api_end_point_uri.port)
62
- if api_end_point_uri.scheme == "https"
63
- http.use_ssl = true
64
- http.ca_path = "/etc/ssl/certs"
65
- http.verify_mode = OpenSSL::SSL::VERIFY_PEER
66
- http.verify_depth = 5
67
- end
68
- response = nil
69
- http.start do
70
- response = http.request(post_request)
71
- end
72
-
73
- response
74
- end
25
+ module GitLabSystemHooksReceiver
75
26
  end
27
+
28
+ require "gitlab-system-hooks-receiver/app"
@@ -0,0 +1,77 @@
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # Copyright (C) 2014-2015 Kenji Okimoto <okimoto@clear-code.com>
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+
18
+ require "net/http"
19
+ require "net/https"
20
+ require "webrick/httpstatus"
21
+ require "json"
22
+
23
+ require "github-web-hooks-receiver/base"
24
+
25
+ module GitLabSystemHooksReceiver
26
+ class App < GitHubWebHooksReceiver::Base
27
+
28
+ private
29
+
30
+ def process_payload(request, response, payload)
31
+ event_name = payload["event_name"]
32
+ __send__("process_#{event_name}_event", request, response, payload)
33
+ end
34
+
35
+ def process_project_create_event(request, response, payload)
36
+ # TODO notify to owner
37
+ owner_email = payload["owner_email"]
38
+ project_id = payload["project_id"]
39
+ @options[:web_hooks].each do |web_hook|
40
+ add_project_hook(project_id, web_hook)
41
+ end
42
+ end
43
+
44
+ def method_missing(name, *args)
45
+ if name =~ /\Aprocess_.*_event\z/
46
+ puts name
47
+ else
48
+ super
49
+ end
50
+ end
51
+
52
+ #
53
+ # POST #{GitLabURI}/projects/:id/hooks
54
+ #
55
+ def add_project_hook(project_id, hook_uri)
56
+ api_end_point_uri = URI.parse(@options[:api_end_point])
57
+ path = File.join(api_end_point_uri.path, "projects", project_id.to_s, "hooks")
58
+ post_request = Net::HTTP::Post.new(path)
59
+ # push_events is enabled by default
60
+ post_request.set_form_data("url" => hook_uri,
61
+ "private_token" => @options[:private_token])
62
+ http = Net::HTTP.new(api_end_point_uri.host, api_end_point_uri.port)
63
+ if api_end_point_uri.scheme == "https"
64
+ http.use_ssl = true
65
+ http.ca_path = "/etc/ssl/certs"
66
+ http.verify_mode = OpenSSL::SSL::VERIFY_PEER
67
+ http.verify_depth = 5
68
+ end
69
+ response = nil
70
+ http.start do
71
+ response = http.request(post_request)
72
+ end
73
+
74
+ response
75
+ end
76
+ end
77
+ end
@@ -1,4 +1,4 @@
1
1
  # -*- coding: us-ascii -*-
2
- class GitLabSystemHooksReceiver
3
- VERSION = "0.1.0"
2
+ module GitLabSystemHooksReceiver
3
+ VERSION = "0.2.0"
4
4
  end
@@ -33,7 +33,7 @@ class SystemHooksReceiverTest < Test::Unit::TestCase
33
33
  end
34
34
 
35
35
  def app
36
- GitLabSystemHooksReceiver.new(options)
36
+ GitLabSystemHooksReceiver::App.new(options)
37
37
  end
38
38
 
39
39
  def test_get
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.1.0
4
+ version: 0.2.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: 2015-03-25 00:00:00.000000000 Z
11
+ date: 2015-03-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -118,7 +118,6 @@ files:
118
118
  - ".gitignore"
119
119
  - ".travis.yml"
120
120
  - Gemfile
121
- - Gemfile.ci
122
121
  - LICENSE
123
122
  - README.md
124
123
  - Rakefile
@@ -126,11 +125,12 @@ files:
126
125
  - config.yaml.example
127
126
  - gitlab-system-hooks-receiver.gemspec
128
127
  - lib/gitlab-system-hooks-receiver.rb
128
+ - lib/gitlab-system-hooks-receiver/app.rb
129
129
  - lib/gitlab-system-hooks-receiver/version.rb
130
130
  - test/run-test.rb
131
131
  - test/system-hooks-receiver-test.rb
132
132
  - test/test-utils.rb
133
- homepage: ''
133
+ homepage: https://github.com/clear-code/gitlab-system-hooks-receiver
134
134
  licenses:
135
135
  - GPL-3.0+
136
136
  metadata: {}
data/Gemfile.ci DELETED
@@ -1,6 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- source "https://rubygems.org"
3
-
4
- # Specify your gem's dependencies in gemspec
5
- gemspec
6
-