janky 0.9.12 → 0.9.13

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES CHANGED
@@ -1,3 +1,21 @@
1
+ = 0.9.13 / 2012-06-24
2
+
3
+ * Pull down the branch HEAD commit from the GitHub API for manual builds.
4
+ This ensures that the latest code is built even when the webhook fails.
5
+ [Jake Douglas, Simon Rozet]
6
+
7
+ * Record the name of the user that triggered a build in the database. This
8
+ is mostly useful for applications consuming the Janky API and isn't exposed
9
+ anywhere in the UI. [Jake Douglas, Simon Rozet]
10
+
11
+ * Use full SHA1s when interacting with other systems to avoid ambiguous
12
+ commits. [Jake Douglas]
13
+
14
+ * Deprecate support for Ruby < 1.9.3. [Simon Rozet]
15
+
16
+ * Add missing database migrations that were wrongfully omitted from the
17
+ 0.9.12 gem package. [Simon Rozet]
18
+
1
19
  = 0.9.12 / 2012-06-23
2
20
 
3
21
  * Upgrade OAuth authentication gem to use GitHub API v3. [Corey Donohoe]
data/README.md CHANGED
@@ -103,6 +103,8 @@ After configuring the app (see below), create the database:
103
103
 
104
104
  $ heroku run rake db:migrate
105
105
 
106
+ **NOTE:** Ruby version 1.9.3 is required to run Janky.
107
+
106
108
  [gist]: https://gist.github.com/1497335
107
109
 
108
110
  ### Configuring
@@ -166,6 +168,7 @@ Required settings:
166
168
  admin token, not a notification token.)
167
169
  * `JANKY_CHAT_HIPCHAT_FROM`: name that messages will appear be sent from.
168
170
  Defaults to `CI`.
171
+ * `JANKY_HUBOT_USER` should be XMPP/Jabber username in format xxxxx_xxxxxx rather than email
169
172
 
170
173
  Installation:
171
174
 
@@ -175,6 +178,7 @@ Installation:
175
178
  * `bundle`
176
179
  * `git commit -am "install hipchat"`
177
180
 
181
+
178
182
  ### Authentication
179
183
 
180
184
  To restrict access to members of a GitHub organization, [register a new
@@ -192,7 +196,7 @@ a few extra settings:
192
196
 
193
197
  Install the [janky script](http://git.io/hubot-janky) in your Hubot
194
198
  then set the `HUBOT_JANKY_URL` environment variable. Example:
195
- `http://user:secret@janky.example.com/_hubot/`, with user and password
199
+ `http://user:password@janky.example.com/_hubot/`, with user and password
196
200
  replaced by `JANKY_HUBOT_USER` and `JANKY_HUBOT_PASSWORD` respectively.
197
201
 
198
202
  ### Custom Build Configuration
data/janky.gemspec CHANGED
@@ -4,7 +4,7 @@ Gem::Specification.new "janky", Janky::VERSION do |s|
4
4
  s.description = "Janky is a Continuous Integration server"
5
5
  s.summary = "Continuous Integration server built on top of Jenkins and " \
6
6
  "designed for GitHub and Hubot"
7
- s.authors = ["GitHub, Inc."]
7
+ s.authors = ["Simon Rozet"]
8
8
  s.homepage = "https://github.com/github/janky"
9
9
  s.has_rdoc = false
10
10
 
@@ -60,6 +60,10 @@ lib/janky/database/migrate/1317384618_add_repo_hook_url.rb
60
60
  lib/janky/database/migrate/1317384619_add_build_room_id.rb
61
61
  lib/janky/database/migrate/1317384629_drop_default_room_id.rb
62
62
  lib/janky/database/migrate/1317384649_github_team_id.rb
63
+ lib/janky/database/migrate/1317384650_add_build_indexes.rb
64
+ lib/janky/database/migrate/1317384651_add_more_build_indexes.rb
65
+ lib/janky/database/migrate/1317384652_change_commit_message_to_text.rb
66
+ lib/janky/database/migrate/1317384653_add_build_pusher.rb
63
67
  lib/janky/database/schema.rb
64
68
  lib/janky/database/seed.dump.gz
65
69
  lib/janky/exception.rb
data/lib/janky.rb CHANGED
@@ -1,3 +1,8 @@
1
+ if RUBY_VERSION < "1.9.3"
2
+ warn "Support for Ruby versions lesser than 1.9.3 is deprecated and will be " \
3
+ "removed in Janky 1.0."
4
+ end
5
+
1
6
  require "net/http"
2
7
  require "digest/md5"
3
8
 
data/lib/janky/branch.rb CHANGED
@@ -49,13 +49,14 @@ module Janky
49
49
  # Create a build for the given commit.
50
50
  #
51
51
  # commit - the Janky::Commit instance to build.
52
+ # user - The login of the GitHub user who pushed.
52
53
  # compare - optional String GitHub Compare View URL. Defaults to the
53
54
  # commit last build, if any.
54
55
  # room_id - optional Fixnum Campfire room ID. Defaults to the room set on
55
56
  # the repository.
56
57
  #
57
58
  # Returns the newly created Janky::Build.
58
- def build_for(commit, room_id = nil, compare = nil)
59
+ def build_for(commit, user, room_id = nil, compare = nil)
59
60
  if compare.nil? && build = commit.last_build
60
61
  compare = build.compare
61
62
  end
@@ -64,13 +65,50 @@ module Janky
64
65
  room_id = repository.room_id
65
66
  end
66
67
 
67
- builds.create(
68
+ builds.create!(
68
69
  :compare => compare,
70
+ :user => user,
69
71
  :commit => commit,
70
72
  :room_id => room_id
71
73
  )
72
74
  end
73
75
 
76
+ # Fetch the HEAD commit of this branch using the GitHub API and create a
77
+ # build and commit record.
78
+ #
79
+ # room_id - See build_for documentation. This is passed as is to the
80
+ # build_for method.
81
+ # user - Ditto.
82
+ #
83
+ # Returns the newly created Janky::Build.
84
+ def head_build_for(room_id, user)
85
+ sha_to_build = GitHub.branch_head_sha(repository.nwo, name)
86
+ return if !sha_to_build
87
+
88
+ commit_data = GitHub.commit(repository.nwo, sha_to_build)
89
+ commit_message = commit_data["commit"]["message"]
90
+ commit_url = repository.github_url("commit/#{sha_to_build}")
91
+ author_data = commit_data["commit"]["author"]
92
+ commit_author =
93
+ if email = author_data["email"]
94
+ "#{author_data["name"]} <#{email}>"
95
+ else
96
+ author_data["name"]
97
+ end
98
+
99
+ commit = repository.commit_for({
100
+ :repository => repository,
101
+ :sha1 => sha_to_build,
102
+ :author => commit_author,
103
+ :message => commit_message,
104
+ :url => commit_url,
105
+ })
106
+
107
+ current_sha = current_build ? current_build.sha1 : "#{sha_to_build}^"
108
+ compare_url = repository.github_url("compare/#{current_sha}...#{commit.sha1}")
109
+ build_for(commit, user, room_id, compare_url)
110
+ end
111
+
74
112
  # The current build, e.g. the most recent one.
75
113
  #
76
114
  # Returns a Build.
data/lib/janky/build.rb CHANGED
@@ -43,7 +43,7 @@ module Janky
43
43
  #
44
44
  # Returns an Array of Builds.
45
45
  def self.started
46
- where("started_at IS NOT NULL").order("started_at DESC")
46
+ where("started_at IS NOT NULL").order("started_at DESC, id DESC")
47
47
  end
48
48
 
49
49
  # Find all completed builds, most recent first.
@@ -213,7 +213,11 @@ module Janky
213
213
  end
214
214
 
215
215
  def sha1
216
- commit.short_sha
216
+ commit.sha1
217
+ end
218
+
219
+ def short_sha1
220
+ sha1[0,7]
217
221
  end
218
222
 
219
223
  def commit_url
@@ -1,10 +1,10 @@
1
1
  module Janky
2
2
  class BuildRequest
3
- def self.handle(repo_uri, branch_name, commit, compare, room_id)
3
+ def self.handle(repo_uri, branch_name, pusher, commit, compare, room_id)
4
4
  repos = Repository.find_all_by_uri(repo_uri)
5
5
  repos.each do |repo|
6
6
  begin
7
- new(repo, branch_name, commit, compare, room_id).handle
7
+ new(repo, branch_name, pusher, commit, compare, room_id).handle
8
8
  rescue Janky::Error => boom
9
9
  Exception.report(boom, :repo => repo.name)
10
10
  end
@@ -13,9 +13,10 @@ module Janky
13
13
  repos.size
14
14
  end
15
15
 
16
- def initialize(repo, branch_name, commit, compare, room_id)
16
+ def initialize(repo, branch_name, pusher, commit, compare, room_id)
17
17
  @repo = repo
18
18
  @branch_name = branch_name
19
+ @pusher = pusher
19
20
  @commit = commit
20
21
  @compare = compare
21
22
  @room_id = room_id
@@ -23,7 +24,7 @@ module Janky
23
24
 
24
25
  def handle
25
26
  current_build = commit.last_build
26
- build = branch.build_for(commit, @room_id, @compare)
27
+ build = branch.build_for(commit, @pusher, @room_id, @compare)
27
28
 
28
29
  if !current_build || (current_build && current_build.red?)
29
30
  if @repo.enabled?
@@ -1,14 +1,18 @@
1
1
  module Janky
2
2
  module Builder
3
3
  class Payload
4
- def self.parse(json)
4
+ def self.parse(json, base_url)
5
5
  parsed = Yajl.load(json)
6
6
  build = parsed["build"]
7
7
 
8
+ full_url = build["full_url"]
9
+ path = build["url"]
10
+ build_url = full_url || "#{base_url}#{path}"
11
+
8
12
  new(
9
13
  build["phase"],
10
14
  build["parameters"]["JANKY_ID"],
11
- build["full_url"],
15
+ build_url,
12
16
  build["status"]
13
17
  )
14
18
  end
@@ -3,7 +3,8 @@ module Janky
3
3
  class Receiver
4
4
  def self.call(env)
5
5
  request = Rack::Request.new(env)
6
- payload = Payload.parse(request.body)
6
+ default_base_url = Builder[:default].url
7
+ payload = Payload.parse(request.body, default_base_url)
7
8
 
8
9
  if payload.started?
9
10
  Build.start(payload.id, payload.url)
data/lib/janky/commit.rb CHANGED
@@ -6,9 +6,5 @@ module Janky
6
6
  def last_build
7
7
  builds.last
8
8
  end
9
-
10
- def short_sha
11
- sha1[0..7]
12
- end
13
9
  end
14
10
  end
@@ -0,0 +1,11 @@
1
+ class AddBuildIndexes < ActiveRecord::Migration
2
+ def self.up
3
+ add_index :builds, :commit_id
4
+ add_index :builds, :branch_id
5
+ end
6
+
7
+ def self.down
8
+ remove_index :builds, :commit_id
9
+ remove_index :builds, :branch_id
10
+ end
11
+ end
@@ -0,0 +1,13 @@
1
+ class AddMoreBuildIndexes < ActiveRecord::Migration
2
+ def self.up
3
+ add_index :builds, :started_at
4
+ add_index :builds, :completed_at
5
+ add_index :builds, :green
6
+ end
7
+
8
+ def self.down
9
+ remove_index :builds, :started_at
10
+ remove_index :builds, :completed_at
11
+ remove_index :builds, :green
12
+ end
13
+ end
@@ -0,0 +1,5 @@
1
+ class ChangeCommitMessageToText < ActiveRecord::Migration
2
+ def change
3
+ change_column :commits, :message, :text, :null => false
4
+ end
5
+ end
@@ -0,0 +1,9 @@
1
+ class AddBuildPusher < ActiveRecord::Migration
2
+ def self.up
3
+ add_column :builds, :user, :string, :null => true
4
+ end
5
+
6
+ def self.down
7
+ remove_column :builds, :user
8
+ end
9
+ end
@@ -34,6 +34,7 @@ ActiveRecord::Schema.define(:version => 1317384652) do
34
34
  t.datetime "updated_at"
35
35
  t.text "output"
36
36
  t.integer "room_id"
37
+ t.string "user"
37
38
  end
38
39
 
39
40
  add_index "builds", ["branch_id"], :name => "index_builds_on_branch_id"
data/lib/janky/github.rb CHANGED
@@ -23,6 +23,14 @@ module Janky
23
23
  attr_reader :secret, :git_host
24
24
  end
25
25
 
26
+ # URL of the GitHub website.
27
+ #
28
+ # Retuns the URL as a String. Example: https://github.com
29
+ def self.github_url
30
+ api_uri = URI.parse(@api_url)
31
+ "#{api_uri.scheme}://#{@git_host}"
32
+ end
33
+
26
34
  # Rack app that handles Post-Receive hook requests from GitHub.
27
35
  #
28
36
  # Returns a GitHub::Receiver.
@@ -52,6 +60,54 @@ module Janky
52
60
  end
53
61
  end
54
62
 
63
+ # Fetch the SHA1 of the given branch HEAD.
64
+ #
65
+ # nwo - qualified "owner/repo" name.
66
+ # branch - Name of the branch as a String.
67
+ #
68
+ # Returns the SHA1 as a String or nil when the branch doesn't exists.
69
+ def self.branch_head_sha(nwo, branch)
70
+ response = api.branches(nwo)
71
+
72
+ if response.code != "200"
73
+ Exception.push_http_response(response)
74
+ raise Error, "Failed to get branches"
75
+ end
76
+
77
+ branches = Yajl.load(response.body)
78
+ branch = branches.detect { |b| b["name"] == branch }
79
+ branch && branch["commit"]["sha"]
80
+ end
81
+
82
+ # Fetch commit details for the given SHA1.
83
+ #
84
+ # nwo - qualified "owner/repo" name.
85
+ # sha - SHA1 of the commit as a String.
86
+ #
87
+ # Example
88
+ #
89
+ # commit("github/janky", "35fff49dc18376845dd37e785c1ea88c6133f928")
90
+ # => { "commit" => {
91
+ # "author" => {
92
+ # "name" => "Simon Rozet",
93
+ # "email" => "sr@github.com",
94
+ # },
95
+ # "message" => "document and clean up Branch#build_for_head",
96
+ # }
97
+ # }
98
+ #
99
+ # Returns the commit Hash.
100
+ def self.commit(nwo, sha)
101
+ response = api.commit(nwo, sha)
102
+
103
+ if response.code != "200"
104
+ Exception.push_http_response(response)
105
+ raise Error, "Failed to get commit"
106
+ end
107
+
108
+ Yajl.load(response.body)
109
+ end
110
+
55
111
  # Create a Post-Receive hook for the given repository.
56
112
  # http://developer.github.com/v3/repos/hooks/#create-a-hook
57
113
  #
@@ -122,5 +178,10 @@ module Janky
122
178
  def self.repo_make_unauthorized(nwo)
123
179
  api.make_unauthorized(nwo)
124
180
  end
181
+
182
+ # Set the SHA of the named branch for the given repo. Mock only.
183
+ def self.set_branch_head(nwo, branch, sha)
184
+ api.set_branch_head(nwo, branch, sha)
185
+ end
125
186
  end
126
187
  end
@@ -40,6 +40,22 @@ module Janky
40
40
  http.request(request)
41
41
  end
42
42
 
43
+ def branches(nwo)
44
+ path = build_path("repos/#{nwo}/branches")
45
+ request = Net::HTTP::Get.new(path)
46
+ request.basic_auth(@user, @password)
47
+
48
+ http.request(request)
49
+ end
50
+
51
+ def commit(nwo, sha)
52
+ path = build_path("repos/#{nwo}/commits/#{sha}")
53
+ request = Net::HTTP::Get.new(path)
54
+ request.basic_auth(@user, @password)
55
+
56
+ http.request(request)
57
+ end
58
+
43
59
  def build_path(path)
44
60
  if path[0] == ?/
45
61
  URI.join(@url, path[1..-1]).path
@@ -5,6 +5,7 @@ module Janky
5
5
 
6
6
  def initialize(user, password)
7
7
  @repos = {}
8
+ @branch_shas = {}
8
9
  end
9
10
 
10
11
  def make_private(nwo)
@@ -19,6 +20,10 @@ module Janky
19
20
  @repos[nwo] = :unauthorized
20
21
  end
21
22
 
23
+ def set_branch_head(nwo, branch, sha)
24
+ @branch_shas[[nwo, branch]] = sha
25
+ end
26
+
22
27
  def create(nwo, secret, url)
23
28
  data = {"url" => "https://api.github.com/hooks/#{Time.now.to_f}"}
24
29
  Response.new("201", Yajl.dump(data))
@@ -42,6 +47,37 @@ module Janky
42
47
  Response.new("200", Yajl.dump(repo))
43
48
  end
44
49
  end
50
+
51
+ def branches(nwo)
52
+ data = []
53
+
54
+ @branch_shas.each do |(name_with_owner, branch), sha|
55
+ if nwo == name_with_owner
56
+ data << {
57
+ "name" => branch,
58
+ "commit" => {
59
+ "sha" => sha
60
+ }
61
+ }
62
+ end
63
+ end
64
+
65
+ Response.new("200", Yajl.dump(data))
66
+ end
67
+
68
+ def commit(nwo, sha)
69
+ data = {
70
+ "commit" => {
71
+ "author" => {
72
+ "name" => "Test Author",
73
+ "email" => "test@github.com"
74
+ },
75
+ "message" => "Test Message"
76
+ }
77
+ }
78
+
79
+ Response.new("200", Yajl.dump(data))
80
+ end
45
81
  end
46
82
  end
47
83
  end
@@ -3,18 +3,21 @@ module Janky
3
3
  class Payload
4
4
  def self.parse(json)
5
5
  parsed = PayloadParser.new(json)
6
- new(parsed.uri, parsed.branch, parsed.head, parsed.commits, parsed.compare)
6
+ new(parsed.uri, parsed.branch, parsed.head, parsed.pusher,
7
+ parsed.commits,
8
+ parsed.compare)
7
9
  end
8
10
 
9
- def initialize(uri, branch, head, commits, compare)
11
+ def initialize(uri, branch, head, pusher, commits, compare)
10
12
  @uri = uri
11
13
  @branch = branch
12
14
  @head = head
15
+ @pusher = pusher
13
16
  @commits = commits
14
17
  @compare = compare
15
18
  end
16
19
 
17
- attr_reader :uri, :branch, :head, :commits, :compare
20
+ attr_reader :uri, :branch, :head, :pusher, :commits, :compare
18
21
 
19
22
  def head_commit
20
23
  @commits.detect do |commit|
@@ -25,6 +28,7 @@ module Janky
25
28
  def to_json
26
29
  { :after => @head,
27
30
  :ref => "refs/heads/#{@branch}",
31
+ :pusher => {:name => @pusher},
28
32
  :uri => @uri,
29
33
  :commits => @commits,
30
34
  :compare => @compare }.to_json
@@ -5,6 +5,10 @@ module Janky
5
5
  @payload = Yajl.load(json)
6
6
  end
7
7
 
8
+ def pusher
9
+ @payload["pusher"]["name"]
10
+ end
11
+
8
12
  def head
9
13
  @payload["after"]
10
14
  end
@@ -32,6 +32,7 @@ module Janky
32
32
  result = BuildRequest.handle(
33
33
  payload.uri,
34
34
  payload.branch,
35
+ payload.pusher,
35
36
  payload.head_commit,
36
37
  payload.compare,
37
38
  @request.POST["room"]
data/lib/janky/hubot.rb CHANGED
@@ -34,13 +34,12 @@ module Janky
34
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
- build = branch.current_build
38
-
39
37
  room_id = (params["room_id"] && Integer(params["room_id"]) rescue nil)
38
+ user = params["user"]
39
+ build = branch.head_build_for(room_id, user)
40
40
 
41
41
  if build
42
- build.rerun(room_id)
43
-
42
+ build.run
44
43
  [201, "Going ham on #{build.repo_name}/#{build.branch_name}"]
45
44
  else
46
45
  [404, "Unknown branch #{branch_name.inspect}. Push again"]
@@ -91,6 +90,7 @@ module Janky
91
90
  { :sha1 => build.sha1,
92
91
  :repo => build.repo_name,
93
92
  :branch => build.branch_name,
93
+ :user => build.user,
94
94
  :green => build.green?,
95
95
  :building => branch.building?,
96
96
  :number => build.number,
@@ -7,7 +7,7 @@ module Janky
7
7
 
8
8
  message = "Build #%s (%s) of %s/%s %s (%ss) %s" % [
9
9
  build.number,
10
- build.sha1,
10
+ build.short_sha1,
11
11
  build.repo_name,
12
12
  build.branch_name,
13
13
  status,
@@ -96,6 +96,27 @@ module Janky
96
96
  uri[/.*[\/:]([a-zA-Z0-9\-_]+)\/([a-zA-Z0-9\-_]+)/] && $2
97
97
  end
98
98
 
99
+ # Fully qualified GitHub name for this repository.
100
+ #
101
+ # Returns the name as a String. Example: github/janky.
102
+ def nwo
103
+ "#{github_owner}/#{github_name}"
104
+ end
105
+
106
+ # Append the given path to the GitHub URL of this repository.
107
+ #
108
+ # path - String path. No slash necessary at the front.
109
+ #
110
+ # Examples
111
+ #
112
+ # github_url("issues")
113
+ # => "https://github.com/github/janky/issues"
114
+ #
115
+ # Returns the URL as a String.
116
+ def github_url(path)
117
+ "#{GitHub.github_url}/#{nwo}/#{path}"
118
+ end
119
+
99
120
  # Name of the Campfire room receiving build notifications.
100
121
  #
101
122
  # Returns the name as a String.
data/lib/janky/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Janky
2
- VERSION = "0.9.12"
2
+ VERSION = "0.9.13"
3
3
  end
@@ -22,7 +22,7 @@ module Janky
22
22
  end
23
23
 
24
24
  def commit_short_sha
25
- @build.sha1
25
+ @build.short_sha1
26
26
  end
27
27
 
28
28
  def output
@@ -14,7 +14,7 @@ module Janky
14
14
  :status => css_status_for(build),
15
15
  :last_built_text => last_built_text_for(build),
16
16
  :message => build.commit_message,
17
- :sha1 => build.sha1,
17
+ :sha1 => build.short_sha1,
18
18
  :author => build.commit_author.split("<").first
19
19
  }
20
20
  end
data/test/janky_test.rb CHANGED
@@ -220,6 +220,28 @@ class JankyTest < Test::Unit::TestCase
220
220
  assert hubot_status.ok?
221
221
  end
222
222
 
223
+ test "build user" do
224
+ gh_post_receive("github", "master", "HEAD", "the dude")
225
+ Janky::Builder.start!
226
+ Janky::Builder.complete!
227
+
228
+ response = hubot_status("github", "master")
229
+ data = Yajl.load(response.body)
230
+ assert_equal 1, data.size
231
+ build = data[0]
232
+ assert_equal "the dude", build["user"]
233
+
234
+ hubot_build("github", "master", nil, "the boyscout")
235
+ Janky::Builder.start!
236
+ Janky::Builder.complete!
237
+
238
+ response = hubot_status("github", "master")
239
+ data = Yajl.load(response.body)
240
+ assert_equal 2, data.size
241
+ build = data[0]
242
+ assert_equal "the boyscout", build["user"]
243
+ end
244
+
223
245
  test "hubot status repo" do
224
246
  gh_post_receive("github")
225
247
  Janky::Builder.start!
@@ -241,6 +263,25 @@ class JankyTest < Test::Unit::TestCase
241
263
  assert hubot_build("github", "rails3").not_found?
242
264
  end
243
265
 
266
+ test "getting latest commit" do
267
+ gh_post_receive("github", "master")
268
+ Janky::Builder.start!
269
+ Janky::Builder.complete!
270
+
271
+ assert_not_equal "deadbeef", hubot_latest_build_sha("github", "master")
272
+
273
+ Janky::GitHub.set_branch_head("github/github", "master", "deadbeef")
274
+ hubot_build("github", "master")
275
+ Janky::Builder.start!
276
+ Janky::Builder.complete!
277
+
278
+ assert_equal "deadbeef", hubot_latest_build_sha("github", "master")
279
+ assert_equal "deadbeef", Janky::Build.last.sha1
280
+ assert_equal "Test Author <test@github.com>", Janky::Build.last.commit_author
281
+ assert_equal "Test Message", Janky::Build.last.commit_message
282
+ assert_equal "https://github.com/github/github/commit/deadbeef", Janky::Build.last.commit_url
283
+ end
284
+
244
285
  test "hubot rooms" do
245
286
  response = hubot_request("GET", "/_hubot/rooms")
246
287
  rooms = Yajl.load(response.body)
data/test/test_helper.rb CHANGED
@@ -44,13 +44,14 @@ class Test::Unit::TestCase
44
44
  )
45
45
  end
46
46
 
47
- def gh_payload(repo, branch, commits)
47
+ def gh_payload(repo, branch, pusher, commits)
48
48
  head = commits.first
49
49
 
50
50
  Janky::GitHub::Payload.new(
51
51
  repo.uri,
52
52
  branch,
53
53
  head.sha1,
54
+ pusher,
54
55
  commits,
55
56
  "http://github/compare/#{branch}...master"
56
57
  )
@@ -60,11 +61,16 @@ class Test::Unit::TestCase
60
61
  Rack::MockRequest.new(Janky.app).get(path)
61
62
  end
62
63
 
63
- def gh_post_receive(repo_name, branch = "master", commit = "HEAD")
64
+ def gh_post_receive(repo_name, branch = "master", commit = "HEAD",
65
+ pusher = "user")
66
+
64
67
  repo = Janky::Repository.find_by_name!(repo_name)
65
- payload = gh_payload(repo, branch, [gh_commit(commit)])
68
+ payload = gh_payload(repo, branch, pusher, [gh_commit(commit)])
66
69
  digest = OpenSSL::Digest::Digest.new("sha1")
67
- sig = OpenSSL::HMAC.hexdigest(digest, Janky::GitHub.secret, payload.to_json)
70
+ sig = OpenSSL::HMAC.hexdigest(digest, Janky::GitHub.secret,
71
+ payload.to_json)
72
+
73
+ Janky::GitHub.set_branch_head(repo.nwo, branch, commit)
68
74
 
69
75
  Rack::MockRequest.new(Janky.app).post("/_github",
70
76
  :input => payload.to_json,
@@ -80,7 +86,7 @@ class Test::Unit::TestCase
80
86
  })
81
87
  end
82
88
 
83
- def hubot_build(repo, branch, room_name = nil)
89
+ def hubot_build(repo, branch, room_name = nil, user = nil)
84
90
  params =
85
91
  if room_id = Janky::ChatService.room_id(room_name)
86
92
  {"room_id" => room_id.to_s}
@@ -88,6 +94,10 @@ class Test::Unit::TestCase
88
94
  {}
89
95
  end
90
96
 
97
+ if user
98
+ params["user"] = user
99
+ end
100
+
91
101
  hubot_request("POST", "/_hubot/#{repo}/#{branch}", :params => params)
92
102
  end
93
103
 
@@ -99,6 +109,11 @@ class Test::Unit::TestCase
99
109
  end
100
110
  end
101
111
 
112
+ def hubot_latest_build_sha(repo, branch)
113
+ response = hubot_status(repo, branch)
114
+ Yajl.load(response.body).first["sha1"]
115
+ end
116
+
102
117
  def hubot_request(method, path, opts={})
103
118
  auth = ["#{Janky::Hubot.username}:#{Janky::Hubot.password}"].pack("m*")
104
119
  env = {"HTTP_AUTHORIZATION" => "Basic #{auth}"}
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: janky
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.12
4
+ version: 0.9.13
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
8
- - GitHub, Inc.
8
+ - Simon Rozet
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-23 00:00:00.000000000 Z
12
+ date: 2012-06-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -242,6 +242,10 @@ files:
242
242
  - lib/janky/database/migrate/1317384619_add_build_room_id.rb
243
243
  - lib/janky/database/migrate/1317384629_drop_default_room_id.rb
244
244
  - lib/janky/database/migrate/1317384649_github_team_id.rb
245
+ - lib/janky/database/migrate/1317384650_add_build_indexes.rb
246
+ - lib/janky/database/migrate/1317384651_add_more_build_indexes.rb
247
+ - lib/janky/database/migrate/1317384652_change_commit_message_to_text.rb
248
+ - lib/janky/database/migrate/1317384653_add_build_pusher.rb
245
249
  - lib/janky/database/schema.rb
246
250
  - lib/janky/database/seed.dump.gz
247
251
  - lib/janky/exception.rb