janky 0.9.0 → 0.9.9
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +30 -0
- data/README.md +59 -21
- data/Rakefile +7 -0
- data/janky.gemspec +6 -4
- data/lib/janky.rb +81 -22
- data/lib/janky/app.rb +1 -1
- data/lib/janky/build.rb +9 -1
- data/lib/janky/builder/http.rb +8 -0
- data/lib/janky/builder/receiver.rb +1 -1
- data/lib/janky/{campfire.rb → chat_service.rb} +28 -55
- data/lib/janky/chat_service/campfire.rb +33 -0
- data/lib/janky/chat_service/hipchat.rb +29 -0
- data/lib/janky/chat_service/mock.rb +26 -0
- data/lib/janky/database/migrate/1312115512_init.rb +1 -1
- data/lib/janky/exception.rb +23 -0
- data/lib/janky/github.rb +82 -23
- data/lib/janky/github/api.rb +17 -8
- data/lib/janky/github/payload_parser.rb +1 -1
- data/lib/janky/hubot.rb +15 -14
- data/lib/janky/job_creator.rb +10 -2
- data/lib/janky/notifier/{campfire.rb → chat_service.rb} +4 -3
- data/lib/janky/notifier/mock.rb +2 -2
- data/lib/janky/public/css/base.css +33 -10
- data/lib/janky/repository.rb +4 -4
- data/lib/janky/templates/index.mustache +10 -5
- data/lib/janky/version.rb +1 -1
- data/lib/janky/views/index.rb +10 -3
- data/lib/janky/views/layout.rb +1 -0
- data/test/janky_test.rb +14 -2
- data/test/test_helper.rb +5 -4
- metadata +13 -10
- data/lib/janky/campfire/mock.rb +0 -0
@@ -41,7 +41,7 @@ module Janky
|
|
41
41
|
repository = @payload["repository"]
|
42
42
|
|
43
43
|
if repository["private"]
|
44
|
-
"git
|
44
|
+
"git@#{GitHub.git_host}:#{URI(repository["url"]).path[1..-1]}"
|
45
45
|
else
|
46
46
|
uri = URI(repository["url"])
|
47
47
|
uri.scheme = "git"
|
data/lib/janky/hubot.rb
CHANGED
@@ -4,7 +4,7 @@ module Janky
|
|
4
4
|
# builds.
|
5
5
|
#
|
6
6
|
# The client side implementation is at
|
7
|
-
# <https://github.com/github/hubot/blob/master/scripts/
|
7
|
+
# <https://github.com/github/hubot-scripts/blob/master/src/scripts/janky.coffee>
|
8
8
|
class Hubot < Sinatra::Base
|
9
9
|
register Helpers
|
10
10
|
|
@@ -15,7 +15,7 @@ module Janky
|
|
15
15
|
repo = Repository.setup(nwo, name)
|
16
16
|
|
17
17
|
if repo
|
18
|
-
url = "#{settings.base_url}
|
18
|
+
url = "#{settings.base_url}#{repo.name}"
|
19
19
|
[201, "Setup #{repo.name} at #{repo.uri} | #{url}"]
|
20
20
|
else
|
21
21
|
[400, "Couldn't access #{nwo}. Check the permissions."]
|
@@ -31,11 +31,12 @@ module Janky
|
|
31
31
|
end
|
32
32
|
|
33
33
|
# Build a repository's branch.
|
34
|
-
post
|
34
|
+
post %r{\/([-_\.0-9a-zA-Z]+)\/([-_\.a-zA-z0-9\/]+)} do |repo_name, branch_name|
|
35
35
|
repo = find_repo(repo_name)
|
36
36
|
branch = repo.branch_for(branch_name)
|
37
37
|
build = branch.current_build
|
38
|
-
|
38
|
+
|
39
|
+
room_id = (params["room_id"] && Integer(params["room_id"]) rescue nil)
|
39
40
|
|
40
41
|
if build
|
41
42
|
build.rerun(room_id)
|
@@ -48,7 +49,7 @@ module Janky
|
|
48
49
|
|
49
50
|
# Get a list of available rooms.
|
50
51
|
get "/rooms" do
|
51
|
-
Yajl.dump(
|
52
|
+
Yajl.dump(ChatService.room_names)
|
52
53
|
end
|
53
54
|
|
54
55
|
# Update a repository's notification room.
|
@@ -56,7 +57,7 @@ module Janky
|
|
56
57
|
repo = find_repo(repo_name)
|
57
58
|
room = params["room"]
|
58
59
|
|
59
|
-
if room_id =
|
60
|
+
if room_id = ChatService.room_id(room)
|
60
61
|
repo.update_attributes!(:room_id => room_id)
|
61
62
|
[200, "Room for #{repo.name} updated to #{room}"]
|
62
63
|
else
|
@@ -67,7 +68,7 @@ module Janky
|
|
67
68
|
# Get the status of all projects.
|
68
69
|
get "/" do
|
69
70
|
content_type "text/plain"
|
70
|
-
repos = Repository.all.map do |repo|
|
71
|
+
repos = Repository.all(:include => [:branches, :commits, :builds]).map do |repo|
|
71
72
|
master = repo.branch_for("master")
|
72
73
|
|
73
74
|
"%-17s %-13s %-10s %40s" % [
|
@@ -81,7 +82,7 @@ module Janky
|
|
81
82
|
end
|
82
83
|
|
83
84
|
# Get the status of a repository's branch.
|
84
|
-
get
|
85
|
+
get %r{\/([-_\.0-9a-zA-Z]+)\/([-_\.a-zA-z0-9\/]+)} do |repo_name, branch_name|
|
85
86
|
limit = params["limit"]
|
86
87
|
|
87
88
|
repo = find_repo(repo_name)
|
@@ -105,12 +106,12 @@ module Janky
|
|
105
106
|
get "/help" do
|
106
107
|
content_type "text/plain"
|
107
108
|
<<-EOS
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
109
|
+
ci build janky
|
110
|
+
ci build janky/fix-everything
|
111
|
+
ci setup github/janky [name]
|
112
|
+
ci toggle janky
|
113
|
+
ci rooms
|
114
|
+
ci set room janky development
|
114
115
|
EOS
|
115
116
|
end
|
116
117
|
end
|
data/lib/janky/job_creator.rb
CHANGED
@@ -71,9 +71,13 @@ module Janky
|
|
71
71
|
uri = server_url
|
72
72
|
user = uri.user
|
73
73
|
pass = uri.password
|
74
|
+
path = uri.path
|
74
75
|
http = Net::HTTP.new(uri.host, uri.port)
|
76
|
+
if uri.scheme == "https"
|
77
|
+
http.use_ssl = true
|
78
|
+
end
|
75
79
|
|
76
|
-
get = Net::HTTP::Get.new("/job/#{name}/")
|
80
|
+
get = Net::HTTP::Get.new("#{path}/job/#{name}/")
|
77
81
|
get.basic_auth(user, pass) if user && pass
|
78
82
|
response = http.request(get)
|
79
83
|
|
@@ -92,9 +96,13 @@ module Janky
|
|
92
96
|
uri = server_url
|
93
97
|
user = uri.user
|
94
98
|
pass = uri.password
|
99
|
+
path = uri.path
|
95
100
|
http = Net::HTTP.new(uri.host, uri.port)
|
101
|
+
if uri.scheme == "https"
|
102
|
+
http.use_ssl = true
|
103
|
+
end
|
96
104
|
|
97
|
-
post = Net::HTTP::Post.new("/createItem?name=#{name}")
|
105
|
+
post = Net::HTTP::Post.new("#{path}/createItem?name=#{name}")
|
98
106
|
post.basic_auth(user, pass) if user && pass
|
99
107
|
post["Content-Type"] = "application/xml"
|
100
108
|
post.body = config
|
@@ -1,8 +1,9 @@
|
|
1
1
|
module Janky
|
2
2
|
module Notifier
|
3
|
-
class
|
3
|
+
class ChatService
|
4
4
|
def self.completed(build)
|
5
|
-
status
|
5
|
+
status = build.green? ? "was successful" : "failed"
|
6
|
+
color = build.green? ? "green" : "red"
|
6
7
|
|
7
8
|
message = "Build #%s (%s) of %s/%s %s (%ss) %s" % [
|
8
9
|
build.number,
|
@@ -14,7 +15,7 @@ module Janky
|
|
14
15
|
build.compare
|
15
16
|
]
|
16
17
|
|
17
|
-
::Janky::
|
18
|
+
::Janky::ChatService.speak(message, build.room_id, {:color => color})
|
18
19
|
end
|
19
20
|
end
|
20
21
|
end
|
data/lib/janky/notifier/mock.rb
CHANGED
@@ -24,7 +24,7 @@ module Janky
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def success?(repo, branch, room_name)
|
27
|
-
room_name ||= Janky::
|
27
|
+
room_name ||= Janky::ChatService.default_room_name
|
28
28
|
|
29
29
|
builds = @notifications.select do |state, build|
|
30
30
|
state == :completed &&
|
@@ -38,7 +38,7 @@ module Janky
|
|
38
38
|
end
|
39
39
|
|
40
40
|
def failure?(repo, branch, room_name)
|
41
|
-
room_name ||= Janky::
|
41
|
+
room_name ||= Janky::ChatService.default_room_name
|
42
42
|
|
43
43
|
builds = @notifications.select do |state, build|
|
44
44
|
state == :completed &&
|
@@ -25,6 +25,7 @@ a img{ border:none; }
|
|
25
25
|
* html .clearfix {height: 1%;}
|
26
26
|
.clearfix {display:inline-block;}
|
27
27
|
.clearfix {display: block;}
|
28
|
+
.right {float: right;}
|
28
29
|
|
29
30
|
/* @end */
|
30
31
|
|
@@ -112,14 +113,21 @@ ul.builds li.building:hover{
|
|
112
113
|
}
|
113
114
|
|
114
115
|
ul.builds a{
|
115
|
-
display:block;
|
116
116
|
text-decoration:none;
|
117
|
-
background:url(../images/disclosure-arrow.png) 100% 10px no-repeat;
|
118
117
|
}
|
119
|
-
|
120
|
-
|
118
|
+
|
119
|
+
ul.builds a.console{
|
120
|
+
float: right;
|
121
|
+
display:block;
|
122
|
+
width: 22px;
|
123
|
+
height: 40px;
|
124
|
+
margin-left: 10px;
|
125
|
+
background:url(../images/disclosure-arrow.png) 65% 10px no-repeat;
|
121
126
|
}
|
122
|
-
ul.builds
|
127
|
+
ul.builds li:hover a.console{
|
128
|
+
background-position:65% -90px;
|
129
|
+
}
|
130
|
+
ul.builds .building a.console{
|
123
131
|
background:none;
|
124
132
|
cursor:default;
|
125
133
|
}
|
@@ -144,16 +152,31 @@ ul.builds h2{
|
|
144
152
|
font-size:16px;
|
145
153
|
text-shadow:0 1px #fff;
|
146
154
|
}
|
147
|
-
ul.builds
|
155
|
+
ul.builds h2 span{
|
156
|
+
font-weight: normal;
|
157
|
+
color: #666666;
|
158
|
+
}
|
159
|
+
ul.builds .good a{
|
160
|
+
color:#358c00;
|
161
|
+
}
|
162
|
+
ul.builds .good h2{
|
148
163
|
color:#358c00;
|
149
164
|
}
|
150
|
-
ul.builds .building a
|
165
|
+
ul.builds .building a{
|
166
|
+
color:#e59741;
|
167
|
+
}
|
168
|
+
ul.builds .building h2{
|
151
169
|
color:#e59741;
|
152
170
|
}
|
153
|
-
ul.builds .janky a
|
171
|
+
ul.builds .janky a{
|
154
172
|
color:#ae0000;
|
155
173
|
}
|
156
|
-
|
174
|
+
ul.builds .janky h2{
|
175
|
+
color:#ae0000;
|
176
|
+
}
|
177
|
+
ul.builds p.sha1{
|
178
|
+
margin-top: 2px;
|
179
|
+
}
|
157
180
|
ul.builds p{
|
158
181
|
margin:-2px 0 0 0;
|
159
182
|
font-size:13px;
|
@@ -201,4 +224,4 @@ pre::-webkit-scrollbar-thumb:horizontal{
|
|
201
224
|
-webkit-border-radius: 4px;
|
202
225
|
}
|
203
226
|
|
204
|
-
/* @end */
|
227
|
+
/* @end */
|
data/lib/janky/repository.rb
CHANGED
@@ -86,27 +86,27 @@ module Janky
|
|
86
86
|
#
|
87
87
|
# Returns the user name as a String.
|
88
88
|
def github_owner
|
89
|
-
uri[
|
89
|
+
uri[/.*[\/:]([a-zA-Z0-9\-_]+)\//] && $1
|
90
90
|
end
|
91
91
|
|
92
92
|
# Name of this repository on GitHub.
|
93
93
|
#
|
94
94
|
# Returns the name as a String.
|
95
95
|
def github_name
|
96
|
-
uri[
|
96
|
+
uri[/.*[\/:]([a-zA-Z0-9\-_]+)\/([a-zA-Z0-9\-_]+)/] && $2
|
97
97
|
end
|
98
98
|
|
99
99
|
# Name of the Campfire room receiving build notifications.
|
100
100
|
#
|
101
101
|
# Returns the name as a String.
|
102
102
|
def campfire_room
|
103
|
-
|
103
|
+
ChatService.room_name(room_id)
|
104
104
|
end
|
105
105
|
|
106
106
|
# Ditto but returns the Fixnum room id. Defaults to the one set
|
107
107
|
# in Campfire.setup.
|
108
108
|
def room_id
|
109
|
-
read_attribute(:room_id) ||
|
109
|
+
read_attribute(:room_id) || ChatService.default_room_id
|
110
110
|
end
|
111
111
|
|
112
112
|
# Setups GitHub and Jenkins for build this repository.
|
@@ -1,11 +1,16 @@
|
|
1
1
|
<ul class="builds">
|
2
2
|
{{# jobs }}
|
3
3
|
<li class="{{ status }}">
|
4
|
-
<
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
<span class="status"></span>
|
5
|
+
<a class="console" href="{{ console_path }}"></a>
|
6
|
+
<p class="right sha1"><a title="{{message}}" href="{{compare_url}}">{{sha1}}</a></p>
|
7
|
+
<h2>
|
8
|
+
<a href="{{repo_path}}">{{ repo_name }}</a>/<a href="{{branch_path}}">{{ branch_name }}</a>
|
9
|
+
</h2>
|
10
|
+
<p>
|
11
|
+
<span class="right">{{author}}</span>
|
12
|
+
{{{ last_built_text }}}
|
13
|
+
</p>
|
9
14
|
</li>
|
10
15
|
{{/ jobs }}
|
11
16
|
</ul>
|
data/lib/janky/version.rb
CHANGED
data/lib/janky/views/index.rb
CHANGED
@@ -6,9 +6,16 @@ module Janky
|
|
6
6
|
@builds.collect do |build|
|
7
7
|
{
|
8
8
|
:console_path => "/#{build.number}/output",
|
9
|
-
:
|
9
|
+
:compare_url => build.compare,
|
10
|
+
:repo_path => "/#{build.repo_name}",
|
11
|
+
:branch_path => "/#{build.repo_name}/#{build.branch_name}",
|
12
|
+
:repo_name => build.repo_name,
|
13
|
+
:branch_name => build.branch_name,
|
10
14
|
:status => css_status_for(build),
|
11
|
-
:last_built_text => last_built_text_for(build)
|
15
|
+
:last_built_text => last_built_text_for(build),
|
16
|
+
:message => build.commit_message,
|
17
|
+
:sha1 => build.sha1,
|
18
|
+
:author => build.commit_author.split("<").first
|
12
19
|
}
|
13
20
|
end
|
14
21
|
end
|
@@ -25,7 +32,7 @@ module Janky
|
|
25
32
|
|
26
33
|
def last_built_text_for(build)
|
27
34
|
if build.building?
|
28
|
-
"
|
35
|
+
"Build started <span class='relatize'>#{build.started_at}</span>…"
|
29
36
|
elsif build.completed?
|
30
37
|
"Built in <span>#{build.duration}</span> seconds"
|
31
38
|
end
|
data/lib/janky/views/layout.rb
CHANGED
data/test/janky_test.rb
CHANGED
@@ -8,8 +8,8 @@ class JankyTest < Test::Unit::TestCase
|
|
8
8
|
|
9
9
|
DatabaseCleaner.clean_with(:truncation)
|
10
10
|
|
11
|
-
Janky::
|
12
|
-
Janky::
|
11
|
+
Janky::ChatService.rooms = {1 => "enterprise", 2 => "builds"}
|
12
|
+
Janky::ChatService.default_room_name = "builds"
|
13
13
|
|
14
14
|
hubot_setup("github/github")
|
15
15
|
end
|
@@ -268,4 +268,16 @@ class JankyTest < Test::Unit::TestCase
|
|
268
268
|
assert hubot_build("janky", "master").not_found?
|
269
269
|
assert hubot_build("github", "master").not_found?
|
270
270
|
end
|
271
|
+
|
272
|
+
test "github owner is parsed correctly" do
|
273
|
+
repo = Janky::Repository.setup("github/janky")
|
274
|
+
assert_equal "github", repo.github_owner
|
275
|
+
assert_equal "janky", repo.github_name
|
276
|
+
end
|
277
|
+
|
278
|
+
test "owner with a dash is parsed correctly" do
|
279
|
+
repo = Janky::Repository.setup("digital-science/central-ftp-manage")
|
280
|
+
assert_equal "digital-science", repo.github_owner
|
281
|
+
assert_equal "central-ftp-manage", repo.github_name
|
282
|
+
end
|
271
283
|
end
|
data/test/test_helper.rb
CHANGED
@@ -17,9 +17,10 @@ class Test::Unit::TestCase
|
|
17
17
|
"JANKY_GITHUB_HOOK_SECRET" => "secret",
|
18
18
|
"JANKY_HUBOT_USER" => "hubot",
|
19
19
|
"JANKY_HUBOT_PASSWORD" => "password",
|
20
|
-
"
|
21
|
-
"
|
22
|
-
"
|
20
|
+
"JANKY_CHAT_CAMPFIRE_ACCOUNT" => "github",
|
21
|
+
"JANKY_CHAT_CAMPFIRE_TOKEN" => "token",
|
22
|
+
"JANKY_CHAT_DEFAULT_ROOM" => "Builds",
|
23
|
+
"JANKY_CHAT" => "campfire"
|
23
24
|
}
|
24
25
|
end
|
25
26
|
|
@@ -71,7 +72,7 @@ class Test::Unit::TestCase
|
|
71
72
|
|
72
73
|
def hubot_build(repo, branch, room_name = nil)
|
73
74
|
params =
|
74
|
-
if room_id = Janky::
|
75
|
+
if room_id = Janky::ChatService.room_id(room_name)
|
75
76
|
{"room_id" => room_id.to_s}
|
76
77
|
else
|
77
78
|
{}
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: janky
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 41
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 9
|
9
|
-
-
|
10
|
-
version: 0.9.
|
9
|
+
- 9
|
10
|
+
version: 0.9.9
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- GitHub, Inc.
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
18
|
+
date: 2012-02-10 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -88,11 +88,12 @@ dependencies:
|
|
88
88
|
requirements:
|
89
89
|
- - ~>
|
90
90
|
- !ruby/object:Gem::Version
|
91
|
-
hash:
|
91
|
+
hash: 19
|
92
92
|
segments:
|
93
|
+
- 1
|
94
|
+
- 1
|
93
95
|
- 0
|
94
|
-
|
95
|
-
version: "0.8"
|
96
|
+
version: 1.1.0
|
96
97
|
type: :runtime
|
97
98
|
version_requirements: *id005
|
98
99
|
- !ruby/object:Gem::Dependency
|
@@ -230,8 +231,10 @@ files:
|
|
230
231
|
- lib/janky/builder/payload.rb
|
231
232
|
- lib/janky/builder/receiver.rb
|
232
233
|
- lib/janky/builder/runner.rb
|
233
|
-
- lib/janky/
|
234
|
-
- lib/janky/campfire
|
234
|
+
- lib/janky/chat_service.rb
|
235
|
+
- lib/janky/chat_service/campfire.rb
|
236
|
+
- lib/janky/chat_service/hipchat.rb
|
237
|
+
- lib/janky/chat_service/mock.rb
|
235
238
|
- lib/janky/commit.rb
|
236
239
|
- lib/janky/database/migrate/1312115512_init.rb
|
237
240
|
- lib/janky/database/migrate/1312117285_non_unique_repo_uri.rb
|
@@ -256,7 +259,7 @@ files:
|
|
256
259
|
- lib/janky/hubot.rb
|
257
260
|
- lib/janky/job_creator.rb
|
258
261
|
- lib/janky/notifier.rb
|
259
|
-
- lib/janky/notifier/
|
262
|
+
- lib/janky/notifier/chat_service.rb
|
260
263
|
- lib/janky/notifier/mock.rb
|
261
264
|
- lib/janky/notifier/multi.rb
|
262
265
|
- lib/janky/public/css/base.css
|