janky 0.10.2 → 0.11.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: 9d531dd95f17c83f106364fc9bb3b56a83e7c84f
4
- data.tar.gz: ea8e851492074c805a207ec0938a0eff692e9e7e
3
+ metadata.gz: e4e36e0fb610583f88d64b504993cb6c57305e15
4
+ data.tar.gz: 827b6fa7764586c70852a679a4a9fcab23d18601
5
5
  SHA512:
6
- metadata.gz: 1c10a412e74e88045013e915ad1859a481e949a01da50c207d26302fe2651d9d1e748cf9bb81399a0296adde8befcb4e53b062b5f7a5445a00bd52ade2afa60f
7
- data.tar.gz: c8ea975e0f9b6527c80b2b91b796b9ca72d4cc3ee82a7503c302839c6476cb9ee43fb688494a23d453b2f5071574e85a7e73d7f59adc1ba29f63a85f81bd87d4
6
+ metadata.gz: 4546417aef772b7d387ec7808631c16d1869d202569ed316fa93bbf862fd34242492a1e691dbc58b125be088d11b2dc3f1b1d82754308f56afc1d9c7bfec2749
7
+ data.tar.gz: 4ee74b538771d5b05da1f4d10388f996749cd7b6daaaeb136771dd8f66af0e88e0fcd3557736bbbe70920e732e1c0fa19fbaa254b932f8e82ef94d6843043cb9
data/CHANGES CHANGED
@@ -1,3 +1,15 @@
1
+ = 0.11.0 / 2014-11-14
2
+
3
+ * Add support for Slack chat rooms
4
+ * Convert chat room ids from integers to strings
5
+ * Ensure build completion works with new Jenkins versions
6
+ * Allow custom build templates to be provided when setting up projects
7
+ * Mark builds that are queued in Jenkins as pending on GitHub
8
+ * Delete and recreate hooks when setting up repositories
9
+ * Add the ability to delete repos via `/ci delete`
10
+ * Get detailed info about repos via `/ci show`
11
+ * Send updates from Janky as a separate context to GitHub
12
+
1
13
  = 0.10.2 / 2013-10-02
2
14
 
3
15
  * Revert AR deprecation warnings
data/README.md CHANGED
@@ -31,6 +31,10 @@ anything unless it needs to. It takes an optional name argument:
31
31
 
32
32
  hubot ci setup github/janky janky-ruby1.9.2
33
33
 
34
+ It also takes an optional template name argument:
35
+
36
+ hubot ci setup github/janky janky-ruby1.9.2 ruby-build
37
+
34
38
  All branches are built automatically on push. Disable auto build with:
35
39
 
36
40
  hubot ci toggle janky
@@ -106,7 +110,7 @@ After configuring the app (see below), create the database:
106
110
 
107
111
  $ heroku run rake db:migrate
108
112
 
109
- **NOTE:** Ruby version 1.9.3 is required to run Janky.
113
+ **NOTE:** Ruby version 2.0.0+ is required to run Janky.
110
114
 
111
115
  [gist]: https://gist.github.com/1497335
112
116
 
@@ -176,7 +180,9 @@ via the GitHub API:
176
180
  -d '{ "scopes": [ "repo:status" ], "note": "janky" }' \
177
181
  https://api.github.com/authorizations
178
182
 
179
- then set `JANKY_GITHUB_STATUS_TOKEN`.
183
+ then set `JANKY_GITHUB_STATUS_TOKEN`. Optionally, you can also set
184
+ `JANKY_GITHUB_STATUS_CONTEXT` to send a context to the GitHub API by
185
+ default
180
186
 
181
187
  `username` and `password` in the above example should be the same as the
182
188
  values provided for `JANKY_GITHUB_USER` and `JANKY_GITHUB_PASSWORD`
@@ -215,6 +221,36 @@ Installation:
215
221
  * `bundle`
216
222
  * `git commit -am "install hipchat"`
217
223
 
224
+ #### Slack
225
+
226
+ Required settings:
227
+
228
+ * `JANKY_CHAT=slack`
229
+ * `JANKY_CHAT_SLACK_TEAM`: slack team name
230
+ * `JANKY_CHAT_SLACK_TOKEN`: authentication token for the user sending build notifications.
231
+ * `JANKY_CHAT_SLACK_USERNAME`: name that messages will appear be sent from.
232
+ Defaults to `CI`.
233
+ * `JANKY_CHAT_SLACK_ICON_URL`: URL to an image to use as the icon for this message.
234
+
235
+ Installation:
236
+
237
+ * Add `require "janky/chat_service/slack"` to the `config/environment.rb`
238
+ file **before** the `Janky.setup(ENV)` line.
239
+ * `echo 'gem "slack.rb"' >> Gemfile`
240
+ * `bundle`
241
+ * `git commit -am "install slack"`
242
+
243
+ #### Hubot
244
+
245
+ Sends notifications to Hubot via [janky script](http://git.io/hubot-janky).
246
+
247
+ Required settings:
248
+
249
+ * `JANKY_CHAT_HUBOT_URL`: URL to your Hubot instance.
250
+ * `JANKY_CHAT_HUBOT_ROOMS`: List of rooms which can be set via `ci set room`.
251
+ * For IRC: Comma-separated list of channels `"#room, #another-room"`
252
+ * For Campfire/HipChat: List with room id and name `"34343:room, 23223:another-room"`
253
+
218
254
  ### Authentication
219
255
 
220
256
  To restrict access to members of a GitHub organization, [register a new
@@ -247,8 +283,10 @@ For more control you can add a `script/cibuild` at the root of your
247
283
  repository for Jenkins to execute instead.
248
284
 
249
285
  For total control, whole Jenkins' `config.xml` files can be associated
250
- with Janky builds. Given a build called `windows`, Janky will try
251
- `config/jobs/windows.xml.erb` before falling back to the default
286
+ with Janky builds. Given a build called `windows` and a template name
287
+ of `psake`, Janky will try `config/jobs/psake.xml.erb` to use a template,
288
+ `config/jobs/windows.xml.erb` to try the job name if the template does
289
+ not exit, before finally falling back to the default
252
290
  configuration, `config/jobs/default.xml.erb`. After updating or adding
253
291
  a custom config, run `hubot ci setup` again to update the Jenkins
254
292
  server.
@@ -294,8 +332,13 @@ send a Pull Request. Note that any changes to behavior without tests will
294
332
  be rejected. If you are adding significant new features, please add both
295
333
  tests and documentation.
296
334
 
335
+ Maintainers
336
+ -----------
337
+
338
+ * [@mattr-](https://github.com/mattr-)
339
+
297
340
  Copying
298
341
  -------
299
342
 
300
- Copyright © 2011-2013, GitHub, Inc. See the `COPYING` file for license
343
+ Copyright © 2011-2014, GitHub, Inc. See the `COPYING` file for license
301
344
  rights and limitations (MIT).
@@ -16,7 +16,7 @@ https://github.com/github/janky/commit/0fc6214e3a75cc138aed46a2493980440e848aa3#
16
16
  EOL
17
17
 
18
18
  # runtime
19
- s.add_dependency "rake", "~>0.9.2"
19
+ s.add_dependency "rake", "~>10.0"
20
20
  s.add_dependency "sinatra", "~>1.3"
21
21
  s.add_dependency "sinatra_auth_github", "~>1.0.0"
22
22
  s.add_dependency "mustache", "~>0.11"
@@ -57,6 +57,7 @@ lib/janky/builder/runner.rb
57
57
  lib/janky/chat_service.rb
58
58
  lib/janky/chat_service/campfire.rb
59
59
  lib/janky/chat_service/hipchat.rb
60
+ lib/janky/chat_service/slack.rb
60
61
  lib/janky/chat_service/mock.rb
61
62
  lib/janky/commit.rb
62
63
  lib/janky/database/migrate/1312115512_init.rb
@@ -73,6 +74,9 @@ lib/janky/database/migrate/1317384651_add_more_build_indexes.rb
73
74
  lib/janky/database/migrate/1317384652_change_commit_message_to_text.rb
74
75
  lib/janky/database/migrate/1317384653_add_build_pusher.rb
75
76
  lib/janky/database/migrate/1317384654_add_build_queued_at.rb
77
+ lib/janky/database/migrate/1317384655_add_template.rb
78
+ lib/janky/database/migrate/1398262033_add_context.rb
79
+ lib/janky/database/migrate/1400144784_change_room_id_to_string.rb
76
80
  lib/janky/database/schema.rb
77
81
  lib/janky/database/seed.dump.gz
78
82
  lib/janky/exception.rb
@@ -88,6 +92,7 @@ lib/janky/hubot.rb
88
92
  lib/janky/job_creator.rb
89
93
  lib/janky/notifier.rb
90
94
  lib/janky/notifier/chat_service.rb
95
+ lib/janky/notifier/failure_service.rb
91
96
  lib/janky/notifier/github_status.rb
92
97
  lib/janky/notifier/mock.rb
93
98
  lib/janky/notifier/multi.rb
@@ -44,6 +44,7 @@ require "janky/chat_service/mock"
44
44
  require "janky/exception"
45
45
  require "janky/notifier"
46
46
  require "janky/notifier/chat_service"
47
+ require "janky/notifier/failure_service"
47
48
  require "janky/notifier/mock"
48
49
  require "janky/notifier/multi"
49
50
  require "janky/notifier/github_status"
@@ -109,7 +110,8 @@ module Janky
109
110
  :username => database.user,
110
111
  :password => database.password,
111
112
  :host => database.host,
112
- :port => database.port
113
+ :port => database.port,
114
+ :reconnect => true,
113
115
  }
114
116
  if socket = settings["JANKY_DATABASE_SOCKET"]
115
117
  connection[:socket] = socket
@@ -203,9 +205,11 @@ module Janky
203
205
  ChatService.setup(chat_name, chat_settings, chat_room)
204
206
 
205
207
  if token = settings["JANKY_GITHUB_STATUS_TOKEN"]
208
+ context = settings["JANKY_GITHUB_STATUS_CONTEXT"]
206
209
  Notifier.setup([
207
- Notifier::GithubStatus.new(token, api_url),
208
- Notifier::ChatService
210
+ Notifier::GithubStatus.new(token, api_url, context),
211
+ Notifier::ChatService,
212
+ Notifier::FailureService
209
213
  ])
210
214
  else
211
215
  Notifier.setup(Notifier::ChatService)
@@ -57,7 +57,7 @@ module Janky
57
57
  # user - The login of the GitHub user who pushed.
58
58
  # compare - optional String GitHub Compare View URL. Defaults to the
59
59
  # commit last build, if any.
60
- # room_id - optional Fixnum Campfire room ID. Defaults to the room set on
60
+ # room_id - optional String room ID. Defaults to the room set on
61
61
  # the repository.
62
62
  #
63
63
  # Returns the newly created Janky::Build.
@@ -66,7 +66,8 @@ module Janky
66
66
  compare = build.compare
67
67
  end
68
68
 
69
- if room_id.nil? || room_id.zero?
69
+ room_id = room_id.to_s
70
+ if room_id.empty? || room_id == "0"
70
71
  room_id = repository.room_id
71
72
  end
72
73
 
@@ -90,24 +91,7 @@ module Janky
90
91
  sha_to_build = GitHub.branch_head_sha(repository.nwo, name)
91
92
  return if !sha_to_build
92
93
 
93
- commit_data = GitHub.commit(repository.nwo, sha_to_build)
94
- commit_message = commit_data["commit"]["message"]
95
- commit_url = repository.github_url("commit/#{sha_to_build}")
96
- author_data = commit_data["commit"]["author"]
97
- commit_author =
98
- if email = author_data["email"]
99
- "#{author_data["name"]} <#{email}>"
100
- else
101
- author_data["name"]
102
- end
103
-
104
- commit = repository.commit_for({
105
- :repository => repository,
106
- :sha1 => sha_to_build,
107
- :author => commit_author,
108
- :message => commit_message,
109
- :url => commit_url,
110
- })
94
+ commit = repository.commit_for_sha(sha_to_build)
111
95
 
112
96
  current_sha = current_build ? current_build.sha1 : "#{sha_to_build}^"
113
97
  compare_url = repository.github_url("compare/#{current_sha}...#{commit.sha1}")
@@ -11,7 +11,7 @@ module Janky
11
11
  select(columns)
12
12
  end
13
13
 
14
- scope :building, -> {
14
+ scope :building, lambda {
15
15
  where("started_at IS NOT NULL AND completed_at IS NULL")
16
16
  }
17
17
 
@@ -131,7 +131,7 @@ module Janky
131
131
  # Run a copy of itself. Typically used to force a build in case of
132
132
  # temporary test failure or when auto-build is disabled.
133
133
  #
134
- # new_room_id - optional Campfire room Fixnum ID. Defaults to the room of the
134
+ # new_room_id - optional Campfire room String ID. Defaults to the room of the
135
135
  # build being re-run.
136
136
  #
137
137
  # Returns the build copy.
@@ -214,7 +214,7 @@ module Janky
214
214
  #
215
215
  # Returns the String room name.
216
216
  def room_name
217
- if room_id && room_id > 0
217
+ if room_id && !room_id.empty?
218
218
  ChatService.room_name(room_id)
219
219
  end
220
220
  end
@@ -29,6 +29,7 @@ module Janky
29
29
  if !current_build || (current_build && current_build.red?)
30
30
  if @repo.enabled?
31
31
  build.run
32
+ Notifier.queued(build)
32
33
  end
33
34
  end
34
35
  end
@@ -40,7 +40,7 @@ module Janky
40
40
  end
41
41
 
42
42
  def completed?
43
- @phase == "FINISHED"
43
+ @phase == "FINISHED" || @phase == "FINALIZED"
44
44
  end
45
45
 
46
46
  def green?
@@ -37,7 +37,7 @@ module Janky
37
37
  # Send a message to a Chat room.
38
38
  #
39
39
  # message - The String message.
40
- # room_id - The Integer room ID.
40
+ # room_id - The String room ID.
41
41
  # options - Optional hash passed to the chat adapter.
42
42
  #
43
43
  # Returns nothing.
@@ -58,7 +58,7 @@ module Janky
58
58
 
59
59
  # Get the name of a room given its ID.
60
60
  #
61
- # id - the Fixnum room ID.
61
+ # id - the String room ID.
62
62
  #
63
63
  # Returns the name as a String or nil when not found.
64
64
  def self.room_name(id)
@@ -90,7 +90,7 @@ module Janky
90
90
 
91
91
  # Configure available rooms. Only available in mock mode.
92
92
  #
93
- # value - Hash of room map (Fixnum ID => String name)
93
+ # value - Hash of room map (String ID => String name)
94
94
  #
95
95
  # Returns nothing.
96
96
  def self.rooms=(value)
@@ -0,0 +1,65 @@
1
+ require "slack"
2
+
3
+ module Janky
4
+ module ChatService
5
+ class Slack
6
+ def initialize(settings)
7
+ team = settings["JANKY_CHAT_SLACK_TEAM"]
8
+
9
+ if team.nil? || team.empty?
10
+ raise Error, "JANKY_CHAT_SLACK_TEAM setting is required"
11
+ end
12
+
13
+ token = settings["JANKY_CHAT_SLACK_TOKEN"]
14
+
15
+ if token.nil? || token.empty?
16
+ raise Error, "JANKY_CHAT_SLACK_TOKEN setting is required"
17
+ end
18
+
19
+ username = settings["JANKY_CHAT_SLACK_USERNAME"] || 'CI'
20
+ icon_url = settings["JANKY_CHAT_SLACK_ICON_URL"]
21
+
22
+ @client = ::Slack::Client.new(team: team, token: token, username: username, icon_url: icon_url)
23
+ end
24
+
25
+ def speak(message, room_id, options = {})
26
+ room_name = ChatService.room_name(room_id) || room_id
27
+
28
+ if options[:build].present?
29
+ @client.post_message(nil, room_name, {attachments: attachments(message, options[:build])})
30
+ else
31
+ @client.post_message(message, room_name, options)
32
+ end
33
+ end
34
+
35
+ def rooms
36
+ @rooms ||= @client.channels.map do |channel|
37
+ Room.new(channel['id'], channel['name'])
38
+ end
39
+ end
40
+
41
+ private
42
+
43
+ def attachments(fallback, build)
44
+ status = build.green? ? "was successful" : "failed"
45
+ color = build.green? ? "good" : "danger"
46
+
47
+ message = "Build #%s of %s/%s %s" % [
48
+ build.number,
49
+ build.repo_name,
50
+ build.branch_name,
51
+ status
52
+ ]
53
+
54
+ janky_field = ::Slack::AttachmentField.new("Janky", build.web_url, false)
55
+ commit_field = ::Slack::AttachmentField.new("Commit", "<#{build.commit_url}|#{build.short_sha1}>", true)
56
+ duration_field = ::Slack::AttachmentField.new("Duration", "#{build.duration}s", true)
57
+ fields = [janky_field.to_h, commit_field.to_h, duration_field.to_h]
58
+
59
+ [::Slack::Attachment.new(fallback, message, nil, color, ["text", "title", "fallback"], fields)]
60
+ end
61
+ end
62
+ end
63
+
64
+ register_chat_service "slack", ChatService::Slack
65
+ end
@@ -6,5 +6,22 @@ module Janky
6
6
  def last_build
7
7
  builds.last
8
8
  end
9
+
10
+ def build!(user, room_id = nil, compare = nil)
11
+ compare = repository.github_url("compare/#{sha1}^...#{sha1}")
12
+
13
+ room_id = room_id.to_s
14
+ if room_id.empty? || room_id == "0"
15
+ room_id = repository.room_id
16
+ end
17
+
18
+ builds.create!(
19
+ :compare => compare,
20
+ :user => user,
21
+ :commit => self,
22
+ :room_id => room_id,
23
+ :branch_id => repository.branch_for('master').id
24
+ )
25
+ end
9
26
  end
10
27
  end
@@ -0,0 +1,9 @@
1
+ class AddTemplate < ActiveRecord::Migration
2
+ def self.up
3
+ add_column :repositories, :job_template, :string, :null => true
4
+ end
5
+
6
+ def self.down
7
+ remove_column :repositories, :job_template
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ class AddContext < ActiveRecord::Migration
2
+ def self.up
3
+ add_column :repositories, :context, :string, :null => true
4
+ end
5
+
6
+ def self.down
7
+ remove_column :repositories, :context
8
+ end
9
+ end
@@ -0,0 +1,6 @@
1
+ class ChangeRoomIdToString < ActiveRecord::Migration
2
+ def change
3
+ change_column :repositories, :room_id, :string
4
+ change_column :builds, :room_id, :string
5
+ end
6
+ end
@@ -11,29 +11,29 @@
11
11
  #
12
12
  # It's strongly recommended to check this file into your version control system.
13
13
 
14
- ActiveRecord::Schema.define(:version => 1317384654) do
14
+ ActiveRecord::Schema.define(:version => 1400144784) do
15
15
 
16
16
  create_table "branches", :force => true do |t|
17
17
  t.string "name", :null => false
18
18
  t.integer "repository_id", :null => false
19
- t.datetime "created_at"
20
- t.datetime "updated_at"
19
+ t.datetime "created_at", :null => false
20
+ t.datetime "updated_at", :null => false
21
21
  end
22
22
 
23
23
  add_index "branches", ["name", "repository_id"], :name => "index_branches_on_name_and_repository_id", :unique => true
24
24
 
25
25
  create_table "builds", :force => true do |t|
26
- t.boolean "green", :default => false
26
+ t.boolean "green", :default => false
27
27
  t.string "url"
28
- t.string "compare", :null => false
28
+ t.string "compare", :null => false
29
29
  t.datetime "started_at"
30
30
  t.datetime "completed_at"
31
- t.integer "commit_id", :null => false
32
- t.integer "branch_id", :null => false
33
- t.datetime "created_at"
34
- t.datetime "updated_at"
31
+ t.integer "commit_id", :null => false
32
+ t.integer "branch_id", :null => false
33
+ t.datetime "created_at", :null => false
34
+ t.datetime "updated_at", :null => false
35
35
  t.text "output"
36
- t.integer "room_id"
36
+ t.string "room_id"
37
37
  t.string "user"
38
38
  t.datetime "queued_at"
39
39
  end
@@ -51,8 +51,8 @@ ActiveRecord::Schema.define(:version => 1317384654) do
51
51
  t.string "author", :null => false
52
52
  t.datetime "committed_at"
53
53
  t.integer "repository_id", :null => false
54
- t.datetime "created_at"
55
- t.datetime "updated_at"
54
+ t.datetime "created_at", :null => false
55
+ t.datetime "updated_at", :null => false
56
56
  t.string "url", :null => false
57
57
  end
58
58
 
@@ -61,12 +61,14 @@ ActiveRecord::Schema.define(:version => 1317384654) do
61
61
  create_table "repositories", :force => true do |t|
62
62
  t.string "name", :null => false
63
63
  t.string "uri", :null => false
64
- t.integer "room_id"
65
- t.datetime "created_at"
66
- t.datetime "updated_at"
64
+ t.string "room_id"
65
+ t.datetime "created_at", :null => false
66
+ t.datetime "updated_at", :null => false
67
67
  t.boolean "enabled", :default => true, :null => false
68
68
  t.string "hook_url"
69
69
  t.integer "github_team_id"
70
+ t.string "job_template"
71
+ t.string "context"
70
72
  end
71
73
 
72
74
  add_index "repositories", ["enabled"], :name => "index_repositories_on_enabled"