sr-bobette 0.0.2 → 0.0.4

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/README.md CHANGED
@@ -1,11 +1,17 @@
1
1
  # Bobette — Bob's sister
2
2
 
3
- Bobette is a Rack app that, when `POST`-ed a [GitHub-like payload][gh-payload],
4
- builds your code using [Bob][].
3
+ Bobette is a [Rack][] app that will turn the payload specified
4
+ via the `bobette.payload` Rack env key into a buildable object
5
+ and then builds it using [Bob][].
5
6
 
6
- You probably don't care about this, though. I am just experimenting
7
- with some ideas for [Integrity][].
7
+ You probably don't care about this, though; check out [Integrity][]
8
+ for a full fledged automated CI server or the test suite if you do.
8
9
 
9
- [Integrity]: http://github.com/integrity/integrity
10
+ ## Acknowledgement
11
+
12
+ Thanks a lot to [Tim Carey-Smith](http://github.com/halorgium) for
13
+ all his very useful feedbacks.
14
+
15
+ [Rack]: http://rack.rubyforge.org
10
16
  [Bob]: http://github.com/integrity/bob
11
- [gh-payload]: http://github.com/guides/post-receive-hooks
17
+ [Integrity]: http://github.com/integrity/integrity
data/lib/bobette.rb CHANGED
@@ -13,11 +13,13 @@ module Bobette
13
13
  end
14
14
 
15
15
  def call(env)
16
- payload = env["bobette.payload"]
17
- commits = payload["commits"].collect { |c| c["id"] }
18
- @buildable.from(payload).build(commits)
16
+ payload = env["bobette.payload"]
19
17
 
20
- Rack::Response.new("OK", 200).finish
18
+ @buildable.call(payload).each { |buildable|
19
+ buildable.build if buildable.respond_to?(:build)
20
+ }
21
+
22
+ [200, {"Content-Type" => "text/plain"}, ["OK"]]
21
23
  end
22
24
  end
23
25
  end
@@ -10,21 +10,24 @@ module Bobette
10
10
  def call(env)
11
11
  payload = Rack::Request.new(env).POST["payload"] || ""
12
12
  payload = JSON.parse(payload)
13
- payload["kind"] = "git"
14
- payload["uri"] = uri(payload.delete("repository")["url"]).to_s
13
+ payload["scm"] = "git"
14
+ payload["uri"] = uri(payload.delete("repository"))
15
15
  payload["branch"] = payload.delete("ref").split("/").last
16
16
  if (head = payload.delete("after")) && @head.call
17
17
  payload["commits"] = [{"id" => head}]
18
18
  end
19
- env["bobette.payload"] = payload
20
19
 
21
- @app.call(env)
20
+ @app.call(env.update("bobette.payload" => payload))
22
21
  rescue JSON::JSONError
23
22
  Rack::Response.new("Unparsable payload", 400).finish
24
23
  end
25
24
 
26
- def uri(url)
27
- URI(url).tap { |u| u.scheme = "git" }
25
+ def uri(repository)
26
+ if repository["private"]
27
+ "git@github.com:#{URI(repository["url"]).path[1..-1]}"
28
+ else
29
+ URI(repository["url"]).tap { |u| u.scheme = "git" }.to_s
30
+ end
28
31
  end
29
32
  end
30
33
  end
@@ -16,37 +16,48 @@ class BobetteGitHubTest < Bobette::TestCase
16
16
  end
17
17
 
18
18
  def setup
19
+ super
19
20
  $head = false
20
21
  end
21
22
 
22
- def github_payload(repo, commits=[], branch="master")
23
+ def payload(repo, commits=[], is_private=false, branch="master")
23
24
  { "ref" => "refs/heads/#{branch}",
24
25
  "after" => commits.last["id"],
25
26
  "commits" => commits,
26
- "repository" => {"url" => "http://github.com/#{repo}"} }
27
+ "repository" => {"url" => "http://github.com/#{repo}",
28
+ "private" => is_private } }
27
29
  end
28
30
 
29
31
  def test_transform_payload
30
32
  commits = %w(b926de8 737bf26 8ba250e 78bb2de).map { |c| {"id" => c} }
31
33
 
32
- post("/", :payload => github_payload("integrity/bob", commits).to_json) { |response|
33
- assert response.ok?
34
+ post("/", :payload =>
35
+ payload("integrity/bob", commits).to_json) { |response|
34
36
 
37
+ assert response.ok?
35
38
  assert_equal(
36
39
  { "uri" => "git://github.com/integrity/bob",
37
- "kind" => "git",
40
+ "scm" => "git",
38
41
  "branch" => "master",
39
42
  "commits" => commits }, JSON.parse(response.body))
40
43
  }
44
+
45
+ post("/", :payload =>
46
+ payload("integrity/bob", commits, true).to_json) { |response|
47
+
48
+ assert response.ok?
49
+ assert_equal "git@github.com:integrity/bob", JSON.parse(response.body)["uri"]
50
+ }
41
51
  end
42
52
 
43
53
  def test_head_commit
44
54
  $head = true
45
55
  commits = %w(b926de8 737bf26 8ba250e 78bb2de).map { |c| {"id" => c} }
46
56
 
47
- post("/", :payload => github_payload("integrity/bob", commits).to_json) { |response|
48
- assert response.ok?
57
+ post("/", :payload =>
58
+ payload("integrity/bob", commits).to_json) { |response|
49
59
 
60
+ assert response.ok?
50
61
  assert_equal [commits.last], JSON.parse(response.body)["commits"]
51
62
  }
52
63
  end
data/test/bobette_test.rb CHANGED
@@ -4,13 +4,19 @@ class BobetteTest < Bobette::TestCase
4
4
  def app
5
5
  @app ||= Rack::Builder.new {
6
6
  use Rack::Lint
7
- run Bobette.new(TestHelper::BuildableStub)
7
+ run Bobette.new(BuildableStub)
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" }
16
+ end
17
+
11
18
  def setup
12
- Bob.logger = Logger.new("/dev/null")
13
- Bob.directory = "/tmp/bobette-builds"
19
+ super
14
20
 
15
21
  @repo = GitRepo.new(:my_test_project)
16
22
  @repo.create
@@ -30,10 +36,6 @@ class BobetteTest < Bobette::TestCase
30
36
  }
31
37
  end
32
38
 
33
- def teardown
34
- FileUtils.rm_rf(Bob.directory)
35
- end
36
-
37
39
  def test_valid_payload
38
40
  assert post("/", {}, "bobette.payload" => payload(@repo)).ok?
39
41
 
@@ -52,4 +54,14 @@ class BobetteTest < Bobette::TestCase
52
54
  assert_raise(NoMethodError) { assert post("/") }
53
55
  assert_raise(NoMethodError) { post("/", {}, "bobette.payload" => "</3") }
54
56
  end
57
+
58
+ def test_no_buildable
59
+ BuildableStub.no_buildable = true
60
+
61
+ payload = payload(@repo).update("branch" => "unknown")
62
+
63
+ post("/", {}, "bobette.payload" => payload) { |response|
64
+ assert_equal 200, response.status
65
+ }
66
+ end
55
67
  end
data/test/helper.rb CHANGED
@@ -9,8 +9,8 @@ begin
9
9
  rescue LoadError
10
10
  end
11
11
 
12
- $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + "/../lib")
13
- $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__))
12
+ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + "/../lib"),
13
+ File.expand_path(File.dirname(__FILE__))
14
14
 
15
15
  require "bobette"
16
16
 
@@ -24,21 +24,20 @@ require "helper/buildable_stub"
24
24
 
25
25
  class Bobette::TestCase < Test::Unit::TestCase
26
26
  include Rack::Test::Methods
27
- include TestHelper
28
27
  include Bob::Test
28
+ include Bobette::TestHelper
29
29
 
30
- def app
31
- @app ||= Rack::Builder.new {
32
- use Rack::Lint
33
- run Bobette.new(TestHelper::BuildableStub)
34
- }
30
+ def setup
31
+ Bob.logger = Logger.new("/dev/null")
32
+ Bob.directory = File.dirname(__FILE__) + "/../tmp"
33
+
34
+ FileUtils.mkdir(Bob.directory)
35
+
36
+ BuildableStub.no_buildable = false
35
37
  end
36
38
 
37
- def payload(repo, branch="master")
38
- { "branch" => branch,
39
- "commits" => repo.commits.map { |c| {"id" => c[:identifier]} },
40
- "uri" => repo.path,
41
- "kind" => "git" }
39
+ def teardown
40
+ FileUtils.rm_rf(Bob.directory)
42
41
  end
43
42
  end
44
43
 
@@ -1,12 +1,20 @@
1
- module TestHelper
1
+ module Bobette::TestHelper
2
2
  class BuildableStub < Bob::Test::BuildableStub
3
- def self.from(payload)
4
- kind = payload["kind"]
3
+ class << self
4
+ attr_accessor :no_buildable
5
+ end
6
+
7
+ def self.call(payload)
8
+ return [] if no_buildable
9
+
10
+ scm = payload["scm"]
5
11
  uri = payload["uri"]
6
12
  branch = payload["branch"]
7
13
  build_script = "./test"
8
14
 
9
- new(kind, uri, branch, build_script)
15
+ payload["commits"].map { |commit|
16
+ new(scm, uri, branch, commit["id"], build_script)
17
+ }
10
18
  end
11
19
 
12
20
  def start_building(commit_id, commit_info)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sr-bobette
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - "Nicol\xC3\xA1s Sanguinetti"
@@ -10,11 +10,11 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2009-06-03 00:00:00 -07:00
13
+ date: 2009-07-17 00:00:00 -07:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
- name: bob-the-builder
17
+ name: bob
18
18
  type: :runtime
19
19
  version_requirement:
20
20
  version_requirements: !ruby/object:Gem::Requirement
@@ -63,16 +63,6 @@ dependencies:
63
63
  - !ruby/object:Gem::Version
64
64
  version: "0"
65
65
  version:
66
- - !ruby/object:Gem::Dependency
67
- name: sr-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
66
  description: Bob's sister
77
67
  email: info@integrityapp.com
78
68
  executables: []
@@ -113,7 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
113
103
  version:
114
104
  requirements: []
115
105
 
116
- rubyforge_project:
106
+ rubyforge_project: integrity
117
107
  rubygems_version: 1.2.0
118
108
  signing_key:
119
109
  specification_version: 2