abak-flow 0.3.2 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +3 -0
- data/.travis.yml +7 -0
- data/Gemfile +10 -1
- data/README.md +13 -30
- data/Rakefile +25 -0
- data/VERSION +1 -1
- data/abak-flow.gemspec +23 -19
- data/bin/request +1 -2
- data/lib/abak-flow/branch.rb +108 -0
- data/lib/abak-flow/branches.rb +68 -0
- data/lib/abak-flow/configuration.rb +67 -0
- data/lib/abak-flow/locales/en.yml +32 -0
- data/lib/abak-flow/locales/ru.yml +32 -0
- data/lib/abak-flow/manager.rb +35 -0
- data/lib/abak-flow/messages.rb +86 -0
- data/lib/abak-flow/pull_request.rb +39 -199
- data/lib/abak-flow/repository.rb +71 -0
- data/lib/abak-flow/request.rb +88 -198
- data/lib/abak-flow/version.rb +1 -1
- data/lib/abak-flow/visitor.rb +43 -0
- data/lib/abak-flow.rb +20 -13
- data/spec/abak-flow/branch_spec.rb +55 -0
- data/spec/abak-flow/branches_spec.rb +20 -0
- data/spec/abak-flow/configuration_spec.rb +73 -0
- data/spec/abak-flow/git_spec.rb +12 -0
- data/spec/abak-flow/github_client_spec.rb +15 -0
- data/spec/abak-flow/messages_spec.rb +146 -0
- data/spec/abak-flow/project_spec.rb +52 -0
- data/spec/abak-flow/pull_request_spec.rb +353 -0
- data/spec/abak-flow/system_spec.rb +97 -0
- data/spec/spec_helper.rb +17 -0
- metadata +82 -31
- data/lib/abak-flow/config.rb +0 -20
- data/lib/abak-flow/extensions.rb +0 -125
- data/lib/abak-flow/github_client.rb +0 -13
@@ -0,0 +1,43 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
module Abak::Flow
|
4
|
+
class Visitor
|
5
|
+
def initialize(*args)
|
6
|
+
options = args.pop if args.last.is_a?(Hash)
|
7
|
+
|
8
|
+
@objects = args
|
9
|
+
@call = options.fetch(:call)
|
10
|
+
@info = options.fetch(:look_for)
|
11
|
+
|
12
|
+
@asked = false
|
13
|
+
end
|
14
|
+
|
15
|
+
def ready?
|
16
|
+
@asked = true
|
17
|
+
|
18
|
+
ready = @objects.map { |o| o.send(@call) }.uniq
|
19
|
+
ready.size == 1 && ready.first
|
20
|
+
end
|
21
|
+
|
22
|
+
def output
|
23
|
+
ready? unless asked?
|
24
|
+
|
25
|
+
@objects.map do |o|
|
26
|
+
next if o.send(@info).empty?
|
27
|
+
|
28
|
+
info = ""
|
29
|
+
name = o.respond_to?(:display_name) ? o.display_name : o.class.name
|
30
|
+
o.send(@info).each_with_index do |inf, idx|
|
31
|
+
info << "\n #{idx + 1}. #{inf}"
|
32
|
+
end
|
33
|
+
|
34
|
+
"\n#{name}#{info}"
|
35
|
+
end * "\n"
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
def asked?
|
40
|
+
@asked
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/lib/abak-flow.rb
CHANGED
@@ -1,19 +1,26 @@
|
|
1
1
|
module Abak
|
2
|
-
module Flow
|
3
|
-
end
|
2
|
+
module Flow; end
|
4
3
|
end
|
5
4
|
|
6
|
-
require
|
7
|
-
require
|
5
|
+
require "abak-flow/version" # ✔
|
6
|
+
require "abak-flow/manager" # ✔
|
7
|
+
require "abak-flow/configuration" # ✔
|
8
|
+
require "abak-flow/repository" # ✔
|
9
|
+
require "abak-flow/branch" # ?
|
10
|
+
require "abak-flow/pull_request" # ?
|
11
|
+
require "abak-flow/request" # ?
|
12
|
+
require "abak-flow/visitor" # ✔
|
8
13
|
|
9
|
-
require 'hub'
|
10
|
-
require 'highline'
|
11
|
-
require 'octokit'
|
12
14
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
# Может пригодится
|
16
|
+
# module ::Faraday
|
17
|
+
# class Response::RaiseOctokitError < Response::Middleware
|
18
|
+
# def error_message_with_trace(response)
|
19
|
+
# message = (response[:body].errors || []).map {|error| "=> #{error.code}: #{error.message}" }.join("\n")
|
18
20
|
|
19
|
-
|
21
|
+
# [error_message_without_trace(response), message].reject { |m| m.empty? }.join("\n\nДополнительные сообщения:\n")
|
22
|
+
# end
|
23
|
+
# alias_method :error_message_without_trace, :error_message
|
24
|
+
# alias_method :error_message, :error_message_with_trace
|
25
|
+
# end
|
26
|
+
# end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require "spec_helper"
|
3
|
+
|
4
|
+
describe Abak::Flow::Branch do
|
5
|
+
let(:develop) { double("Branch", full: "develop") }
|
6
|
+
let(:master) { double("Branch", full: "master") }
|
7
|
+
let(:hotfix) { double("Branch", full: "hotfix/PR-2011") }
|
8
|
+
let(:feature) { double("Branch", full: "feature/JP-515") }
|
9
|
+
let(:noname) { double("Branch", full: "my_own/what_i_want/branch_name") }
|
10
|
+
|
11
|
+
describe "#name" do
|
12
|
+
it { described_class.new(feature).name.should eq "feature/JP-515" }
|
13
|
+
it { described_class.new(develop).name.should eq "develop" }
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "#prefix" do
|
17
|
+
it { described_class.new(develop).prefix.should be_nil }
|
18
|
+
it { described_class.new(hotfix).prefix.should eq "hotfix" }
|
19
|
+
it { described_class.new(feature).prefix.should eq "feature" }
|
20
|
+
it { described_class.new(noname).prefix.should eq "my_own/what_i_want" }
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "#task" do
|
24
|
+
it { described_class.new(develop).task.should be_nil }
|
25
|
+
it { described_class.new(feature).task.should eq "JP-515" }
|
26
|
+
it { described_class.new(noname).task.should eq "branch_name" }
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "#hotfix?" do
|
30
|
+
it { described_class.new(develop).hotfix?.should eq false }
|
31
|
+
it { described_class.new(noname).hotfix?.should eq false }
|
32
|
+
it { described_class.new(feature).hotfix?.should eq false }
|
33
|
+
it { described_class.new(hotfix).hotfix?.should eq true }
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "#feature?" do
|
37
|
+
it { described_class.new(master).feature?.should eq false }
|
38
|
+
it { described_class.new(noname).feature?.should eq false }
|
39
|
+
it { described_class.new(hotfix).feature?.should eq false }
|
40
|
+
it { described_class.new(feature).feature?.should eq true }
|
41
|
+
end
|
42
|
+
|
43
|
+
describe "#task?" do
|
44
|
+
it { described_class.new(develop).task?.should eq false }
|
45
|
+
it { described_class.new(noname).task?.should eq false }
|
46
|
+
it { described_class.new(hotfix).task?.should eq true }
|
47
|
+
it { described_class.new(feature).task?.should eq true }
|
48
|
+
end
|
49
|
+
|
50
|
+
describe "#tracker_task" do
|
51
|
+
it { described_class.new(develop).tracker_task.should be_nil }
|
52
|
+
it { described_class.new(feature).tracker_task.should eq "JP-515" }
|
53
|
+
it { described_class.new(noname).tracker_task.should be_nil }
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require "spec_helper"
|
3
|
+
|
4
|
+
describe Abak::Flow::Branches do
|
5
|
+
describe "Interface" do
|
6
|
+
subject { described_class }
|
7
|
+
|
8
|
+
it { should respond_to :current_branch }
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "#current_branch" do
|
12
|
+
let(:branch) { double("Branch") }
|
13
|
+
let(:git) { double("Git", current_branch: "my_branch", branches: {"my_branch" => branch}) }
|
14
|
+
|
15
|
+
before { described_class.stub(:git).and_return git }
|
16
|
+
subject { described_class.current_branch }
|
17
|
+
|
18
|
+
it { should be_kind_of Abak::Flow::Branch }
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require "spec_helper"
|
3
|
+
|
4
|
+
describe Abak::Flow::Configuration do
|
5
|
+
let(:oauth_user) { "Admin" }
|
6
|
+
let(:oauth_token) { "0123456789" }
|
7
|
+
let(:proxy_server) { "http://www.super-proxy.net:4080/" }
|
8
|
+
let(:environment) { "http://www.linux-proxy.net:6666/" }
|
9
|
+
let(:instance) { described_class.clone.instance }
|
10
|
+
|
11
|
+
let(:git) do
|
12
|
+
double("Git Config", config: {
|
13
|
+
"abak-flow.oauth-user" => oauth_user,
|
14
|
+
"abak-flow.oauth-token" => oauth_token,
|
15
|
+
"abak-flow.proxy-server" => proxy_server,
|
16
|
+
"abak-flow.locale" => "ru"
|
17
|
+
})
|
18
|
+
end
|
19
|
+
|
20
|
+
context "when all config elements missing" do
|
21
|
+
let(:git) { double("Git Config", config: {}) }
|
22
|
+
|
23
|
+
before do
|
24
|
+
described_class.any_instance.stub(:environment_http_proxy).and_return nil
|
25
|
+
described_class.any_instance.stub(:git).and_return git
|
26
|
+
described_class.any_instance.stub(:setup_locale)
|
27
|
+
end
|
28
|
+
|
29
|
+
subject { instance.params }
|
30
|
+
|
31
|
+
its(:oauth_user) { should be_nil }
|
32
|
+
its(:oauth_token) { should be_nil }
|
33
|
+
its(:proxy_server) { should be_nil }
|
34
|
+
its(:locale) { should eq "en" }
|
35
|
+
end
|
36
|
+
|
37
|
+
context "when all config elements exists" do
|
38
|
+
before do
|
39
|
+
described_class.any_instance.stub(:environment_http_proxy).and_return nil
|
40
|
+
described_class.any_instance.stub(:git).and_return git
|
41
|
+
described_class.any_instance.stub(:setup_locale)
|
42
|
+
end
|
43
|
+
|
44
|
+
subject { instance.params }
|
45
|
+
|
46
|
+
its(:oauth_user) { should eq "Admin" }
|
47
|
+
its(:oauth_token) { should eq "0123456789" }
|
48
|
+
its(:locale) { should eq "ru" }
|
49
|
+
its(:proxy_server) { should eq "http://www.super-proxy.net:4080/" }
|
50
|
+
end
|
51
|
+
|
52
|
+
context "when various proxy server set" do
|
53
|
+
before do
|
54
|
+
described_class.any_instance.stub(:git).and_return git
|
55
|
+
described_class.any_instance.stub(:setup_locale)
|
56
|
+
end
|
57
|
+
|
58
|
+
subject { instance.params.proxy_server }
|
59
|
+
|
60
|
+
context "when ENV and git config setup proxy server" do
|
61
|
+
before { described_class.any_instance.stub(:environment_http_proxy).and_return environment }
|
62
|
+
|
63
|
+
it { should eq "http://www.super-proxy.net:4080/" }
|
64
|
+
end
|
65
|
+
|
66
|
+
context "when only ENV setup proxy server" do
|
67
|
+
before { described_class.any_instance.stub(:environment_http_proxy).and_return environment }
|
68
|
+
before { git.stub(:config).and_return({}) }
|
69
|
+
|
70
|
+
it { should eq "http://www.linux-proxy.net:6666/" }
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require "spec_helper"
|
3
|
+
|
4
|
+
describe Abak::Flow::Git do
|
5
|
+
subject { described_class.clone.instance }
|
6
|
+
|
7
|
+
describe "Interface" do
|
8
|
+
it { should respond_to :git }
|
9
|
+
it { should respond_to :command }
|
10
|
+
it { should respond_to :command_lines }
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require "spec_helper"
|
3
|
+
|
4
|
+
describe Abak::Flow::GithubClient do
|
5
|
+
let(:instance) { described_class.clone.instance }
|
6
|
+
|
7
|
+
describe "#connection" do
|
8
|
+
let(:options) { {login: "login", password: "password"} }
|
9
|
+
|
10
|
+
before { described_class.any_instance.stub(:connection_options).and_return options }
|
11
|
+
after { instance.connection }
|
12
|
+
|
13
|
+
it { Octokit::Client.should_receive(:new).with({login: "login", password: "password"}) }
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,146 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require "spec_helper"
|
3
|
+
|
4
|
+
describe Abak::Flow::Messages do
|
5
|
+
let(:messages) { Abak::Flow::Messages.new "my_scope" }
|
6
|
+
subject { messages }
|
7
|
+
|
8
|
+
describe "Interface" do
|
9
|
+
it { should respond_to :each }
|
10
|
+
it { should respond_to :push }
|
11
|
+
it { should respond_to :<< }
|
12
|
+
it { should respond_to :to_s }
|
13
|
+
it { should respond_to :header }
|
14
|
+
it { should respond_to :print }
|
15
|
+
it { should respond_to :pretty_print }
|
16
|
+
it { should respond_to :pp }
|
17
|
+
it { should respond_to :empty? }
|
18
|
+
it { should respond_to :translate }
|
19
|
+
it { should respond_to :t }
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "Public methods" do
|
23
|
+
describe "#header" do
|
24
|
+
before { I18n.should_receive(:t).with(:header, scope: "my_scope").and_return "+HEADER+" }
|
25
|
+
subject { messages.header}
|
26
|
+
|
27
|
+
it { should eq "+HEADER+" }
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "#push" do
|
31
|
+
context "when no elements pushed" do
|
32
|
+
its(:elements) { should be_empty }
|
33
|
+
end
|
34
|
+
|
35
|
+
context "when push only one element" do
|
36
|
+
before { messages.push :hello }
|
37
|
+
|
38
|
+
its(:elements) { should eq [:hello] }
|
39
|
+
end
|
40
|
+
|
41
|
+
context "when push more than one element" do
|
42
|
+
before { messages.push :hello }
|
43
|
+
before { messages.push :world }
|
44
|
+
|
45
|
+
its(:elements) { should eq [:hello, :world] }
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "#each" do
|
50
|
+
context "when no block given" do
|
51
|
+
it { expect { messages.each }.to raise_error ArgumentError }
|
52
|
+
end
|
53
|
+
|
54
|
+
context "when block given" do
|
55
|
+
before do
|
56
|
+
messages.push :hello
|
57
|
+
messages.push :linux
|
58
|
+
|
59
|
+
I18n.should_receive(:t).with(:linux, scope: "my_scope").and_return "linux_t"
|
60
|
+
I18n.should_receive(:t).with(:hello, scope: "my_scope").and_return "hello_t"
|
61
|
+
end
|
62
|
+
|
63
|
+
it { expect { |b| messages.each(&b) }.to yield_successive_args("hello_t", "linux_t") }
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe "#to_s" do
|
68
|
+
subject { messages.to_s }
|
69
|
+
|
70
|
+
context "when messages are empty" do
|
71
|
+
it { should be_empty }
|
72
|
+
end
|
73
|
+
|
74
|
+
context "when messages are not empty" do
|
75
|
+
before do
|
76
|
+
messages.push :hello
|
77
|
+
messages.push :linux
|
78
|
+
|
79
|
+
I18n.should_receive(:t).with(:linux, scope: "my_scope").and_return "linux_t"
|
80
|
+
I18n.should_receive(:t).with(:hello, scope: "my_scope").and_return "hello_t"
|
81
|
+
end
|
82
|
+
|
83
|
+
it { should include "hello_t" }
|
84
|
+
it { should include "linux_t" }
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
describe "#pretty_print" do
|
89
|
+
subject { messages.pp }
|
90
|
+
|
91
|
+
context "when messages are empty" do
|
92
|
+
it { should be_empty }
|
93
|
+
end
|
94
|
+
|
95
|
+
context "when messages are not empty" do
|
96
|
+
before do
|
97
|
+
messages.push :hello
|
98
|
+
messages.push :linux
|
99
|
+
|
100
|
+
I18n.should_receive(:t).with(:header, scope: "my_scope").and_return "+HEADER+"
|
101
|
+
I18n.should_receive(:t).with(:linux, scope: "my_scope").and_return "linux_t"
|
102
|
+
I18n.should_receive(:t).with(:hello, scope: "my_scope").and_return "hello_t"
|
103
|
+
end
|
104
|
+
|
105
|
+
it { should include "hello_t" }
|
106
|
+
it { should include "linux_t" }
|
107
|
+
it { should include "+HEADER+" }
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
describe "#translate" do
|
112
|
+
context "when translate from current scope" do
|
113
|
+
before { I18n.should_receive(:t).with(:word, scope: "my_scope").and_return "WORD" }
|
114
|
+
subject { messages.t :word }
|
115
|
+
|
116
|
+
it { should eq "WORD" }
|
117
|
+
end
|
118
|
+
|
119
|
+
context "when translate from different scope" do
|
120
|
+
before { I18n.should_receive(:t).with(:hello, scope: "diff_scope").and_return "HELLO" }
|
121
|
+
subject { messages.t :hello, {scope: "diff_scope"} }
|
122
|
+
|
123
|
+
it { should eq "HELLO" }
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
describe "#purge!" do
|
128
|
+
context "when message have elements" do
|
129
|
+
before { messages.push :hello }
|
130
|
+
before { messages.push :linux }
|
131
|
+
before { messages.purge! }
|
132
|
+
|
133
|
+
subject { messages }
|
134
|
+
|
135
|
+
it { should be_empty }
|
136
|
+
end
|
137
|
+
|
138
|
+
context "when message have no elements" do
|
139
|
+
before { messages.purge! }
|
140
|
+
subject { messages }
|
141
|
+
|
142
|
+
it { should be_empty }
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require "spec_helper"
|
3
|
+
|
4
|
+
describe Abak::Flow::Project do
|
5
|
+
let(:origin) { double("Origin", name: "origin", url: "git@github.com:Strech/abak-flow.git") }
|
6
|
+
let(:upstream) { double("Upstream", name: "upstream", url: "http://github.com/Godlike/abak-flow-new.git") }
|
7
|
+
let(:git) { double("Git", remotes: [origin, upstream]) }
|
8
|
+
let(:instance) { Abak::Flow::Project.clone.instance }
|
9
|
+
|
10
|
+
context "when initialize project with two remote repositories" do
|
11
|
+
before { Abak::Flow::Project.any_instance.stub(:git).and_return git }
|
12
|
+
|
13
|
+
subject { instance.remotes }
|
14
|
+
|
15
|
+
it { should have_key :origin }
|
16
|
+
it { should have_key :upstream }
|
17
|
+
end
|
18
|
+
|
19
|
+
context "when initialize project with some wrong repositories" do
|
20
|
+
let(:wrong) { double("Wrong", name: "wrong", url: "git@wrong-site.com:Me/wrong-flow.git") }
|
21
|
+
let(:git) { double("Git", remotes: [origin, wrong]) }
|
22
|
+
|
23
|
+
before { Abak::Flow::Project.any_instance.stub(:git).and_return git }
|
24
|
+
|
25
|
+
subject { instance.remotes }
|
26
|
+
|
27
|
+
it { should have_key :origin }
|
28
|
+
it { should_not have_key :upstream }
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "#Remote" do
|
32
|
+
before { Abak::Flow::Project.any_instance.stub(:git).and_return git }
|
33
|
+
|
34
|
+
describe "#origin" do
|
35
|
+
subject { instance.remotes[:origin] }
|
36
|
+
|
37
|
+
its(:owner) { should eq "Strech" }
|
38
|
+
its(:project) { should eq "abak-flow" }
|
39
|
+
its(:repo) { should eq origin }
|
40
|
+
its(:to_s) { should eq "Strech/abak-flow" }
|
41
|
+
end
|
42
|
+
|
43
|
+
describe "#upstream" do
|
44
|
+
subject { instance.remotes[:upstream] }
|
45
|
+
|
46
|
+
its(:owner) { should eq "Godlike" }
|
47
|
+
its(:project) { should eq "abak-flow-new" }
|
48
|
+
its(:repo) { should eq upstream }
|
49
|
+
its(:to_s) { should eq "Godlike/abak-flow-new" }
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|