janky 0.9.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.
- data/CHANGES +3 -0
- data/COPYING +22 -0
- data/Gemfile +2 -0
- data/README.md +211 -0
- data/Rakefile +19 -0
- data/config.ru +3 -0
- data/janky.gemspec +102 -0
- data/lib/janky.rb +224 -0
- data/lib/janky/app.rb +81 -0
- data/lib/janky/branch.rb +112 -0
- data/lib/janky/build.rb +223 -0
- data/lib/janky/build_request.rb +49 -0
- data/lib/janky/builder.rb +108 -0
- data/lib/janky/builder/client.rb +82 -0
- data/lib/janky/builder/http.rb +43 -0
- data/lib/janky/builder/mock.rb +45 -0
- data/lib/janky/builder/payload.rb +63 -0
- data/lib/janky/builder/receiver.rb +20 -0
- data/lib/janky/builder/runner.rb +47 -0
- data/lib/janky/campfire.rb +127 -0
- data/lib/janky/campfire/mock.rb +0 -0
- data/lib/janky/commit.rb +14 -0
- data/lib/janky/database/migrate/1312115512_init.rb +48 -0
- data/lib/janky/database/migrate/1312117285_non_unique_repo_uri.rb +10 -0
- data/lib/janky/database/migrate/1312198807_repo_enabled.rb +11 -0
- data/lib/janky/database/migrate/1313867551_add_build_output_column.rb +9 -0
- data/lib/janky/database/migrate/1313871652_add_commit_url_column.rb +9 -0
- data/lib/janky/database/migrate/1317384618_add_repo_hook_url.rb +9 -0
- data/lib/janky/database/migrate/1317384619_add_build_room_id.rb +9 -0
- data/lib/janky/database/migrate/1317384629_drop_default_room_id.rb +9 -0
- data/lib/janky/database/migrate/1317384649_github_team_id.rb +9 -0
- data/lib/janky/database/schema.rb +68 -0
- data/lib/janky/database/seed.dump.gz +0 -0
- data/lib/janky/exception.rb +62 -0
- data/lib/janky/github.rb +67 -0
- data/lib/janky/github/api.rb +69 -0
- data/lib/janky/github/commit.rb +27 -0
- data/lib/janky/github/mock.rb +47 -0
- data/lib/janky/github/payload.rb +34 -0
- data/lib/janky/github/payload_parser.rb +57 -0
- data/lib/janky/github/receiver.rb +69 -0
- data/lib/janky/helpers.rb +17 -0
- data/lib/janky/hubot.rb +117 -0
- data/lib/janky/job_creator.rb +111 -0
- data/lib/janky/notifier.rb +84 -0
- data/lib/janky/notifier/campfire.rb +21 -0
- data/lib/janky/notifier/mock.rb +55 -0
- data/lib/janky/notifier/multi.rb +22 -0
- data/lib/janky/public/css/base.css +204 -0
- data/lib/janky/public/images/building-bot.gif +0 -0
- data/lib/janky/public/images/disclosure-arrow.png +0 -0
- data/lib/janky/public/images/logo.png +0 -0
- data/lib/janky/public/images/robawt-status.gif +0 -0
- data/lib/janky/public/javascripts/application.js +3 -0
- data/lib/janky/public/javascripts/jquery.js +16 -0
- data/lib/janky/public/javascripts/jquery.relatize.js +111 -0
- data/lib/janky/repository.rb +174 -0
- data/lib/janky/tasks.rb +36 -0
- data/lib/janky/templates/console.mustache +4 -0
- data/lib/janky/templates/index.mustache +11 -0
- data/lib/janky/templates/layout.mustache +22 -0
- data/lib/janky/version.rb +3 -0
- data/lib/janky/views/console.rb +33 -0
- data/lib/janky/views/index.rb +35 -0
- data/lib/janky/views/layout.rb +19 -0
- data/test/default.xml.erb +0 -0
- data/test/janky_test.rb +271 -0
- data/test/test_helper.rb +107 -0
- metadata +319 -0
File without changes
|
data/lib/janky/commit.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
class Init < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :repositories, :force => true do |t|
|
4
|
+
t.string :name, :null => false
|
5
|
+
t.string :uri, :null => false
|
6
|
+
t.integer :room_id, :default => 376289, :null => false # Builds room
|
7
|
+
t.timestamps
|
8
|
+
end
|
9
|
+
add_index :repositories, :name, :unique => true
|
10
|
+
add_index :repositories, :uri, :unique => true
|
11
|
+
|
12
|
+
create_table :branches, :force => true do |t|
|
13
|
+
t.string :name, :null => false
|
14
|
+
t.belongs_to :repository, :null => false
|
15
|
+
t.timestamps
|
16
|
+
end
|
17
|
+
add_index :branches, [:name, :repository_id], :unique => true
|
18
|
+
|
19
|
+
create_table :commits, :force => true do |t|
|
20
|
+
t.string :sha1, :null => false
|
21
|
+
t.string :message, :null => false
|
22
|
+
t.string :author, :null => false
|
23
|
+
t.datetime :committed_at
|
24
|
+
t.belongs_to :repository, :null => false
|
25
|
+
t.timestamps
|
26
|
+
end
|
27
|
+
add_index :commits, [:sha1, :repository_id], :unique => true
|
28
|
+
|
29
|
+
create_table :builds, :force => true do |t|
|
30
|
+
t.boolean :green, :default => false
|
31
|
+
t.string :url, :null => true
|
32
|
+
t.string :compare, :null => false
|
33
|
+
t.datetime :started_at
|
34
|
+
t.datetime :completed_at
|
35
|
+
t.belongs_to :commit, :null => false
|
36
|
+
t.belongs_to :branch, :null => false
|
37
|
+
t.timestamps
|
38
|
+
end
|
39
|
+
add_index :builds, :url, :unique => true
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.down
|
43
|
+
drop_table :repositories
|
44
|
+
drop_table :branches
|
45
|
+
drop_table :commits
|
46
|
+
drop_table :builds
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
class RepoEnabled < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
add_column :repositories, :enabled, :boolean, :null => false, :default => true
|
4
|
+
add_index :repositories, :enabled
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.down
|
8
|
+
remove_column :repositories, :enabled
|
9
|
+
remove_index :repositories, :enabled
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
class DropDefaultRoomId < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
change_column :repositories, :room_id, :integer, :default => nil, :null => true
|
4
|
+
end
|
5
|
+
|
6
|
+
def self.down
|
7
|
+
change_column :repositories, :room_id, :integer, :default => 376289, :null => false
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
# This file is auto-generated from the current state of the database. Instead
|
2
|
+
# of editing this file, please use the migrations feature of Active Record to
|
3
|
+
# incrementally modify your database, and then regenerate this schema definition.
|
4
|
+
#
|
5
|
+
# Note that this schema.rb definition is the authoritative source for your
|
6
|
+
# database schema. If you need to create the application database on another
|
7
|
+
# system, you should be using db:schema:load, not running all the migrations
|
8
|
+
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
|
9
|
+
# you'll amass, the slower it'll run and the greater likelihood for issues).
|
10
|
+
#
|
11
|
+
# It's strongly recommended to check this file into your version control system.
|
12
|
+
|
13
|
+
ActiveRecord::Schema.define(:version => 1317384649) do
|
14
|
+
|
15
|
+
create_table "branches", :force => true do |t|
|
16
|
+
t.string "name", :null => false
|
17
|
+
t.integer "repository_id", :null => false
|
18
|
+
t.datetime "created_at"
|
19
|
+
t.datetime "updated_at"
|
20
|
+
end
|
21
|
+
|
22
|
+
add_index "branches", ["name", "repository_id"], :name => "index_branches_on_name_and_repository_id", :unique => true
|
23
|
+
|
24
|
+
create_table "builds", :force => true do |t|
|
25
|
+
t.boolean "green", :default => false
|
26
|
+
t.string "url"
|
27
|
+
t.string "compare", :null => false
|
28
|
+
t.datetime "started_at"
|
29
|
+
t.datetime "completed_at"
|
30
|
+
t.integer "commit_id", :null => false
|
31
|
+
t.integer "branch_id", :null => false
|
32
|
+
t.datetime "created_at"
|
33
|
+
t.datetime "updated_at"
|
34
|
+
t.text "output", :limit => 2147483647
|
35
|
+
t.integer "room_id"
|
36
|
+
end
|
37
|
+
|
38
|
+
add_index "builds", ["url"], :name => "index_builds_on_url", :unique => true
|
39
|
+
|
40
|
+
create_table "commits", :force => true do |t|
|
41
|
+
t.string "sha1", :null => false
|
42
|
+
t.string "message", :null => false
|
43
|
+
t.string "author", :null => false
|
44
|
+
t.datetime "committed_at"
|
45
|
+
t.integer "repository_id", :null => false
|
46
|
+
t.datetime "created_at"
|
47
|
+
t.datetime "updated_at"
|
48
|
+
t.string "url", :null => false
|
49
|
+
end
|
50
|
+
|
51
|
+
add_index "commits", ["sha1", "repository_id"], :name => "index_commits_on_sha1_and_repository_id", :unique => true
|
52
|
+
|
53
|
+
create_table "repositories", :force => true do |t|
|
54
|
+
t.string "name", :null => false
|
55
|
+
t.string "uri", :null => false
|
56
|
+
t.integer "room_id"
|
57
|
+
t.datetime "created_at"
|
58
|
+
t.datetime "updated_at"
|
59
|
+
t.boolean "enabled", :default => true, :null => false
|
60
|
+
t.string "hook_url"
|
61
|
+
t.integer "github_team_id"
|
62
|
+
end
|
63
|
+
|
64
|
+
add_index "repositories", ["enabled"], :name => "index_repositories_on_enabled"
|
65
|
+
add_index "repositories", ["name"], :name => "index_repositories_on_name", :unique => true
|
66
|
+
add_index "repositories", ["uri"], :name => "index_repositories_on_uri"
|
67
|
+
|
68
|
+
end
|
Binary file
|
@@ -0,0 +1,62 @@
|
|
1
|
+
module Janky
|
2
|
+
module Exception
|
3
|
+
def self.setup(notifier)
|
4
|
+
@notifier = notifier
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.report(exception, context={})
|
8
|
+
@notifier.report(exception, context)
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.push(context)
|
12
|
+
@notifier.push(context)
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.reset!
|
16
|
+
@notifier.reset!
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.push_http_response(response)
|
20
|
+
push(
|
21
|
+
:response_code => response.code.inspect,
|
22
|
+
:response_body => response.body.inspect
|
23
|
+
)
|
24
|
+
end
|
25
|
+
|
26
|
+
class Middleware
|
27
|
+
def initialize(app)
|
28
|
+
@app = app
|
29
|
+
end
|
30
|
+
|
31
|
+
def call(env)
|
32
|
+
request = Rack::Request.new(env)
|
33
|
+
Exception.reset!
|
34
|
+
Exception.push(
|
35
|
+
:app => "janky",
|
36
|
+
:method => request.request_method,
|
37
|
+
:user_agent => request.user_agent,
|
38
|
+
:params => (request.params.inspect rescue nil),
|
39
|
+
:session => (request.session.inspect rescue nil),
|
40
|
+
:referrer => request.referrer,
|
41
|
+
:remote_ip => request.ip,
|
42
|
+
:url => request.url
|
43
|
+
)
|
44
|
+
@app.call(env)
|
45
|
+
rescue Object => boom
|
46
|
+
Exception.report(boom)
|
47
|
+
raise
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
class Mock
|
52
|
+
def self.push(context)
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.report(e, context={})
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.reset!
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
data/lib/janky/github.rb
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
module Janky
|
2
|
+
module GitHub
|
3
|
+
def self.setup(user, password, secret, url)
|
4
|
+
@user = user
|
5
|
+
@password = password
|
6
|
+
@secret = secret
|
7
|
+
@url = url
|
8
|
+
end
|
9
|
+
|
10
|
+
class << self
|
11
|
+
attr_reader :secret
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.enable_mock!
|
15
|
+
@api = Mock.new(@user, @password)
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.repo_make_private(nwo)
|
19
|
+
api.make_private(nwo)
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.repo_make_public(nwo)
|
23
|
+
api.make_public(nwo)
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.repo_make_unauthorized(nwo)
|
27
|
+
api.make_unauthorized(nwo)
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.receiver
|
31
|
+
@receiver ||= Receiver.new(@secret)
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.repo_get(nwo)
|
35
|
+
response = api.repo_get(nwo)
|
36
|
+
|
37
|
+
case response.code
|
38
|
+
when "200"
|
39
|
+
Yajl.load(response.body)
|
40
|
+
when "403", "404"
|
41
|
+
nil
|
42
|
+
else
|
43
|
+
Exception.push_http_response(response)
|
44
|
+
raise Error, "Failed to get hook"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.hook_create(nwo)
|
49
|
+
response = api.create(nwo, @secret, @url)
|
50
|
+
|
51
|
+
if response.code == "201"
|
52
|
+
Yajl.load(response.body)["url"]
|
53
|
+
else
|
54
|
+
Exception.push_http_response(response)
|
55
|
+
raise Error, "Failed to create hook"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.hook_exists?(url)
|
60
|
+
api.get(url).code == "200"
|
61
|
+
end
|
62
|
+
|
63
|
+
def self.api
|
64
|
+
@api ||= API.new(@user, @password)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
module Janky
|
2
|
+
module GitHub
|
3
|
+
class API
|
4
|
+
def initialize(user, password)
|
5
|
+
@user = user
|
6
|
+
@password = password
|
7
|
+
end
|
8
|
+
|
9
|
+
def create(nwo, secret, url)
|
10
|
+
request = Net::HTTP::Post.new("/repos/#{nwo}/hooks")
|
11
|
+
payload = build_payload(url, secret)
|
12
|
+
request.body = Yajl.dump(payload)
|
13
|
+
request.basic_auth(@user, @password)
|
14
|
+
|
15
|
+
http.request(request)
|
16
|
+
end
|
17
|
+
|
18
|
+
def trigger(hook_url)
|
19
|
+
path = URI(hook_url).path
|
20
|
+
request = Net::HTTP::Post.new("#{path}/test")
|
21
|
+
request.basic_auth(@user, @password)
|
22
|
+
|
23
|
+
http.request(request)
|
24
|
+
end
|
25
|
+
|
26
|
+
def get(hook_url)
|
27
|
+
path = URI(hook_url).path
|
28
|
+
request = Net::HTTP::Get.new(path)
|
29
|
+
request.basic_auth(@user, @password)
|
30
|
+
|
31
|
+
http.request(request)
|
32
|
+
end
|
33
|
+
|
34
|
+
def repo_get(nwo)
|
35
|
+
path = "/repos/#{nwo}"
|
36
|
+
request = Net::HTTP::Get.new(path)
|
37
|
+
request.basic_auth(@user, @password)
|
38
|
+
|
39
|
+
http.request(request)
|
40
|
+
end
|
41
|
+
|
42
|
+
def build_payload(url, secret)
|
43
|
+
{ "name" => "web",
|
44
|
+
"active" => true,
|
45
|
+
"config" => {
|
46
|
+
"url" => url,
|
47
|
+
"secret" => secret,
|
48
|
+
"content_type" => "json"
|
49
|
+
}
|
50
|
+
}
|
51
|
+
end
|
52
|
+
|
53
|
+
def http
|
54
|
+
@http ||= http!
|
55
|
+
end
|
56
|
+
|
57
|
+
def http!
|
58
|
+
uri = URI("https://api.github.com")
|
59
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
60
|
+
|
61
|
+
http.use_ssl = true
|
62
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
63
|
+
http.ca_path = "/etc/ssl/certs"
|
64
|
+
|
65
|
+
http
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Janky
|
2
|
+
module GitHub
|
3
|
+
class Commit
|
4
|
+
def initialize(sha1, url, message, author, time)
|
5
|
+
@sha1 = sha1
|
6
|
+
@url = url
|
7
|
+
@message = message
|
8
|
+
@author = author
|
9
|
+
@time = time
|
10
|
+
end
|
11
|
+
|
12
|
+
attr_reader :sha1, :url, :message, :author
|
13
|
+
|
14
|
+
def committed_at
|
15
|
+
@time
|
16
|
+
end
|
17
|
+
|
18
|
+
def to_hash
|
19
|
+
{ :id => @sha1,
|
20
|
+
:url => @url,
|
21
|
+
:message => @message,
|
22
|
+
:author => {:name => @author},
|
23
|
+
:timestamp => @time }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|