magi 0.1.1 → 0.1.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 00e582eed9e7365b07a029623587010791632dae
4
- data.tar.gz: d25ee1877b2ddcdfbb3ed4a8b678f3f837b8c50c
3
+ metadata.gz: d9b37e2f2249ebba06dacf853b32344b7de4dbc8
4
+ data.tar.gz: 07d0c016c8eb3cbd46433416923d912d44f8025a
5
5
  SHA512:
6
- metadata.gz: 501d6fb97fae40d4b13bf4add9e97dc645e7d7b87845cb76b56260cf9625bc840f7494038c0c74f6fa53ed8782fae12a8db5a98d402be99a13602b35df0da040
7
- data.tar.gz: 5e06f62c92daffb43bbe257f74cb250cd43d4fd0dda0c45cbae1eefaa9f76133c6df10d5ceea54e47975b3ee2345bf9dcfabdc9d4daf953597a712103e57e754
6
+ metadata.gz: 14299f4ba42d7a39813ad25815abde2cc7096c000f5ad660599c1afc3010b2f6555872dbd229a422228e770f1c828d8875dbe163091a203f1f3cff5604f5a216
7
+ data.tar.gz: a0f096a9d2dbf44468755b1a84312abd4df7bb161c93bdc2c6a45d167bc9e274b2aec86928cae26846b3e1df7666ff6fdde610c6adf71c5c4e8b5a9dc88afc00
data/Gemfile CHANGED
@@ -19,6 +19,7 @@ end
19
19
 
20
20
  group :test do
21
21
  gem "autodoc"
22
+ gem "coveralls", require: false
22
23
  gem "factory_girl_rails"
23
24
  gem "response_code_matchers"
24
25
  gem "rspec-json_matcher"
data/README.md CHANGED
@@ -1,10 +1,10 @@
1
- # Magi
1
+ # Magi [![Build Status](https://travis-ci.org/r7kamura/magi.png?branch=master)](https://travis-ci.org/r7kamura/magi) [![Code Climate](https://codeclimate.com/github/r7kamura/magi.png)](https://codeclimate.com/github/r7kamura/magi) [![Coverage Status](https://coveralls.io/repos/r7kamura/magi/badge.png)](https://coveralls.io/r/r7kamura/magi)
2
2
  Casual CI server system (magi is a temporal name).
3
3
 
4
4
  ## Usage
5
5
  ```
6
6
  $ gem install magi # install magi.gem
7
- $ brew install mysql redis # install MySQL and Redis
7
+ $ brew install mysql redis # install mysql and redis
8
8
  $ magi setup # create mysql tables
9
9
  $ magi start # launch server on http://localhost:3000
10
10
  ```
@@ -87,6 +87,10 @@ section.builds {
87
87
  background: #fafafa;
88
88
  }
89
89
 
90
+ li.unfinished a {
91
+ @include stripe;
92
+ }
93
+
90
94
  li.unfinished a:before {
91
95
  content: "\F056";
92
96
  }
@@ -4,3 +4,23 @@
4
4
  padding: .2em .6em;
5
5
  margin-bottom: .5em;
6
6
  }
7
+
8
+ @mixin stripe {
9
+ background-size: 30px 30px;
10
+ background-color: #ddd;
11
+ background-image: linear-gradient(
12
+ 135deg,
13
+ rgba(255, 255, 255, .30) 25%,
14
+ transparent 25%,
15
+ transparent 50%,
16
+ rgba(255, 255, 255, .30) 50%,
17
+ rgba(255, 255, 255, .30) 75%,
18
+ transparent 75%,
19
+ transparent
20
+ );
21
+ -webkit-animation: progress 3s linear infinite;
22
+ }
23
+
24
+ @-webkit-keyframes progress {
25
+ 0% { background-position: 0 0; } 100% { background-position: 60px 0; }
26
+ }
@@ -3,23 +3,9 @@ class ApplicationController < ActionController::Base
3
3
 
4
4
  respond_to :html, :json
5
5
 
6
- rescue_from WeakParameters::ValidationError do
7
- head 400
8
- end
9
-
10
6
  self.responder = Magi::Responder
11
7
 
12
- private
13
-
14
- def require_resource_params
15
- head 400 unless resource_params
16
- end
17
-
18
- def resource_name
19
- self.class.name.split("::").last.sub(/Controller$/, "").singularize.underscore
20
- end
21
-
22
- def resource_params
23
- params[resource_name]
8
+ rescue_from WeakParameters::ValidationError do
9
+ head 400
24
10
  end
25
11
  end
data/app/models/job.rb CHANGED
@@ -13,6 +13,12 @@ class Job < ActiveRecord::Base
13
13
 
14
14
  delegate :scheduled?, to: :scheduler, allow_nil: true
15
15
 
16
+ property(:description, type: :text)
17
+
18
+ property(:script, type: :text)
19
+
20
+ property(:schedule, placeholder: "* * * * *")
21
+
16
22
  class << self
17
23
  def create_with_properties(params)
18
24
  new.update_attributes_with_properties(params)
@@ -55,12 +61,6 @@ class Job < ActiveRecord::Base
55
61
  end
56
62
  end
57
63
 
58
- property(:description)
59
-
60
- property(:schedule)
61
-
62
- property(:script)
63
-
64
64
  def run
65
65
  script ? execute : raise_script_not_found
66
66
  end
@@ -70,22 +70,12 @@ class Job < ActiveRecord::Base
70
70
  end
71
71
 
72
72
  def enqueue
73
- builds.create.tap(&:enqueue)
74
- end
75
-
76
- def enqueue_with_before_enqueues
77
- if self.class.before_enqueues.all? {|hook| instance_exec(&hook) != false }
78
- enqueue_without_before_enqueues
79
- end
73
+ enqueue_without_before_enqueues if execute_before_enqueues
80
74
  end
81
- alias_method_chain :enqueue, :before_enqueues
82
75
 
83
- def enqueue_with_after_enqueues
84
- enqueue_without_after_enqueues.tap do
85
- self.class.after_enqueues.all? {|hook| instance_exec(&hook) != false }
86
- end
76
+ def enqueue_without_before_enqueues
77
+ builds.create.tap(&:enqueue).tap { execute_after_enqueues }
87
78
  end
88
- alias_method_chain :enqueue, :after_enqueues
89
79
 
90
80
  def status_name
91
81
  last_finished_build.try(:status_name) || "unfinished"
@@ -100,9 +90,7 @@ class Job < ActiveRecord::Base
100
90
  end
101
91
 
102
92
  def update_attributes_with_properties(params)
103
- params.slice(:name, *self.class.property_names).each do |key, value|
104
- send("#{key}=", value)
105
- end
93
+ params.slice(:name, *self.class.property_names).each {|key, value| send("#{key}=", value) }
106
94
  tap(&:save)
107
95
  end
108
96
 
@@ -117,21 +105,29 @@ class Job < ActiveRecord::Base
117
105
  end
118
106
 
119
107
  def execute
120
- workspace.chdir { Magi::Executer.execute(script) }
108
+ execute_before_executes
109
+ workspace.chdir { execute_script }.tap { execute_after_executes }
121
110
  end
122
111
 
123
- def execute_with_before_executes
112
+ def execute_script
113
+ Magi::Executer.execute(script)
114
+ end
115
+
116
+ def execute_before_enqueues
117
+ self.class.before_enqueues.all? {|hook| instance_exec(&hook) != false }
118
+ end
119
+
120
+ def execute_after_enqueues
121
+ self.class.after_enqueues.all? {|hook| instance_exec(&hook) != false }
122
+ end
123
+
124
+ def execute_before_executes
124
125
  self.class.before_executes.all? {|hook| instance_exec(&hook) != false }
125
- execute_without_before_executes
126
126
  end
127
- alias_method_chain :execute, :before_executes
128
127
 
129
- def execute_with_after_executes
130
- execute_without_after_executes.tap do
131
- self.class.after_executes.all? {|hook| instance_exec(&hook) != false }
132
- end
128
+ def execute_after_executes
129
+ self.class.after_executes.all? {|hook| instance_exec(&hook) != false }
133
130
  end
134
- alias_method_chain :execute, :after_executes
135
131
 
136
132
  def raise_script_not_found
137
133
  raise ScriptNotFound, 'You must set properties["script"]'
@@ -6,28 +6,17 @@ section.job_settings
6
6
  p= f.label :name
7
7
  p= f.text_field :name, placeholder: "required"
8
8
 
9
- .field
10
- p= f.label :description
11
- p= f.text_area :description, rows: 3
12
-
13
- .field
14
- p= f.label :script
15
- p= f.text_area :script, rows: 6
16
-
17
- .field
18
- p= f.label :schedule
19
- p= f.text_field :schedule, placeholder: "* * * * *"
20
-
21
9
  - resource.class.properties.each do |property|
22
- - next if property.name.in?([:description, :schedule, :script])
23
10
  .field
24
11
  p= f.label property.name
25
12
  p
26
13
  - case property.type
27
14
  - when :boolean
28
15
  = f.check_box property.name, {}, "true", "false"
16
+ - when :text
17
+ = f.text_area property.name, rows: 3
29
18
  - else
30
- = f.text_field property.name
19
+ = f.text_field property.name, placeholder: property.options[:placeholder]
31
20
 
32
21
  .field
33
22
  p= f.submit class: "button"
data/db/schema.rb CHANGED
@@ -9,28 +9,28 @@
9
9
  # from scratch. The latter is a flawed and unsustainable approach (the more migrations
10
10
  # you'll amass, the slower it'll run and the greater likelihood for issues).
11
11
  #
12
- # It's strongly recommended to check this file into your version control system.
12
+ # It's strongly recommended that you check this file into your version control system.
13
13
 
14
- ActiveRecord::Schema.define(:version => 20130608153655) do
14
+ ActiveRecord::Schema.define(version: 20130608153655) do
15
15
 
16
- create_table "builds", :force => true do |t|
16
+ create_table "builds", force: true do |t|
17
17
  t.boolean "status"
18
18
  t.datetime "started_at"
19
19
  t.datetime "finished_at"
20
20
  t.integer "job_id"
21
21
  t.text "output"
22
- t.datetime "created_at", :null => false
23
- t.datetime "updated_at", :null => false
22
+ t.datetime "created_at", null: false
23
+ t.datetime "updated_at", null: false
24
24
  t.text "properties"
25
25
  end
26
26
 
27
- add_index "builds", ["job_id"], :name => "index_builds_on_job_id"
27
+ add_index "builds", ["job_id"], name: "index_builds_on_job_id", using: :btree
28
28
 
29
- create_table "jobs", :force => true do |t|
29
+ create_table "jobs", force: true do |t|
30
30
  t.string "name"
31
31
  t.text "properties"
32
- t.datetime "created_at", :null => false
33
- t.datetime "updated_at", :null => false
32
+ t.datetime "created_at", null: false
33
+ t.datetime "updated_at", null: false
34
34
  end
35
35
 
36
36
  end
data/lib/magi/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Magi
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -14,7 +14,7 @@ module Magi
14
14
  end
15
15
 
16
16
  def enabled?
17
- job.enable_simplecov == "1"
17
+ !!job.enable_simplecov
18
18
  end
19
19
 
20
20
  def workspace_path
@@ -67,10 +67,19 @@ module Magi
67
67
  end
68
68
 
69
69
  def save
70
+ save_files
71
+ save_build
72
+ end
73
+
74
+ def save_files
70
75
  current_build_path.mkpath
71
76
  symlink_assets
72
77
  copy_result_html
73
78
  end
79
+
80
+ def save_build
81
+ job.current_build.update_properties(coverage: last_coverage)
82
+ end
74
83
  end
75
84
  end
76
85
 
@@ -83,3 +92,7 @@ Job.class_eval do
83
92
  @coverage ||= Magi::SimpleCov.new(self)
84
93
  end
85
94
  end
95
+
96
+ Build.class_eval do
97
+ property(:coverage)
98
+ end
@@ -0,0 +1,49 @@
1
+ require "spec_helper"
2
+
3
+ describe Magi::Command do
4
+ let(:command) do
5
+ described_class.new(arguments)
6
+ end
7
+
8
+ describe ".call" do
9
+ it "delegates to #call" do
10
+ described_class.any_instance.should_receive(:call)
11
+ described_class.call(["setup"])
12
+ end
13
+ end
14
+
15
+ describe "#call" do
16
+ context "with `setup`" do
17
+ let(:arguments) do
18
+ ["setup"]
19
+ end
20
+
21
+ it "executes setup script" do
22
+ command.should_receive(:system).with("cd #{Dir.pwd} && rake db:create db:migrate")
23
+ command.call
24
+ end
25
+ end
26
+
27
+ context "with `start`" do
28
+ let(:arguments) do
29
+ ["start"]
30
+ end
31
+
32
+ it "executes start script" do
33
+ command.should_receive(:system).with({ "WORKSPACE_PATH" => Dir.pwd }, "cd #{Dir.pwd} && foreman start")
34
+ command.call
35
+ end
36
+ end
37
+
38
+ context "with unknown arguments" do
39
+ let(:arguments) do
40
+ []
41
+ end
42
+
43
+ it "shows usage" do
44
+ command.should_receive(:puts).with("Usage: magi {setup|start}")
45
+ command.call
46
+ end
47
+ end
48
+ end
49
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,4 +1,10 @@
1
1
  require "simplecov"
2
+ require "coveralls"
3
+ Coveralls.wear!
4
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
5
+ SimpleCov::Formatter::HTMLFormatter,
6
+ Coveralls::SimpleCov::Formatter,
7
+ ]
2
8
  SimpleCov.start
3
9
 
4
10
  ENV["RAILS_ENV"] ||= "test"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: magi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryo Nakamura
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-06-21 00:00:00.000000000 Z
11
+ date: 2013-06-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: clockwork
@@ -373,6 +373,7 @@ files:
373
373
  - script/rails
374
374
  - spec/factories/build.rb
375
375
  - spec/factories/job.rb
376
+ - spec/magi/command_spec.rb
376
377
  - spec/models/build_spec.rb
377
378
  - spec/models/job_spec.rb
378
379
  - spec/requests/builds_spec.rb
@@ -412,6 +413,7 @@ summary: Magi
412
413
  test_files:
413
414
  - spec/factories/build.rb
414
415
  - spec/factories/job.rb
416
+ - spec/magi/command_spec.rb
415
417
  - spec/models/build_spec.rb
416
418
  - spec/models/job_spec.rb
417
419
  - spec/requests/builds_spec.rb