redmine_github_hook 2.1.0 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +1 -13
- data/app/controllers/github_hook_controller.rb +32 -8
- data/app/services/github_hook/message_logger.rb +43 -0
- data/app/services/github_hook/null_logger.rb +8 -0
- data/app/services/github_hook/updater.rb +0 -7
- data/lib/redmine_github_hook/version.rb +1 -1
- data/test/functional/github_hook_controller_test.rb +10 -0
- data/test/unit/github_hook/message_logger_test.rb +49 -0
- data/test/unit/github_hook/updater_test.rb +12 -1
- metadata +14 -11
- data/app/helpers/git_hook_helper.rb +0 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0a6ff195525b5c076cf4462b8b8e8086cf6951fc
|
4
|
+
data.tar.gz: 488774f618ee936d027a1f1a3717b2269c4f9e5c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3b6e88ba8fedd6a4e33151b8d11f6d93b2f824ae71ce6203c8eca5933fd8fdba22096d8a902ff68bcd9c5ffb6c343b02974d836ea7abcb90cdc885a9b65c9101
|
7
|
+
data.tar.gz: b72341171add46e10e8503cd2ebd6ffb0cef3231ba45580924689c1427c69df9552c4fa19419adf265dd02fb8c0391d6c79f129cde317cfe6f08c580399de85f
|
data/README.md
CHANGED
@@ -15,22 +15,11 @@ That approach works perfectly fine, but is a bit heavy-handed and cumbersome. Th
|
|
15
15
|
|
16
16
|
### 1. Install the plugin
|
17
17
|
|
18
|
-
You have two options for installing the plugin:
|
19
|
-
|
20
|
-
#### A: As a RubyGem
|
21
|
-
|
22
18
|
1. Add the gem to your Gemfile.local:
|
23
19
|
`gem "redmine_github_hook"`
|
24
20
|
2. `bundle`
|
25
21
|
3. Restart your Redmine
|
26
22
|
|
27
|
-
#### B: As a plugin
|
28
|
-
|
29
|
-
1. Follow the plugin installation procedure outlined in the [Redmine wiki](http://www.redmine.org/wiki/redmine/Plugins).
|
30
|
-
* Make sure that Redmine GitHub Hook is installed in a directory named `redmine_github_hook`
|
31
|
-
* Easiest way: change in your plugins directory and pull with git: `git clone git://github.com/koppen/redmine_github_hook.git`
|
32
|
-
2. Restart your Redmine.
|
33
|
-
|
34
23
|
### 2. Add the repository to Redmine
|
35
24
|
|
36
25
|
Adding a Git repository to a project (note, this should work whether you want to use Redmine GitHub Hook or not).
|
@@ -46,7 +35,6 @@ Adding a Git repository to a project (note, this should work whether you want to
|
|
46
35
|
* If this is not the case, you can specify the actual Redmine project identifier in the Post-Receive URL by using the format `[redmine_url]/github_hook?project_id=[identifier]` (for example `http://redmine.example.com/github_hook?project_id=my_project`).
|
47
36
|
* GitHub Hook will then update **all repositories** in the specified project. *Be aware, that this process may take a while if you have many repositories in your project.*
|
48
37
|
* If you want GitHub Hook to **only update the current repository** you can specify it with an additional parameter in the Post-Receive URL by using the format `[redmine_url]/github_hook?project_id=[identifier]&repository_id=[repository]` (for example `http://redmine.example.com/github_hook?project_id=my_project&repository_id=my_repo`).
|
49
|
-
* If you want GitHub Hook to **only update the current repository** you can specify it with an additional parameter in the Post-Receive URL by using the format `[redmine_url]/github_hook?project_id=[identifier]&repository_id=[repository]` (for example `http://redmine.example.com/github_hook?project_id=my_project&repository_id=my_repo`).
|
50
38
|
* In most cases, just having the "push" event trigger the webhook should suffice, but you are free to customize the events as you desire.
|
51
39
|
* *Note: Make sure you're adding a Webhook - which is what Redmine Github Hook expects. GitHub has some builtin Redmine integration; that's not what you're looking for.*
|
52
40
|
|
@@ -94,7 +82,7 @@ The interactions between the different parts of the process is outlined in the f
|
|
94
82
|
|
95
83
|

|
96
84
|
|
97
|
-
(Diagram made with [http://bramp.github.io/js-sequence-diagrams/
|
85
|
+
(Diagram made with [js-sequence-diagrams](http://bramp.github.io/js-sequence-diagrams/)).
|
98
86
|
|
99
87
|
|
100
88
|
## License
|
@@ -4,17 +4,41 @@ class GithubHookController < ApplicationController
|
|
4
4
|
skip_before_filter :verify_authenticity_token, :check_if_login_required
|
5
5
|
|
6
6
|
def index
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
7
|
+
message_logger = GithubHook::MessageLogger.new(logger)
|
8
|
+
update_repository(message_logger) if request.post?
|
9
|
+
messages = message_logger.messages.map { |log| log[:message] }
|
10
|
+
render(:json => messages)
|
11
|
+
|
12
|
+
rescue ActiveRecord::RecordNotFound => error
|
13
|
+
render_error_as_json(error, 404)
|
14
|
+
|
15
|
+
rescue TypeError => error
|
16
|
+
render_error_as_json(error, 412)
|
15
17
|
end
|
16
18
|
|
17
19
|
def welcome
|
18
20
|
# Render the default layout
|
19
21
|
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def parse_payload
|
26
|
+
JSON.parse(params[:payload] || "{}")
|
27
|
+
end
|
28
|
+
|
29
|
+
def render_error_as_json(error, status)
|
30
|
+
render(
|
31
|
+
:json => {
|
32
|
+
:title => error.class.to_s,
|
33
|
+
:message => error.message
|
34
|
+
},
|
35
|
+
:status => status
|
36
|
+
)
|
37
|
+
end
|
38
|
+
|
39
|
+
def update_repository(logger)
|
40
|
+
updater = GithubHook::Updater.new(parse_payload, params)
|
41
|
+
updater.logger = logger
|
42
|
+
updater.call
|
43
|
+
end
|
20
44
|
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module GithubHook
|
2
|
+
class MessageLogger
|
3
|
+
attr_reader :messages, :wrapped_logger
|
4
|
+
|
5
|
+
def initialize(wrapped_logger = nil)
|
6
|
+
@messages = []
|
7
|
+
@wrapped_logger = wrapped_logger
|
8
|
+
end
|
9
|
+
|
10
|
+
def debug(message = yield)
|
11
|
+
add_message(:debug, message)
|
12
|
+
end
|
13
|
+
|
14
|
+
def error(message = yield)
|
15
|
+
add_message(:error, message)
|
16
|
+
end
|
17
|
+
|
18
|
+
def fatal(message = yield)
|
19
|
+
add_message(:fatal, message)
|
20
|
+
end
|
21
|
+
|
22
|
+
def info(message = yield)
|
23
|
+
add_message(:info, message)
|
24
|
+
end
|
25
|
+
|
26
|
+
def warn(message = yield)
|
27
|
+
add_message(:warn, message)
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def add_message(level, message)
|
33
|
+
if wrapped_logger
|
34
|
+
wrapped_logger.send(level, message)
|
35
|
+
end
|
36
|
+
|
37
|
+
@messages << {
|
38
|
+
:level => level.to_s,
|
39
|
+
:message => message
|
40
|
+
}
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -29,13 +29,6 @@ module GithubHook
|
|
29
29
|
|
30
30
|
private
|
31
31
|
|
32
|
-
class NullLogger
|
33
|
-
def debug(*_); end
|
34
|
-
def info(*_); end
|
35
|
-
def warn(*_); end
|
36
|
-
def error(*_); end
|
37
|
-
end
|
38
|
-
|
39
32
|
attr_reader :params, :payload
|
40
33
|
|
41
34
|
# Executes shell command. Returns true if the shell command exits with a
|
@@ -83,6 +83,16 @@ class GithubHookControllerTest < ActionController::TestCase
|
|
83
83
|
assert_equal 'OK', @response.body
|
84
84
|
end
|
85
85
|
|
86
|
+
def test_should_render_error_message
|
87
|
+
GithubHook::Updater.any_instance.expects(:update_repository).raises(ActiveRecord::RecordNotFound.new("Repository not found"))
|
88
|
+
do_post
|
89
|
+
assert_response :not_found
|
90
|
+
assert_equal({
|
91
|
+
"title" => "ActiveRecord::RecordNotFound",
|
92
|
+
"message" => "Repository not found"
|
93
|
+
}, JSON.parse(@response.body))
|
94
|
+
end
|
95
|
+
|
86
96
|
def test_should_not_require_login
|
87
97
|
GithubHook::Updater.any_instance.expects(:update_repository).returns(true)
|
88
98
|
@controller.expects(:check_if_login_required).never
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# require 'test_helper'
|
2
|
+
require "test/unit"
|
3
|
+
require_relative "../../../app/services/github_hook/message_logger"
|
4
|
+
|
5
|
+
class MessageLoggerTest < Test::Unit::TestCase
|
6
|
+
setup do
|
7
|
+
@logger = GithubHook::MessageLogger.new
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_adds_messages_to_an_array
|
11
|
+
logger.info "Testing"
|
12
|
+
assert_equal [
|
13
|
+
{:level => "info", :message => "Testing"}
|
14
|
+
], logger.messages
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_supports_standard_log_levels
|
18
|
+
levels = ["fatal", "error", "warn", "info", "debug"]
|
19
|
+
levels.each do |level|
|
20
|
+
logger.public_send(level, level)
|
21
|
+
end
|
22
|
+
assert_equal levels, logger.messages.map { |m| m[:level] }
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_supports_blocks
|
26
|
+
logger.debug { "This is my message" }
|
27
|
+
assert_equal [
|
28
|
+
{:level => "debug", :message => "This is my message"}
|
29
|
+
], logger.messages
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_logs_to_a_wrapped_logger_as_well
|
33
|
+
wrapped_logger = GithubHook::MessageLogger.new
|
34
|
+
logger = GithubHook::MessageLogger.new(wrapped_logger)
|
35
|
+
logger.debug "This goes everywhere"
|
36
|
+
assert_equal [
|
37
|
+
:level => "debug", :message => "This goes everywhere"
|
38
|
+
], logger.messages
|
39
|
+
assert_equal [
|
40
|
+
:level => "debug", :message => "This goes everywhere"
|
41
|
+
], wrapped_logger.messages
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def logger
|
47
|
+
@logger ||= GithubHook::MessageLogger.new
|
48
|
+
end
|
49
|
+
end
|
@@ -23,7 +23,7 @@ class GithubHookUpdaterTest < Test::Unit::TestCase
|
|
23
23
|
|
24
24
|
def payload
|
25
25
|
# Ruby hash with the parsed data from the JSON payload
|
26
|
-
{"before"=>"5aef35982fb2d34e9d9d4502f6ede1072793222d", "repository"=>{"url"=>"http://github.com/defunkt/github", "name"=>"github", "description"=>"You're lookin' at it.", "watchers"=>5, "forks"=>2, "private"=>1, "owner"=>{"email"=>"chris@ozmm.org", "name"=>"defunkt"}}, "commits"=>[{"id"=>"41a212ee83ca127e3c8cf465891ab7216a705f59", "url"=>"http://github.com/defunkt/github/commit/41a212ee83ca127e3c8cf465891ab7216a705f59", "author"=>{"email"=>"chris@ozmm.org", "name"=>"Chris Wanstrath"}, "message"=>"okay i give in", "timestamp"=>"2008-02-15T14:57:17-08:00", "added"=>["filepath.rb"]}, {"id"=>"de8251ff97ee194a289832576287d6f8ad74e3d0", "url"=>"http://github.com/defunkt/github/commit/de8251ff97ee194a289832576287d6f8ad74e3d0", "author"=>{"email"=>"chris@ozmm.org", "name"=>"Chris Wanstrath"}, "message"=>"update pricing a tad", "timestamp"=>"2008-02-15T14:36:34-08:00"}], "after"=>"de8251ff97ee194a289832576287d6f8ad74e3d0", "ref"=>"refs/heads/master"}
|
26
|
+
{"before" => "5aef35982fb2d34e9d9d4502f6ede1072793222d", "repository"=>{"url" => "http://github.com/defunkt/github", "name" => "github", "description" => "You're lookin' at it.", "watchers"=>5, "forks"=>2, "private"=>1, "owner"=>{"email" => "chris@ozmm.org", "name" => "defunkt"}}, "commits"=>[{"id" => "41a212ee83ca127e3c8cf465891ab7216a705f59", "url" => "http://github.com/defunkt/github/commit/41a212ee83ca127e3c8cf465891ab7216a705f59", "author"=>{"email" => "chris@ozmm.org", "name" => "Chris Wanstrath"}, "message" => "okay i give in", "timestamp" => "2008-02-15T14:57:17-08:00", "added"=>["filepath.rb"]}, {"id" => "de8251ff97ee194a289832576287d6f8ad74e3d0", "url" => "http://github.com/defunkt/github/commit/de8251ff97ee194a289832576287d6f8ad74e3d0", "author"=>{"email" => "chris@ozmm.org", "name" => "Chris Wanstrath"}, "message" => "update pricing a tad", "timestamp" => "2008-02-15T14:36:34-08:00"}], "after" => "de8251ff97ee194a289832576287d6f8ad74e3d0", "ref" => "refs/heads/master"}
|
27
27
|
end
|
28
28
|
|
29
29
|
def build_updater(payload, options = {})
|
@@ -171,4 +171,15 @@ class GithubHookUpdaterTest < Test::Unit::TestCase
|
|
171
171
|
|
172
172
|
updater.call
|
173
173
|
end
|
174
|
+
|
175
|
+
def test_logs_if_a_message_logger_is_given
|
176
|
+
updater = GithubHook::Updater.new(payload)
|
177
|
+
updater.stubs(:exec).returns(true)
|
178
|
+
|
179
|
+
logger = GithubHook::MessageLogger.new
|
180
|
+
updater.logger = logger
|
181
|
+
|
182
|
+
updater.call
|
183
|
+
assert logger.messages.any?, "Should have received messages"
|
184
|
+
end
|
174
185
|
end
|
metadata
CHANGED
@@ -1,41 +1,41 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redmine_github_hook
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jakob Skjerning
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-05-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.5'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.5'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
description:
|
@@ -45,13 +45,14 @@ executables: []
|
|
45
45
|
extensions: []
|
46
46
|
extra_rdoc_files: []
|
47
47
|
files:
|
48
|
-
- .gitignore
|
48
|
+
- ".gitignore"
|
49
49
|
- Gemfile
|
50
50
|
- LICENSE
|
51
51
|
- README.md
|
52
52
|
- Rakefile
|
53
53
|
- app/controllers/github_hook_controller.rb
|
54
|
-
- app/
|
54
|
+
- app/services/github_hook/message_logger.rb
|
55
|
+
- app/services/github_hook/null_logger.rb
|
55
56
|
- app/services/github_hook/updater.rb
|
56
57
|
- app/views/github_hook/welcome.html.erb
|
57
58
|
- config/routes.rb
|
@@ -62,6 +63,7 @@ files:
|
|
62
63
|
- redmine_github_hook.gemspec
|
63
64
|
- test/functional/github_hook_controller_test.rb
|
64
65
|
- test/test_helper.rb
|
66
|
+
- test/unit/github_hook/message_logger_test.rb
|
65
67
|
- test/unit/github_hook/updater_test.rb
|
66
68
|
homepage: ''
|
67
69
|
licenses:
|
@@ -73,17 +75,17 @@ require_paths:
|
|
73
75
|
- lib
|
74
76
|
required_ruby_version: !ruby/object:Gem::Requirement
|
75
77
|
requirements:
|
76
|
-
- -
|
78
|
+
- - ">="
|
77
79
|
- !ruby/object:Gem::Version
|
78
80
|
version: '0'
|
79
81
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
82
|
requirements:
|
81
|
-
- -
|
83
|
+
- - ">="
|
82
84
|
- !ruby/object:Gem::Version
|
83
85
|
version: '0'
|
84
86
|
requirements: []
|
85
87
|
rubyforge_project:
|
86
|
-
rubygems_version: 2.
|
88
|
+
rubygems_version: 2.4.6
|
87
89
|
signing_key:
|
88
90
|
specification_version: 4
|
89
91
|
summary: Allow your Redmine installation to be notified when changes have been pushed
|
@@ -91,4 +93,5 @@ summary: Allow your Redmine installation to be notified when changes have been p
|
|
91
93
|
test_files:
|
92
94
|
- test/functional/github_hook_controller_test.rb
|
93
95
|
- test/test_helper.rb
|
96
|
+
- test/unit/github_hook/message_logger_test.rb
|
94
97
|
- test/unit/github_hook/updater_test.rb
|