bobette 0.0.3 → 0.0.5

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/Rakefile CHANGED
@@ -2,6 +2,7 @@ require "rake/testtask"
2
2
 
3
3
  Rake::TestTask.new(:default) do |t|
4
4
  t.test_files = FileList["test/*_test.rb"]
5
+ t.libs << "test"
5
6
  end
6
7
 
7
8
  begin
data/bobette.gemspec ADDED
@@ -0,0 +1,35 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "bobette"
3
+ s.version = "0.0.5"
4
+ s.date = "2009-10-10"
5
+
6
+ s.summary = "Bob's sister"
7
+ s.description = "Bob's sister"
8
+
9
+ s.homepage = "http://integrityapp.com"
10
+
11
+ s.authors = ["Nicolás Sanguinetti", "Simon Rozet"]
12
+ s.email = "info@integrityapp.com"
13
+
14
+ s.require_paths = ["lib"]
15
+ s.rubyforge_project = "integrity"
16
+ s.has_rdoc = false
17
+ s.rubygems_version = "1.3.1"
18
+
19
+ s.add_dependency "rack"
20
+
21
+ s.files = %w[
22
+ LICENSE
23
+ README.md
24
+ Rakefile
25
+ bobette.gemspec
26
+ lib/bobette.rb
27
+ lib/bobette/github.rb
28
+ test/bobette_github_test.rb
29
+ test/bobette_test.rb
30
+ test/deps.rip
31
+ test/helper.rb
32
+ test/helper/builder_stub.rb
33
+ test/helper/github_payload.js
34
+ ]
35
+ end
@@ -10,13 +10,15 @@ module Bobette
10
10
  def call(env)
11
11
  payload = Rack::Request.new(env).POST["payload"] || ""
12
12
  payload = JSON.parse(payload)
13
+ payload.delete("before")
13
14
  payload["scm"] = "git"
14
15
  payload["uri"] = uri(payload.delete("repository"))
15
16
  payload["branch"] = payload.delete("ref").split("/").last
16
17
  if (head = payload.delete("after")) && @head.call
17
- payload["commits"] = [{"id" => head}]
18
+ payload["commits"] = [head]
19
+ else
20
+ payload["commits"] = payload.delete("commits").collect { |c| c["id"] }
18
21
  end
19
-
20
22
  @app.call(env.update("bobette.payload" => payload))
21
23
  rescue JSON::JSONError
22
24
  Rack::Response.new("Unparsable payload", 400).finish
data/lib/bobette.rb CHANGED
@@ -1,28 +1,16 @@
1
- require "bob"
2
-
3
1
  module Bobette
4
- def self.new(buildable)
5
- App.new(buildable)
2
+ def self.new(builder)
3
+ App.new(builder)
6
4
  end
7
5
 
8
6
  class App
9
- attr_reader :buildable
10
-
11
- def initialize(buildable)
12
- @buildable = buildable
7
+ def initialize(builder)
8
+ @builder = builder
13
9
  end
14
10
 
15
11
  def call(env)
16
- payload = env["bobette.payload"]
17
- commits = payload["commits"].collect { |c| c["id"] }
18
- buildable = @buildable.call(payload)
19
-
20
- if buildable.respond_to?(:build)
21
- buildable.build(commits)
22
- [200, {"Content-Type" => "text/plain"}, ["OK"]]
23
- else
24
- [412, {"Content-Type" => "text/plain"}, ["Precondition Failed"]]
25
- end
12
+ @builder.call(env["bobette.payload"]).each { |b| b.build }
13
+ [200, {"Content-Type" => "text/plain"}, ["OK"]]
26
14
  end
27
15
  end
28
16
  end
@@ -1,5 +1,4 @@
1
- require File.dirname(__FILE__) + "/helper"
2
-
1
+ require "helper"
3
2
  require "bobette/github"
4
3
 
5
4
  class BobetteGitHubTest < Bobette::TestCase
@@ -16,48 +15,40 @@ class BobetteGitHubTest < Bobette::TestCase
16
15
  end
17
16
 
18
17
  def setup
18
+ super
19
19
  $head = false
20
- end
21
-
22
- def payload(repo, commits=[], is_private=false, branch="master")
23
- { "ref" => "refs/heads/#{branch}",
24
- "after" => commits.last["id"],
25
- "commits" => commits,
26
- "repository" => {"url" => "http://github.com/#{repo}",
27
- "private" => is_private } }
20
+ @payload = File.read("test/helper/github_payload.js")
28
21
  end
29
22
 
30
23
  def test_transform_payload
31
- commits = %w(b926de8 737bf26 8ba250e 78bb2de).map { |c| {"id" => c} }
32
-
33
- post("/", :payload =>
34
- payload("integrity/bob", commits).to_json) { |response|
24
+ commits = JSON.parse(@payload)["commits"].collect {|c| c["id"]}
35
25
 
26
+ post("/", :payload => @payload) { |response|
36
27
  assert response.ok?
37
28
  assert_equal(
38
- { "uri" => "git://github.com/integrity/bob",
29
+ { "uri" => "git://github.com/sr/bob",
39
30
  "scm" => "git",
40
31
  "branch" => "master",
41
32
  "commits" => commits }, JSON.parse(response.body))
42
33
  }
34
+ end
43
35
 
44
- post("/", :payload =>
45
- payload("integrity/bob", commits, true).to_json) { |response|
36
+ def test_transform_payload_private
37
+ payload = JSON.parse(@payload)
38
+ payload["repository"]["private"] = true
46
39
 
40
+ post("/", :payload => payload.to_json) { |response|
47
41
  assert response.ok?
48
- assert_equal "git@github.com:integrity/bob", JSON.parse(response.body)["uri"]
42
+ assert_equal "git@github.com:sr/bob", JSON.parse(response.body)["uri"]
49
43
  }
50
44
  end
51
45
 
52
46
  def test_head_commit
53
47
  $head = true
54
- commits = %w(b926de8 737bf26 8ba250e 78bb2de).map { |c| {"id" => c} }
55
-
56
- post("/", :payload =>
57
- payload("integrity/bob", commits).to_json) { |response|
58
-
48
+ post("/", :payload => @payload) { |response|
59
49
  assert response.ok?
60
- assert_equal [commits.last], JSON.parse(response.body)["commits"]
50
+ assert_equal ["b2f5af7a7cd70e69d1145a6b4ddbf87df22bd343"],
51
+ JSON.parse(response.body)["commits"]
61
52
  }
62
53
  end
63
54
 
data/test/bobette_test.rb CHANGED
@@ -1,74 +1,63 @@
1
- require File.dirname(__FILE__) + "/helper"
1
+ require "helper"
2
2
 
3
3
  class BobetteTest < Bobette::TestCase
4
4
  def app
5
5
  @app ||= Rack::Builder.new {
6
6
  use Rack::Lint
7
- run Bobette.new(BuildableStub)
7
+ run Bobette.new(BuilderStub)
8
8
  }
9
9
  end
10
10
 
11
- def payload(repo, branch="master")
12
- { "branch" => branch,
13
- "commits" => repo.commits.map { |c| {"id" => c[:identifier]} },
14
- "uri" => repo.path,
15
- "scm" => "git" }
11
+ def payload(repo)
12
+ { "branch" => repo.branch,
13
+ "commits" => repo.commits.collect { |c| c["identifier"] },
14
+ "uri" => repo.uri.to_s,
15
+ "scm" => repo.scm }
16
16
  end
17
17
 
18
18
  def setup
19
- Bob.logger = Logger.new("/dev/null")
20
- Bob.directory = "/tmp/bobette-builds"
19
+ super
21
20
 
22
- BuildableStub.no_buildable = false
23
-
24
- @repo = GitRepo.new(:my_test_project)
21
+ @repo = GitRepo.new("my_test_project")
25
22
  @repo.create
26
- 3.times { |i|
27
- i.odd? ? @repo.add_successful_commit : @repo.add_failing_commit
28
- }
23
+ 3.times{|i|i.odd? ? @repo.add_successful_commit : @repo.add_failing_commit}
29
24
 
30
- @metadata = {}
31
- @builds = {}
25
+ @commits = {}
26
+ @builds = {}
32
27
 
33
- Beacon.watch(:start) { |commit_id, commit_info|
34
- @metadata[commit_id] = commit_info
28
+ Beacon.watch(:start) { |commit|
29
+ @id = commit["identifier"]
30
+ @commits[@id] = commit
35
31
  }
36
32
 
37
- Beacon.watch(:finish) { |commit_id, status, output|
38
- @builds[commit_id] = [status ? :successful : :failed, output]
33
+ Beacon.watch(:finish) { |status, output|
34
+ @builds[@id] = [status ? :successful : :failed, output]
39
35
  }
40
36
  end
41
37
 
42
- def teardown
43
- FileUtils.rm_rf(Bob.directory)
44
- end
45
-
46
38
  def test_valid_payload
47
39
  assert post("/", {}, "bobette.payload" => payload(@repo)).ok?
48
40
 
49
- assert_equal 4, @metadata.count
50
41
  assert_equal 4, @builds.count
42
+ assert_equal 4, @commits.count
51
43
 
52
44
  commit = @repo.head
53
45
 
54
46
  assert_equal :failed, @builds[commit].first
55
47
  assert_equal "Running tests...\n", @builds[commit].last
56
- assert_equal "This commit will fail", @metadata[commit][:message]
48
+ assert_equal "This commit will fail", @commits[commit]["message"]
49
+ assert_equal "John Doe <johndoe@example.org>", @commits[commit]["author"]
50
+ assert_kind_of Time, @commits[commit]["committed_at"]
57
51
  end
58
52
 
59
53
  def test_invalid_payload
60
- # TODO
61
54
  assert_raise(NoMethodError) { assert post("/") }
62
55
  assert_raise(NoMethodError) { post("/", {}, "bobette.payload" => "</3") }
63
56
  end
64
57
 
65
58
  def test_no_buildable
66
- BuildableStub.no_buildable = true
67
-
59
+ BuilderStub.no_buildable = true
68
60
  payload = payload(@repo).update("branch" => "unknown")
69
-
70
- post("/", {}, "bobette.payload" => payload) { |response|
71
- assert_equal 412, response.status
72
- }
61
+ post("/", {}, "bobette.payload" => payload) { |r| r.ok? }
73
62
  end
74
63
  end
data/test/deps.rip ADDED
@@ -0,0 +1,6 @@
1
+ addressable 2.1.0
2
+ beacon 0.1
3
+ rack 1.0.0
4
+ json 1.1.7
5
+ rack-test 0.5.0
6
+ git://github.com/integrity/bob 8a477f2
@@ -0,0 +1,23 @@
1
+ module Bobette::TestHelper
2
+ class BuilderStub < Bob::Test::BuilderStub
3
+ class << self
4
+ attr_accessor :no_buildable
5
+ end
6
+
7
+ def self.call(payload)
8
+ return [] if no_buildable
9
+
10
+ payload.delete("commits").collect { |c|
11
+ new(payload.merge("command" => "./test", "commit" => c))
12
+ }
13
+ end
14
+
15
+ def started(commit_info)
16
+ Beacon.fire(:start, commit_info)
17
+ end
18
+
19
+ def completed(status, output)
20
+ Beacon.fire(:finish, status, output)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,54 @@
1
+ {
2
+ "after": "b2f5af7a7cd70e69d1145a6b4ddbf87df22bd343",
3
+ "before": "b260e5b541b87dd95768a4d0211be2dc66a26e1a",
4
+ "commits": [
5
+ {
6
+ "added": [],
7
+ "author": {
8
+ "email": "simon@rozet.name",
9
+ "name": "Simon Rozet"
10
+ },
11
+ "id": "c6dd001c1a95763b2ea62201b73005a6b86c048e",
12
+ "message": "Test SCM#dir_for instead of private #path method",
13
+ "modified": [
14
+ "test\/git_test.rb",
15
+ "test\/svn_test.rb"
16
+ ],
17
+ "removed": [],
18
+ "timestamp": "2009-09-30T06:10:44-07:00",
19
+ "url": "http:\/\/github.com\/sr\/bob\/commit\/c6dd001c1a95763b2ea62201b73005a6b86c048e"
20
+ },
21
+ {
22
+ "added": [
23
+ "deps.rip",
24
+ "hack.rip"
25
+ ],
26
+ "author": {
27
+ "email": "simon@rozet.name",
28
+ "name": "Simon Rozet"
29
+ },
30
+ "id": "b2f5af7a7cd70e69d1145a6b4ddbf87df22bd343",
31
+ "message": "Add rip files",
32
+ "modified": [],
33
+ "removed": [],
34
+ "timestamp": "2009-09-30T06:16:12-07:00",
35
+ "url": "http:\/\/github.com\/sr\/bob\/commit\/b2f5af7a7cd70e69d1145a6b4ddbf87df22bd343"
36
+ }
37
+ ],
38
+ "ref": "refs\/heads\/master",
39
+ "repository": {
40
+ "description": "Bob the Builder will build your codes",
41
+ "fork": true,
42
+ "forks": 0,
43
+ "homepage": "http:\/\/integrityapp.com",
44
+ "name": "bob",
45
+ "open_issues": 0,
46
+ "owner": {
47
+ "email": "simon@rozet.name",
48
+ "name": "sr"
49
+ },
50
+ "private": false,
51
+ "url": "http:\/\/github.com\/sr\/bob",
52
+ "watchers": 3
53
+ }
54
+ }
data/test/helper.rb CHANGED
@@ -9,9 +9,6 @@ begin
9
9
  rescue LoadError
10
10
  end
11
11
 
12
- $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + "/../lib"),
13
- File.expand_path(File.dirname(__FILE__))
14
-
15
12
  require "bobette"
16
13
 
17
14
  class Test::Unit::TestSuite
@@ -20,11 +17,24 @@ class Test::Unit::TestSuite
20
17
  end
21
18
  end
22
19
 
23
- require "helper/buildable_stub"
20
+ require "helper/builder_stub"
24
21
 
25
22
  class Bobette::TestCase < Test::Unit::TestCase
26
23
  include Rack::Test::Methods
27
24
  include Bob::Test
28
25
  include Bobette::TestHelper
26
+
27
+ def setup
28
+ Bob.logger = Logger.new("/dev/null")
29
+ Bob.directory = File.dirname(__FILE__) + "/../tmp"
30
+
31
+ FileUtils.mkdir(Bob.directory)
32
+
33
+ BuilderStub.no_buildable = false
34
+ end
35
+
36
+ def teardown
37
+ FileUtils.rm_rf(Bob.directory)
38
+ end
29
39
  end
30
40
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bobette
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - "Nicol\xC3\xA1s Sanguinetti"
@@ -10,19 +10,9 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2009-07-02 00:00:00 +02:00
13
+ date: 2009-10-10 00:00:00 +02:00
14
14
  default_executable:
15
15
  dependencies:
16
- - !ruby/object:Gem::Dependency
17
- name: bob
18
- type: :runtime
19
- version_requirement:
20
- version_requirements: !ruby/object:Gem::Requirement
21
- requirements:
22
- - - ">="
23
- - !ruby/object:Gem::Version
24
- version: "0"
25
- version:
26
16
  - !ruby/object:Gem::Dependency
27
17
  name: rack
28
18
  type: :runtime
@@ -33,46 +23,6 @@ dependencies:
33
23
  - !ruby/object:Gem::Version
34
24
  version: "0"
35
25
  version:
36
- - !ruby/object:Gem::Dependency
37
- name: rack-test
38
- type: :development
39
- version_requirement:
40
- version_requirements: !ruby/object:Gem::Requirement
41
- requirements:
42
- - - ">="
43
- - !ruby/object:Gem::Version
44
- version: "0"
45
- version:
46
- - !ruby/object:Gem::Dependency
47
- name: json
48
- type: :development
49
- version_requirement:
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: "0"
55
- version:
56
- - !ruby/object:Gem::Dependency
57
- name: beacon
58
- type: :development
59
- version_requirement:
60
- version_requirements: !ruby/object:Gem::Requirement
61
- requirements:
62
- - - ">="
63
- - !ruby/object:Gem::Version
64
- version: "0"
65
- version:
66
- - !ruby/object:Gem::Dependency
67
- name: bob-test
68
- type: :development
69
- version_requirement:
70
- version_requirements: !ruby/object:Gem::Requirement
71
- requirements:
72
- - - ">="
73
- - !ruby/object:Gem::Version
74
- version: "0"
75
- version:
76
26
  description: Bob's sister
77
27
  email: info@integrityapp.com
78
28
  executables: []
@@ -85,13 +35,15 @@ files:
85
35
  - LICENSE
86
36
  - README.md
87
37
  - Rakefile
88
- - examples/integrity.ru
38
+ - bobette.gemspec
89
39
  - lib/bobette.rb
90
40
  - lib/bobette/github.rb
91
41
  - test/bobette_github_test.rb
92
42
  - test/bobette_test.rb
43
+ - test/deps.rip
93
44
  - test/helper.rb
94
- - test/helper/buildable_stub.rb
45
+ - test/helper/builder_stub.rb
46
+ - test/helper/github_payload.js
95
47
  has_rdoc: true
96
48
  homepage: http://integrityapp.com
97
49
  licenses: []
@@ -1,25 +0,0 @@
1
- require "integrity"
2
- require "bobette"
3
- require "bobette/github"
4
-
5
- class Integrity::Project
6
- def self.new(payload)
7
- # Auto-create!
8
- first_or_create(:kind => payload["kind"],
9
- :uri => payload["uri"],
10
- :branch => payload["master"]
11
- )
12
- end
13
- end
14
-
15
- map "/github" do
16
- use Bobette::GitHub
17
- run Bobette.new(Integrity::Project)
18
- end
19
-
20
- Integrity.new(:database_uri => "sqlite3:integrity.db")
21
- DataMapper.auto_migrate!
22
-
23
- map "/" do
24
- run Integrity::App
25
- end
@@ -1,26 +0,0 @@
1
- module Bobette::TestHelper
2
- class BuildableStub < Bob::Test::BuildableStub
3
- class << self
4
- attr_accessor :no_buildable
5
- end
6
-
7
- def self.call(payload)
8
- return nil if no_buildable
9
-
10
- scm = payload["scm"]
11
- uri = payload["uri"]
12
- branch = payload["branch"]
13
- build_script = "./test"
14
-
15
- new(scm, uri, branch, build_script)
16
- end
17
-
18
- def start_building(commit_id, commit_info)
19
- Beacon.fire(:start, commit_id, commit_info)
20
- end
21
-
22
- def finish_building(commit_id, status, output)
23
- Beacon.fire(:finish, commit_id, status, output)
24
- end
25
- end
26
- end