abak-flow 1.0.6 → 1.0.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -120,7 +120,7 @@ module Abak::Flow
120
120
  private
121
121
  def tasks_from_commit_message
122
122
  @parsed_tasks ||=
123
- @branch.gcommit.message
123
+ @branch.gcommit.contents
124
124
  .scan(/(?:#{MAGICK_WORDS * "|"})\s+(#{TASK_FORMAT})/i)
125
125
  end
126
126
 
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+
3
+ module Abak::Flow
4
+ module Commands
5
+ class Checkup
6
+
7
+ def initialize
8
+ manager = Manager.instance
9
+
10
+ @configuration = manager.configuration
11
+ @repository = manager.repository
12
+ end
13
+
14
+ def run(args, options)
15
+ Visitor.new(@configuration, @repository,
16
+ command: "checkup", call: :ready?, inspect: :errors)
17
+ .on_fail(exit: 1)
18
+
19
+ say ANSI.green { I18n.t("commands.checkup.success") }
20
+ end
21
+
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,41 @@
1
+ # coding: utf-8
2
+ require "commander/blank"
3
+ require "commander/command"
4
+
5
+ module Abak::Flow
6
+ module Commands
7
+ class Compare
8
+ def initialize
9
+ manager = Manager.instance
10
+
11
+ @configuration = manager.configuration
12
+ @repository = manager.repository
13
+ @git = manager.git
14
+ end
15
+
16
+ def run(args, options)
17
+ Checkup.new.run(Array.new, ::Commander::Command::Options.new)
18
+
19
+ current = @git.current_branch
20
+ head = Branch.new(options.head || current)
21
+ base = Branch.new(options.base || head.extract_base_name)
22
+
23
+ if head.current?
24
+ say ANSI.white {
25
+ I18n.t("commands.compare.updating",
26
+ branch: ANSI.bold { head },
27
+ upstream: ANSI.bold { "#{@repository.origin}" }) }
28
+
29
+ head.update
30
+ else
31
+ say ANSI.yellow {
32
+ I18n.t("commands.compare.diverging",
33
+ branch: ANSI.bold { head }) }
34
+ end
35
+
36
+ say ANSI.green { head.compare_link(base) }
37
+ end
38
+
39
+ end
40
+ end
41
+ end
@@ -22,6 +22,8 @@ en:
22
22
  body_is_incorrect: Message body is not specified
23
23
 
24
24
  commands:
25
+ default:
26
+ fail: Something goes wrong!
25
27
  checkup:
26
28
  fail: You are not prepared!
27
29
  success: "Congratulations, you are ready to ROCK :)"
@@ -22,6 +22,8 @@ ru:
22
22
  body_is_incorrect: Не указано содержание
23
23
 
24
24
  commands:
25
+ default:
26
+ fail: Что-то пошло не так!
25
27
  checkup:
26
28
  fail: "Вы не готовы!"
27
29
  success: "Поздравляем, вы готовы чтобы жечь :)"
@@ -9,18 +9,10 @@ module Abak::Flow
9
9
 
10
10
  default_command :help
11
11
 
12
- # TODO : Заменить команды классами
13
- command :checkup do |c|
14
- c.syntax = "git request checkup"
15
- c.description = "Проверить все ли настроено для работы с github и удаленными репозиториями"
16
-
17
- c.action do |args, options|
18
- m = Manager.instance
19
- v = Visitor.new(m.configuration, m.repository, call: :ready?, inspect: :errors)
20
- v.exit_on_fail(:checkup, 1)
21
-
22
- say ANSI.green { I18n.t("commands.checkup.success") }
23
- end
12
+ command :checkup do |cmd|
13
+ cmd.syntax = "git request checkup"
14
+ cmd.description = "Проверить все ли настроено для работы с github и удаленными репозиториями"
15
+ cmd.action Commands::Checkup, :run
24
16
  end # command :checkup
25
17
 
26
18
  command :compare do |c|
@@ -30,30 +22,7 @@ module Abak::Flow
30
22
  c.option "--base STRING", String, "Имя ветки с которой нужно сравнить"
31
23
  c.option "--head STRING", String, "Имя ветки которую нужно сравнить"
32
24
 
33
- c.action do |args, options|
34
- m = Manager.instance
35
- v = Visitor.new(m.configuration, m.repository, call: :ready?, inspect: :errors)
36
- v.exit_on_fail(:compare, 1)
37
-
38
- current = m.git.current_branch
39
- head = Branch.new(options.head || current)
40
- base = Branch.new(options.base || head.extract_base_name)
41
-
42
- if head.current?
43
- say ANSI.white {
44
- I18n.t("commands.compare.updating",
45
- branch: ANSI.bold { head },
46
- upstream: ANSI.bold { "#{m.repository.origin}" }) }
47
-
48
- head.update
49
- else
50
- say ANSI.yellow {
51
- I18n.t("commands.compare.diverging",
52
- branch: ANSI.bold { head }) }
53
- end
54
-
55
- say ANSI.green { head.compare_link(base) }
56
- end
25
+ cmd.action Commands::Compare, :run
57
26
  end # command :compare
58
27
 
59
28
  command :publish do |c|
@@ -1,5 +1,5 @@
1
1
  module Abak
2
2
  module Flow
3
- VERSION = "1.0.6"
3
+ VERSION = "1.0.7"
4
4
  end
5
5
  end
@@ -8,6 +8,7 @@ module Abak::Flow
8
8
  @objects = args
9
9
  @call = options.fetch(:call)
10
10
  @inspect = options.fetch(:inspect)
11
+ @command = options.fetch(:command, "default")
11
12
 
12
13
  @asked = false
13
14
  end
@@ -44,6 +45,15 @@ module Abak::Flow
44
45
  exit(code)
45
46
  end
46
47
 
48
+ def on_fail(options = Hash.new, &block)
49
+ return if ready?
50
+
51
+ say ANSI.red I18n.t("commands.#{@command}.fail")
52
+ say ANSI.yellow { output }
53
+
54
+ exit(options[:exit]) if options.key?(:exit)
55
+ end
56
+
47
57
  private
48
58
  def asked?
49
59
  @asked
data/lib/abak-flow.rb CHANGED
@@ -1,10 +1,12 @@
1
- require "abak-flow/version" # ✔
2
- require "abak-flow/manager" # ✔
3
- require "abak-flow/configuration" # ✔
4
- require "abak-flow/repository" # ✔
5
- require "abak-flow/branch" # ?
6
- require "abak-flow/pull_request" # ?
7
- require "abak-flow/visitor" # ✔
1
+ require "abak-flow/version"
2
+ require "abak-flow/manager"
3
+ require "abak-flow/configuration"
4
+ require "abak-flow/repository"
5
+ require "abak-flow/branch"
6
+ require "abak-flow/pull_request"
7
+ require "abak-flow/visitor"
8
+ require "abak-flow/commands/checkup"
9
+ require "abak-flow/commands/compare"
8
10
 
9
11
 
10
12
  # Может пригодится
@@ -123,14 +123,14 @@ describe Abak::Flow::Branch do
123
123
  end
124
124
 
125
125
  context "when git commit is a short multi line" do
126
- let(:message) { "Hello commit message\n\nFixes PC4-100" }
126
+ let(:message) { "Hello commit message\n\nAnother new line" }
127
127
  let(:gcommit) { double("Git commit", message: message) }
128
128
 
129
129
  it { expect(noname.message).to eq "Hello commit message" }
130
130
  end
131
131
 
132
132
  context "when git commit is a very long multi line" do
133
- let(:message) { "#{'X' * 200}\n\nFixes PC4-100" }
133
+ let(:message) { "#{'X' * 200}\n\nAnother new line" }
134
134
  let(:gcommit) { double("Git commit", message: message) }
135
135
 
136
136
  it { expect(noname.message.length).to eq 75 }
@@ -139,7 +139,7 @@ describe Abak::Flow::Branch do
139
139
  end
140
140
 
141
141
  describe "#extract_title" do
142
- let(:message) { "Hello world!\n\nFixes PC4-100" }
142
+ let(:message) { "Hello world!\n\nAnother new line" }
143
143
  let(:gcommit) { double("Git commit", message: message) }
144
144
 
145
145
  context "when branch named not like tracker task" do
@@ -175,7 +175,7 @@ describe Abak::Flow::Branch do
175
175
  before { I18n.stub(:t).with("commands.publish.nothing").and_return "Empty!" }
176
176
 
177
177
  context "when commit message has no magick words" do
178
- let(:gcommit) { double("Git commit", message: "Hello world") }
178
+ let(:gcommit) { double("Git commit", contents: "Hello world") }
179
179
 
180
180
  before do
181
181
  git_feature.stub(:gcommit).and_return gcommit
@@ -208,7 +208,7 @@ describe Abak::Flow::Branch do
208
208
 
209
209
  context "when commit message has magick word" do
210
210
  context "when branch is task different from commit message" do
211
- let(:gcommit) { double("Git commit", message: "Fix PC4-200") }
211
+ let(:gcommit) { double("Git commit", contents: "Fix PC4-200") }
212
212
 
213
213
  before { git_feature.stub(:gcommit).and_return gcommit }
214
214
 
@@ -217,7 +217,7 @@ describe Abak::Flow::Branch do
217
217
  end
218
218
 
219
219
  context "when branch is task equals to commit message" do
220
- let(:gcommit) { double("Git commit", message: "Fix JP-515") }
220
+ let(:gcommit) { double("Git commit", contents: "Fix JP-515") }
221
221
 
222
222
  before { git_feature.stub(:gcommit).and_return gcommit }
223
223
 
@@ -225,7 +225,7 @@ describe Abak::Flow::Branch do
225
225
  end
226
226
 
227
227
  context "when branch is not task" do
228
- let(:gcommit) { double("Git commit", message: "Fix PC4-200, PC5-111\n\nCloses PC2-1122") }
228
+ let(:gcommit) { double("Git commit", contents: "Fix PC4-200, PC5-111\n\nCloses PC2-1122") }
229
229
 
230
230
  before { git_master.stub(:gcommit).and_return gcommit }
231
231
 
@@ -0,0 +1,38 @@
1
+ # coding: utf-8
2
+ require "spec_helper"
3
+
4
+ describe Abak::Flow::Commands::Checkup do
5
+ let(:command) { described_class.new }
6
+ let(:options) { double("Options") }
7
+ let(:run) { command.run(Array.new, options) }
8
+ let(:ansi) { double("ANSI") }
9
+ let(:manager) do
10
+ double("Manager", configuration: configuration,
11
+ repository: repository)
12
+ end
13
+
14
+ before do
15
+ stub_const('ANSI', ansi)
16
+ ansi.stub(green: "Success")
17
+ ansi.stub(red: "Fail")
18
+ ansi.stub(yellow: "Warning")
19
+
20
+ Abak::Flow::Manager.stub(instance: manager)
21
+ Abak::Flow::Visitor.any_instance.stub(:say) { |args| args }
22
+ Abak::Flow::Commands::Checkup.any_instance.stub(:say) { |args| args }
23
+ end
24
+
25
+ context "when no errors occurred" do
26
+ let(:repository) { double("Repository", ready?: true, errors: Array.new) }
27
+ let(:configuration) { double("Configuration", ready?: true, errors: Array.new) }
28
+
29
+ it { expect(run).to eq "Success" }
30
+ end
31
+
32
+ context "when errors occurred" do
33
+ let(:repository) { double("Repository", ready?: false, errors: ["Damn"]) }
34
+ let(:configuration) { double("Configuration", ready?: true, errors: Array.new) }
35
+
36
+ it { expect { run }.to raise_error SystemExit }
37
+ end
38
+ end
@@ -0,0 +1,120 @@
1
+ # coding: utf-8
2
+ require "spec_helper"
3
+
4
+ describe Abak::Flow::Commands::Compare do
5
+ let(:command) { described_class.new }
6
+ let(:options) { double("Options") }
7
+ let(:run) { command.run(Array.new, options) }
8
+ let(:ansi) { double("ANSI") }
9
+ let(:git) { double("Git") }
10
+ let(:manager) do
11
+ double("Manager", configuration: configuration,
12
+ repository: repository, git: git)
13
+ end
14
+
15
+ before do
16
+ stub_const('ANSI', ansi)
17
+ ansi.stub(green: "Success")
18
+ ansi.stub(red: "Fail")
19
+ ansi.stub(yellow: "Warning")
20
+
21
+ git.stub(:branch) { |x| x }
22
+
23
+ Abak::Flow::Manager.stub(instance: manager)
24
+ Abak::Flow::Visitor.any_instance.stub(:say) { |args| args }
25
+ Abak::Flow::Commands::Compare.any_instance.stub(:say) { |args| args }
26
+ Abak::Flow::Commands::Checkup.any_instance.stub(:say) { |args| args }
27
+ end
28
+
29
+ context "when errors occurred" do
30
+ let(:repository) { double("Repository", ready?: false, errors: ["Damn"]) }
31
+ let(:configuration) { double("Configuration", ready?: true, errors: Array.new) }
32
+
33
+ it { expect { run }.to raise_error SystemExit }
34
+ end
35
+
36
+ context "when no errors occurred" do
37
+ let(:repository) { double("Repository", ready?: true, errors: Array.new, origin: origin) }
38
+ let(:configuration) { double("Configuration", ready?: true, errors: Array.new) }
39
+ let(:origin) { double("Origin", repo: "origin-repo/flow") }
40
+
41
+ context "when only head/base is given" do
42
+ let(:current_branch) { double("Current branch", name: "cur-br-name", full: "cur-br-name") }
43
+ let(:master) { double("Master branch", name: "master", full: "master") }
44
+
45
+ before do
46
+ options.stub(head: master)
47
+ options.stub(base: nil)
48
+ end
49
+
50
+ context "when current branch is master" do
51
+ before do
52
+ Abak::Flow::Branch.any_instance.stub(extract_base_name: master)
53
+ git.stub(current_branch: master)
54
+ master.stub(current: true)
55
+
56
+ expect(ansi).to receive(:white)
57
+ expect(ansi).to receive(:green)
58
+ end
59
+
60
+ after { run }
61
+
62
+ it { expect(git).to receive(:push).with("origin-repo/flow", master) }
63
+ end
64
+
65
+ context "when current branch is not master" do
66
+ before do
67
+ Abak::Flow::Branch.any_instance.stub(extract_base_name: current_branch)
68
+ git.stub(current_branch: current_branch)
69
+ master.stub(current: false)
70
+ end
71
+
72
+ after { run }
73
+
74
+ it do
75
+ expect(ansi).to receive(:yellow)
76
+ expect(ansi).to receive(:green)
77
+ end
78
+ end
79
+ end
80
+
81
+ context "when head and base are given" do
82
+ let(:current_branch) { double("Current branch") }
83
+ let(:master) { double("Master branch", name: "master", full: "master") }
84
+ let(:develop) { double("Develop branch", name: "develop", full: "develop") }
85
+
86
+ before do
87
+ options.stub(head: master)
88
+ options.stub(base: develop)
89
+ end
90
+
91
+ context "when current branch is not head" do
92
+ before do
93
+ git.stub(current_branch: current_branch)
94
+ master.stub(current: false)
95
+ end
96
+
97
+ after { run }
98
+
99
+ it do
100
+ expect(ansi).to receive(:yellow)
101
+ expect(ansi).to receive(:green)
102
+ end
103
+ end
104
+
105
+ context "when current branch is head" do
106
+ before do
107
+ git.stub(current_branch: master)
108
+ master.stub(current: true)
109
+
110
+ expect(ansi).to receive(:white)
111
+ expect(ansi).to receive(:green)
112
+ end
113
+
114
+ after { run }
115
+
116
+ it { expect(git).to receive(:push).with("origin-repo/flow", master) }
117
+ end
118
+ end
119
+ end
120
+ end
metadata CHANGED
@@ -2,14 +2,14 @@
2
2
  name: abak-flow
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.0.6
5
+ version: 1.0.7
6
6
  platform: ruby
7
7
  authors:
8
8
  - Strech (aka Sergey Fedorov)
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-02-17 00:00:00.000000000 Z
12
+ date: 2014-02-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: octokit
@@ -205,6 +205,8 @@ files:
205
205
  - bin/request
206
206
  - lib/abak-flow.rb
207
207
  - lib/abak-flow/branch.rb
208
+ - lib/abak-flow/commands/checkup.rb
209
+ - lib/abak-flow/commands/compare.rb
208
210
  - lib/abak-flow/configuration.rb
209
211
  - lib/abak-flow/locales/en.yml
210
212
  - lib/abak-flow/locales/ru.yml
@@ -215,6 +217,8 @@ files:
215
217
  - lib/abak-flow/version.rb
216
218
  - lib/abak-flow/visitor.rb
217
219
  - spec/lib/abak-flow/branch_spec.rb
220
+ - spec/lib/abak-flow/commands/checkup_spec.rb
221
+ - spec/lib/abak-flow/commands/compare_spec.rb
218
222
  - spec/spec_helper.rb
219
223
  homepage: https://github.com/Strech/abak-flow
220
224
  licenses:
@@ -243,4 +247,6 @@ specification_version: 3
243
247
  summary: Совмещение 2-х подходов разработки Git-flow & Github-flow
244
248
  test_files:
245
249
  - spec/lib/abak-flow/branch_spec.rb
250
+ - spec/lib/abak-flow/commands/checkup_spec.rb
251
+ - spec/lib/abak-flow/commands/compare_spec.rb
246
252
  - spec/spec_helper.rb