lita-gerrit 0.0.2 → 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/contrib/lita-gerrit-hook +1 -1
- data/lib/lita/handlers/gerrit.rb +40 -8
- data/lita-gerrit.gemspec +1 -1
- data/spec/fixtures/build_notification.json +47 -0
- data/spec/fixtures/change_details.json +18 -0
- data/spec/lita/handlers/gerrit_spec.rb +43 -28
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3b203e85230aa8bad7bba1b02adc97fe69462fb3
|
4
|
+
data.tar.gz: d58f748675e6055d824dfa4dfef42e5fcd9ffe33
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8a68658534cf347da6a1fa4695bfd941b4e938f261461de172f152f0accbd921e843e9ca7bbcc1ea410175f631718f2410b6e6c8cf2bd4be0b624d04f1ef6097
|
7
|
+
data.tar.gz: 9f395162979bc89a2b7ec4c5d2d8dfdbc69d6e7054550f2b3d75996701fe4cf59a9bba7a36b74684a95b9a9c59bb6c83740395fdb3c4658f93cb63efc967eebf
|
data/contrib/lita-gerrit-hook
CHANGED
data/lib/lita/handlers/gerrit.rb
CHANGED
@@ -28,11 +28,11 @@ module Lita
|
|
28
28
|
case http_resp.code
|
29
29
|
when 200
|
30
30
|
change = MultiJson.load(http_resp.body.lines.to_a[1..-1].join)
|
31
|
-
message = "gerrit
|
31
|
+
message = "[gerrit] [#{change["project"]}] \"#{change["subject"]}\" by #{change["owner"]["name"]}. #{change_link}"
|
32
32
|
when 404
|
33
|
-
message = "Change ##{change_id} does not exist"
|
33
|
+
message = "[gerrit] Change ##{change_id} does not exist"
|
34
34
|
else
|
35
|
-
raise "Failed to fetch #{change_uri} (#{http_resp.code})"
|
35
|
+
raise "[gerrit] Failed to fetch #{change_uri} (#{http_resp.code})"
|
36
36
|
end
|
37
37
|
|
38
38
|
response.reply(message)
|
@@ -74,24 +74,56 @@ module Lita
|
|
74
74
|
Lita.logger.error(e.message)
|
75
75
|
end
|
76
76
|
|
77
|
+
#
|
78
|
+
# Notification from Jenkins build
|
79
|
+
#
|
80
|
+
|
81
|
+
http.post "/gerrit/build/:room", :build_notification
|
82
|
+
|
83
|
+
def build_notification(request, response)
|
84
|
+
target = Source.new(room: request.env["router.params"][:room])
|
85
|
+
notification = MultiJson.load(request.body.read)
|
86
|
+
build = notification["build"]
|
87
|
+
params = build["parameters"]
|
88
|
+
|
89
|
+
message = "[jenkins] [#{params["GERRIT_PROJECT"]}] Build %s for \"#{params["GERRIT_CHANGE_SUBJECT"]}\" by #{params["GERRIT_PATCHSET_UPLOADER_NAME"]}"
|
90
|
+
|
91
|
+
if build["phase"] == "FINALIZED"
|
92
|
+
case build["status"]
|
93
|
+
when "FAILURE"
|
94
|
+
message = message % "FAILED"
|
95
|
+
message += " (#{build["full_url"]})"
|
96
|
+
when "SUCCESS"
|
97
|
+
message = message % "OK"
|
98
|
+
else
|
99
|
+
message = message % "UNKNOWN"
|
100
|
+
end
|
101
|
+
|
102
|
+
robot.send_message(target, message)
|
103
|
+
end
|
104
|
+
|
105
|
+
rescue Exception => e
|
106
|
+
robot.send_message(target, "[jenkins] failed to process Gerrit build event (#{e.message})")
|
107
|
+
end
|
108
|
+
|
77
109
|
private
|
78
110
|
|
79
111
|
# List of supported hooks
|
80
112
|
# (https://gerrit-review.googlesource.com/Documentation/config-hooks.html#_supported_hooks)
|
81
113
|
|
82
114
|
def patchset_created(params)
|
83
|
-
message = "gerrit
|
84
|
-
message % [params["
|
115
|
+
message = "[gerrit] [%s] %s uploaded patchset %s. %s"
|
116
|
+
message % [params["project"], params["uploader"], params["patchset"], params["change-url"]]
|
85
117
|
end
|
86
118
|
|
87
119
|
def comment_added(params)
|
88
|
-
message = "gerrit
|
120
|
+
message = "[gerrit] [%s]: %s commented %s (V:%s/CR:%s)"
|
89
121
|
message % [params["project"], params["author"], params["change-url"], params["verified"], params["reviewed"]]
|
90
122
|
end
|
91
123
|
|
92
124
|
def change_merged(params)
|
93
|
-
message = "gerrit
|
94
|
-
message % [params["
|
125
|
+
message = "[gerrit] [%s] %s merged %s"
|
126
|
+
message % [params["project"], params["submitter"], params["change-url"]]
|
95
127
|
end
|
96
128
|
end
|
97
129
|
|
data/lita-gerrit.gemspec
CHANGED
@@ -0,0 +1,47 @@
|
|
1
|
+
{
|
2
|
+
"name": "chef-gerrit_tests",
|
3
|
+
"url": "job/chef-gerrit_tests/",
|
4
|
+
"build": {
|
5
|
+
"full_url": "http://jenkins.example.loc/job/chef-gerrit_tests/315/",
|
6
|
+
"number": 315,
|
7
|
+
"phase": "FINALIZED",
|
8
|
+
"status": "SUCCESS",
|
9
|
+
"url": "job/chef-gerrit_tests/315/",
|
10
|
+
"scm": {
|
11
|
+
"url": "ssh://gerrit.example.loc:29418/sysadmin/chef.git",
|
12
|
+
"branch": "detached",
|
13
|
+
"commit": "f97200b5d5bbf5bd242f645f29e089e47fa51ff3"
|
14
|
+
},
|
15
|
+
"parameters": {
|
16
|
+
"GERRIT_HOST": "gerrit.example.loc",
|
17
|
+
"GERRIT_PATCHSET_UPLOADER": "\"Hervé\" <herve@example.com>",
|
18
|
+
"GERRIT_EVENT_ACCOUNT_NAME": "Hervé",
|
19
|
+
"GERRIT_EVENT_TYPE": "patchset-created",
|
20
|
+
"GERRIT_CHANGE_ID": "I29a79eae813c7662736dd1a1f9074cc316301918",
|
21
|
+
"GERRIT_TOPIC": "es_http_compress",
|
22
|
+
"GERRIT_CHANGE_NUMBER": "3705",
|
23
|
+
"GERRIT_VERSION": "2.8.1",
|
24
|
+
"GERRIT_PATCHSET_UPLOADER_NAME": "Hervé",
|
25
|
+
"GERRIT_CHANGE_COMMIT_MESSAGE": "aGFwcm94eTogZW5hYmxlIEhUVFAgY29tcHJlc3Npb24gb24ga2liYW5hIGZyb250ZW5kCgpDaGFuZ2UtSWQ6IEkyOWE3OWVhZTgxM2M3NjYyNzM2ZGQxYTFmOTA3NGNjMzE2MzAxOTE4Cg==",
|
26
|
+
"GERRIT_PATCHSET_UPLOADER_EMAIL": "herve@example.com",
|
27
|
+
"GERRIT_PORT": "29418",
|
28
|
+
"GERRIT_EVENT_HASH": "-108092174",
|
29
|
+
"GERRIT_BRANCH": "master",
|
30
|
+
"GERRIT_NAME": "gerrit.example.loc",
|
31
|
+
"GERRIT_CHANGE_OWNER_NAME": "Hervé",
|
32
|
+
"GERRIT_EVENT_ACCOUNT": "\"Hervé\" <herve@example.com>",
|
33
|
+
"GERRIT_EVENT_ACCOUNT_EMAIL": "herve@example.com",
|
34
|
+
"GERRIT_CHANGE_OWNER": "\"Hervé\" <herve@example.com>",
|
35
|
+
"GERRIT_CHANGE_URL": "http://gerrit.example.loc:8080/3705",
|
36
|
+
"GERRIT_SCHEME": "ssh",
|
37
|
+
"GERRIT_CHANGE_SUBJECT": "haproxy: enable HTTP compression on kibana frontend",
|
38
|
+
"GERRIT_REFSPEC": "refs/changes/05/3705/2",
|
39
|
+
"GERRIT_PATCHSET_NUMBER": "2",
|
40
|
+
"GERRIT_PATCHSET_REVISION": "f97200b5d5bbf5bd242f645f29e089e47fa51ff3",
|
41
|
+
"GERRIT_PROJECT": "sysadmin/chef",
|
42
|
+
"GERRIT_CHANGE_OWNER_EMAIL": "herve@example.com"
|
43
|
+
},
|
44
|
+
"artifacts": {
|
45
|
+
}
|
46
|
+
}
|
47
|
+
}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
)]}'
|
2
|
+
{
|
3
|
+
"kind": "gerritcodereview#change",
|
4
|
+
"id": "chef~master~Ib0b61ed3eebb8e22596a8401bf976949d798826a",
|
5
|
+
"project": "chef",
|
6
|
+
"branch": "master",
|
7
|
+
"topic": "beanstalk",
|
8
|
+
"change_id": "Ib0b61ed3eebb8e22596a8401bf976949d798826a",
|
9
|
+
"subject": "haproxy : migrate beanstalk frontend",
|
10
|
+
"status": "MERGED",
|
11
|
+
"created": "2014-03-14 12:42:15.320000000",
|
12
|
+
"updated": "2014-03-17 10:32:21.311000000",
|
13
|
+
"_sortkey": "002bcd180000096b",
|
14
|
+
"_number": 42,
|
15
|
+
"owner": {
|
16
|
+
"name": "John Doe"
|
17
|
+
}
|
18
|
+
}
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require "spec_helper"
|
2
|
+
require "stringio"
|
2
3
|
|
3
4
|
describe Lita::Handlers::Gerrit, lita_handler: true do
|
4
5
|
|
@@ -13,12 +14,9 @@ describe Lita::Handlers::Gerrit, lita_handler: true do
|
|
13
14
|
it { routes("get me gerrit 123, please").to(:change_details) }
|
14
15
|
it { doesnt_route("gerrit foo").to(:change_details) }
|
15
16
|
|
16
|
-
it { routes_http(:post, "/gerrit/hooks").to(:hook) }
|
17
|
-
|
18
17
|
describe "#change_details" do
|
19
|
-
let(:response)
|
20
|
-
|
21
|
-
end
|
18
|
+
let(:response) { double("HTTParty::Response") }
|
19
|
+
let(:body) { File.read("spec/fixtures/change_details.json") }
|
22
20
|
|
23
21
|
before do
|
24
22
|
allow(HTTParty).to receive(:get).and_return(response)
|
@@ -26,31 +24,9 @@ describe Lita::Handlers::Gerrit, lita_handler: true do
|
|
26
24
|
|
27
25
|
it "replies with the title and URL for the issue" do
|
28
26
|
allow(response).to receive(:code).and_return(200)
|
29
|
-
|
30
|
-
allow(response).to receive(:body).and_return(<<-JSON.chomp
|
31
|
-
)]}'
|
32
|
-
{
|
33
|
-
"kind": "gerritcodereview#change",
|
34
|
-
"id": "chef~master~Ib0b61ed3eebb8e22596a8401bf976949d798826a",
|
35
|
-
"project": "chef",
|
36
|
-
"branch": "master",
|
37
|
-
"topic": "beanstalk",
|
38
|
-
"change_id": "Ib0b61ed3eebb8e22596a8401bf976949d798826a",
|
39
|
-
"subject": "haproxy : migrate beanstalk frontend",
|
40
|
-
"status": "MERGED",
|
41
|
-
"created": "2014-03-14 12:42:15.320000000",
|
42
|
-
"updated": "2014-03-17 10:32:21.311000000",
|
43
|
-
"_sortkey": "002bcd180000096b",
|
44
|
-
"_number": 42,
|
45
|
-
"owner": {
|
46
|
-
"name": "John Doe"
|
47
|
-
}
|
48
|
-
}
|
49
|
-
JSON
|
50
|
-
)
|
27
|
+
allow(response).to receive(:body).and_return(body)
|
51
28
|
|
52
29
|
send_command("gerrit 42")
|
53
|
-
|
54
30
|
expect(replies.last).to eq("gerrit: haproxy : migrate beanstalk frontend by John Doe in chef. https://gerrit.example.com/42")
|
55
31
|
end
|
56
32
|
|
@@ -70,4 +46,43 @@ JSON
|
|
70
46
|
expect(replies.last).to match("Error: Failed to fetch https://gerrit.example.com/a/changes/42 (500)")
|
71
47
|
end
|
72
48
|
end
|
49
|
+
|
50
|
+
it { routes_http(:post, "/gerrit/hooks").to(:hook) }
|
51
|
+
|
52
|
+
describe "#hook" do
|
53
|
+
let(:request) do
|
54
|
+
request = double("Rack::Request")
|
55
|
+
allow(request).to receive(:params).and_return(params)
|
56
|
+
request
|
57
|
+
end
|
58
|
+
|
59
|
+
let(:response) { Rack::Response.new }
|
60
|
+
|
61
|
+
let(:params) { double("Hash") }
|
62
|
+
end
|
63
|
+
|
64
|
+
it { routes_http(:post, "/gerrit/build/myroom").to(:build_notification) }
|
65
|
+
it { doesnt_route_http(:post, "/gerrit/build/").to(:build_notification) }
|
66
|
+
|
67
|
+
describe "#build_notification" do
|
68
|
+
let(:request) { double("Rack::Request") }
|
69
|
+
let(:response) { Rack::Response.new }
|
70
|
+
let(:env) { {"router.params" => { :room => "myroom" }} }
|
71
|
+
let(:body) { File.read("spec/fixtures/build_notification.json") }
|
72
|
+
|
73
|
+
context "build finalized" do
|
74
|
+
before do
|
75
|
+
allow(request).to receive(:env).and_return(env)
|
76
|
+
allow(request).to receive(:body).and_return(StringIO.new(body))
|
77
|
+
end
|
78
|
+
|
79
|
+
it "notifies the applicable room" do
|
80
|
+
expect(robot).to receive(:send_message) do |target, message|
|
81
|
+
expect(target.room).to eq("myroom")
|
82
|
+
expect(message).to eq('jenkins: Build "haproxy: enable HTTP compression on kibana frontend" by Hervé in sysadmin/chef OK')
|
83
|
+
end
|
84
|
+
subject.build_notification(request, response)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
73
88
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lita-gerrit
|
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
|
- Jonathan Amiez
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-11-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: lita
|
@@ -125,6 +125,8 @@ files:
|
|
125
125
|
- lib/lita-gerrit.rb
|
126
126
|
- lib/lita/handlers/gerrit.rb
|
127
127
|
- lita-gerrit.gemspec
|
128
|
+
- spec/fixtures/build_notification.json
|
129
|
+
- spec/fixtures/change_details.json
|
128
130
|
- spec/lita/handlers/gerrit_spec.rb
|
129
131
|
- spec/spec_helper.rb
|
130
132
|
homepage: https://github.com/josqu4red/lita-gerrit
|
@@ -153,5 +155,7 @@ signing_key:
|
|
153
155
|
specification_version: 4
|
154
156
|
summary: Retrieve change status from chat and display events
|
155
157
|
test_files:
|
158
|
+
- spec/fixtures/build_notification.json
|
159
|
+
- spec/fixtures/change_details.json
|
156
160
|
- spec/lita/handlers/gerrit_spec.rb
|
157
161
|
- spec/spec_helper.rb
|