glman 0.0.9 → 0.1.0
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 +8 -8
- data/README.md +15 -7
- data/glman.gemspec +2 -0
- data/lib/glman.rb +1 -0
- data/lib/glman/commands/base.rb +82 -134
- data/lib/glman/commands/config.rb +65 -0
- data/lib/glman/commands/configs/aliases_config.rb +53 -0
- data/lib/glman/commands/configs/gitlab_config.rb +42 -0
- data/lib/glman/commands/configs/notify_irc_config.rb +48 -0
- data/lib/glman/commands/configs/users_config.rb +29 -0
- data/lib/glman/commands/help_messages.rb +56 -0
- data/lib/glman/commands/mr.rb +70 -0
- data/lib/glman/commands/notify.rb +48 -0
- data/lib/glman/config_manager.rb +39 -0
- data/lib/glman/data_presenter.rb +9 -0
- data/lib/glman/init_required.rb +40 -0
- data/lib/glman/kernel.rb +5 -0
- data/lib/glman/repos/git_repo.rb +8 -0
- data/lib/glman/repos/projects_repo.rb +1 -1
- data/lib/glman/repos/users_repo.rb +1 -1
- data/lib/glman/version.rb +1 -1
- data/spec/glman/commands/config/aliases_config_spec.rb +76 -0
- data/spec/glman/commands/config/gitlab_config_spec.rb +63 -0
- data/spec/glman/commands/config/notify_irc_config_spec.rb +89 -0
- data/spec/glman/commands/config/users_config_spec.rb +42 -0
- data/spec/glman/commands/config_spec.rb +140 -0
- data/spec/glman/config_manager_spec.rb +54 -0
- data/spec/glman/init_required_spec.rb +19 -0
- data/spec/spec_helper.rb +22 -0
- metadata +59 -4
- data/lib/glman/configuration.rb +0 -58
data/lib/glman/kernel.rb
ADDED
data/lib/glman/repos/git_repo.rb
CHANGED
data/lib/glman/version.rb
CHANGED
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Glman::Commands::Configs::AliasesConfig do
|
4
|
+
subject{ described_class.new(config_manager: config_manager) }
|
5
|
+
let(:config_manager) { double('config_manager') }
|
6
|
+
|
7
|
+
describe '#add' do
|
8
|
+
before(:each) do
|
9
|
+
config_manager.should_receive(:set).with({ aliases: set_aliases })
|
10
|
+
config_manager.should_receive(:get).and_return(get_aliases)
|
11
|
+
end
|
12
|
+
let(:alias_name) {:dj}
|
13
|
+
let(:email) {'damian@o2.pl'}
|
14
|
+
let(:input_hash) {{email: email, alias_name: alias_name}}
|
15
|
+
let(:new_alias) {{alias_name => email}}
|
16
|
+
let(:old_aliases) {{pn: 'pniemczyk@o2.pl'}}
|
17
|
+
let(:get_aliases) {{aliases: old_aliases}}
|
18
|
+
let(:set_aliases) {old_aliases.merge(new_alias)}
|
19
|
+
|
20
|
+
it 'should add new alias to existings' do
|
21
|
+
subject.add(input_hash)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe '#delete' do
|
26
|
+
before(:each) do
|
27
|
+
config_manager.should_receive(:set).with({ aliases: set_aliases })
|
28
|
+
config_manager.should_receive(:get).and_return(get_aliases)
|
29
|
+
end
|
30
|
+
|
31
|
+
let(:alias_to_delete) {'pn'}
|
32
|
+
let(:get_aliases) {{aliases: {dj: 'damian@o2.pl', pn: 'pawel@o2.pl'}}}
|
33
|
+
let(:set_aliases) {{dj: 'damian@o2.pl'}}
|
34
|
+
|
35
|
+
it 'should delete alias from existings' do
|
36
|
+
subject.delete(alias_to_delete)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
describe '#set' do
|
42
|
+
before(:each) {config_manager.should_receive(:set).with({ aliases: set_aliases })}
|
43
|
+
let(:set_aliases) {{dj: 'damian@o2.pl', pn: 'pawel@o2.pl'}}
|
44
|
+
|
45
|
+
it 'should set new aliases' do
|
46
|
+
subject.set(set_aliases)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe '#get' do
|
51
|
+
before(:each) {config_manager.should_receive(:get).and_return(get_aliases)}
|
52
|
+
let(:current_aliasses) {{pn: 'pawel@o2.pl'}}
|
53
|
+
let(:get_aliases) {{aliases: current_aliasses}}
|
54
|
+
|
55
|
+
it 'should receive current aliases' do
|
56
|
+
subject.get.should eq current_aliasses
|
57
|
+
end
|
58
|
+
|
59
|
+
context 'when configuration is empty' do
|
60
|
+
let(:current_aliasses) {Glman::Commands::Configs::AliasesConfig::DEFAULT}
|
61
|
+
|
62
|
+
it 'should receive default aliases' do
|
63
|
+
subject.get.should eq current_aliasses
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe '#clear' do
|
69
|
+
before(:each) {config_manager.should_receive(:set).with({ aliases: set_aliases })}
|
70
|
+
let(:set_aliases) { nil }
|
71
|
+
|
72
|
+
it 'should set aliases to default' do
|
73
|
+
subject.clear
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Glman::Commands::Configs::GitlabConfig do
|
4
|
+
subject{ described_class.new(config_manager: config_manager) }
|
5
|
+
let(:config_manager) { double('config_manager') }
|
6
|
+
|
7
|
+
describe '#set' do
|
8
|
+
context 'error' do
|
9
|
+
it 'should raise GitlabConfigurationError when data is not Hash' do
|
10
|
+
msg = 'incorrect data'
|
11
|
+
-> {subject.set('bad')}.should raise_error(described_class::GitlabConfigurationError, msg)
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should raise GitlabConfigurationError when url is incorrect' do
|
15
|
+
msg = 'url is incorrect'
|
16
|
+
-> {subject.set(url: '@')}.should raise_error(described_class::GitlabConfigurationError, msg)
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should raise GitlabConfigurationError when private_token missing' do
|
20
|
+
msg = 'private_token missing'
|
21
|
+
-> {subject.set(url: 'http://test.com')}.should raise_error(described_class::GitlabConfigurationError, msg)
|
22
|
+
-> {subject.set(url: 'http://test.com', private_token: ' ')}.should raise_error(described_class::GitlabConfigurationError, msg)
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'successed' do
|
28
|
+
before(:each) {config_manager.should_receive(:set).with({ gitlab: set_gitlab })}
|
29
|
+
let(:set_gitlab) {{url: 'http://localhost', private_token: '1234'}}
|
30
|
+
|
31
|
+
it 'should set new gitlab' do
|
32
|
+
subject.set(set_gitlab)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe '#get' do
|
38
|
+
before(:each) {config_manager.should_receive(:get).and_return(get_gitlab)}
|
39
|
+
let(:current_config) {{url: 'http://localhost', private_token: '1234'}}
|
40
|
+
let(:get_gitlab) {{gitlab: current_config}}
|
41
|
+
|
42
|
+
it 'should receive current gitlab' do
|
43
|
+
subject.get.should eq current_config
|
44
|
+
end
|
45
|
+
|
46
|
+
context 'when configuration is empty' do
|
47
|
+
let(:current_config) {Glman::Commands::Configs::GitlabConfig::DEFAULT}
|
48
|
+
|
49
|
+
it 'should receive default gitlab' do
|
50
|
+
subject.get.should eq current_config
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe '#clear' do
|
56
|
+
before(:each) {config_manager.should_receive(:set).with({ gitlab: set_gitlab })}
|
57
|
+
let(:set_gitlab) { Glman::Commands::Configs::GitlabConfig::DEFAULT }
|
58
|
+
|
59
|
+
it 'should set to default' do
|
60
|
+
subject.clear
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Glman::Commands::Configs::NotifyIrcConfig do
|
4
|
+
subject{ described_class.new(config_manager: config_manager) }
|
5
|
+
let(:config_manager) { double('config_manager') }
|
6
|
+
|
7
|
+
describe '#set' do
|
8
|
+
before(:each){ config_manager.should_receive(:get).and_return(old_config) }
|
9
|
+
|
10
|
+
let(:old_config) do
|
11
|
+
{
|
12
|
+
notify: {
|
13
|
+
email: {some: 'test'},
|
14
|
+
irc: old_irc_config
|
15
|
+
}
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
let(:old_irc_config) do
|
20
|
+
{
|
21
|
+
nick: 'glman_test',
|
22
|
+
channel: 'test',
|
23
|
+
server: 'irc.super.com',
|
24
|
+
port: 9999,
|
25
|
+
ssl: false
|
26
|
+
}
|
27
|
+
end
|
28
|
+
|
29
|
+
let(:set_part_config) {{ channel: 'test-new', port: 1234, ssl: false }}
|
30
|
+
let(:set_full_config) do
|
31
|
+
{
|
32
|
+
nick: 'super_man',
|
33
|
+
channel: 'heroses',
|
34
|
+
server: 'irc.cool.com',
|
35
|
+
port: 912,
|
36
|
+
ssl: true
|
37
|
+
}
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'should set part configuration' do
|
41
|
+
config = old_irc_config.merge(set_part_config)
|
42
|
+
config_manager.should_receive(:set).with(notify: { email: {some: 'test'}, irc: config})
|
43
|
+
subject.set(set_part_config)
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'should set full configuration' do
|
47
|
+
config_manager.should_receive(:set).with(notify: { email: {some: 'test'}, irc: set_full_config})
|
48
|
+
subject.set(set_full_config)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe '#get' do
|
53
|
+
before(:each) {config_manager.should_receive(:get).and_return(notify: {irc: current_config})}
|
54
|
+
let(:current_config) do
|
55
|
+
{
|
56
|
+
nick: 'glman_test',
|
57
|
+
channel: 'test',
|
58
|
+
server: 'irc.super.com',
|
59
|
+
port: 9999,
|
60
|
+
ssl: false
|
61
|
+
}
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'should receive current itc configuration' do
|
65
|
+
subject.get.should eq current_config
|
66
|
+
end
|
67
|
+
|
68
|
+
context 'when configuration is empty' do
|
69
|
+
let(:current_config) {Glman::Commands::Configs::NotifyIrcConfig::DEFAULT}
|
70
|
+
|
71
|
+
it 'should receive default users' do
|
72
|
+
subject.get.should eq current_config
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
describe '#clear' do
|
78
|
+
before(:each) do
|
79
|
+
config_manager.should_receive(:set).with({ notify: {irc: new_config} })
|
80
|
+
config_manager.should_receive(:get).and_return({})
|
81
|
+
end
|
82
|
+
|
83
|
+
let(:new_config) { Glman::Commands::Configs::NotifyIrcConfig::DEFAULT }
|
84
|
+
|
85
|
+
it 'should set users to default' do
|
86
|
+
subject.clear
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Glman::Commands::Configs::UsersConfig do
|
4
|
+
subject{ described_class.new(config_manager: config_manager) }
|
5
|
+
let(:config_manager) { double('config_manager') }
|
6
|
+
|
7
|
+
describe '#set' do
|
8
|
+
before(:each) {config_manager.should_receive(:set).with({ users: set_users })}
|
9
|
+
let(:set_users) {{'damian@o2.pl' => {id: 1} , 'pawel@o2.pl' => {id: 2}}}
|
10
|
+
|
11
|
+
it 'should set new users' do
|
12
|
+
subject.set(set_users)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe '#get' do
|
17
|
+
before(:each) {config_manager.should_receive(:get).and_return(get_users)}
|
18
|
+
let(:current_users) {{'pawel@o2.pl' => {id: 2}}}
|
19
|
+
let(:get_users) {{users: current_users}}
|
20
|
+
|
21
|
+
it 'should receive current users' do
|
22
|
+
subject.get.should eq current_users
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'when configuration is empty' do
|
26
|
+
let(:current_users) {Glman::Commands::Configs::UsersConfig::DEFAULT}
|
27
|
+
|
28
|
+
it 'should receive default users' do
|
29
|
+
subject.get.should eq current_users
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe '#clear' do
|
35
|
+
before(:each) {config_manager.should_receive(:set).with({ users: set_users })}
|
36
|
+
let(:set_users) { nil }
|
37
|
+
|
38
|
+
it 'should set users to default' do
|
39
|
+
subject.clear
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,140 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Glman::Commands::Config do
|
4
|
+
subject{ described_class.new(config_manager: config_manager) }
|
5
|
+
let(:config_manager) { double('config_manager') }
|
6
|
+
|
7
|
+
describe '#show' do
|
8
|
+
let(:msg_no_configuration_yet) { 'No configuration yet' }
|
9
|
+
|
10
|
+
it 'should display message no_configuration_yet when configuration missing' do
|
11
|
+
config_manager.should_receive(:get).and_return({})
|
12
|
+
Glman::DataPresenter.should_receive(:show).with(msg_no_configuration_yet, {})
|
13
|
+
subject.show
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should display message no_configuration_yet when nested configuration missing' do
|
17
|
+
config_manager.should_receive(:get).and_return({ test: 'value' })
|
18
|
+
Glman::DataPresenter.should_receive(:show).with(msg_no_configuration_yet, {})
|
19
|
+
subject.show(['nested'])
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should display nested configuration when params present' do
|
23
|
+
expected_conf = { a: 'b'}
|
24
|
+
nested_conf = { next_level: expected_conf }
|
25
|
+
config = { test: nested_conf }
|
26
|
+
config_manager.should_receive(:get).and_return(config)
|
27
|
+
Glman::DataPresenter.should_receive(:show).with(expected_conf, {})
|
28
|
+
subject.show(['test', 'next_level'])
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should display base configuration when params missing' do
|
32
|
+
config = {test: 'test'}
|
33
|
+
config_manager.should_receive(:get).and_return(config)
|
34
|
+
Glman::DataPresenter.should_receive(:show).with(config, {})
|
35
|
+
subject.show
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context 'gitlab' do
|
40
|
+
let(:gitlab_conf) { double('gitlab_conf') }
|
41
|
+
before(:each) {subject.should_receive(:gitlab_conf).and_return(gitlab_conf)}
|
42
|
+
|
43
|
+
it '#set' do
|
44
|
+
value = { url: 'url', private_token: 'token' }
|
45
|
+
gitlab_conf.should_receive(:set).with(value)
|
46
|
+
subject.set(:gitlab, value)
|
47
|
+
end
|
48
|
+
|
49
|
+
it '#clear' do
|
50
|
+
gitlab_conf.should_receive(:clear)
|
51
|
+
subject.clear(:gitlab)
|
52
|
+
end
|
53
|
+
|
54
|
+
it '#get' do
|
55
|
+
gitlab_conf.should_receive(:get)
|
56
|
+
subject.get(:gitlab)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
context 'users' do
|
61
|
+
let(:users_conf) { double('users_conf') }
|
62
|
+
before(:each) {subject.should_receive(:users_conf).and_return(users_conf)}
|
63
|
+
|
64
|
+
it '#set' do
|
65
|
+
value = { 'damian@o2.pl' => {id: 1} }
|
66
|
+
users_conf.should_receive(:set).with(value)
|
67
|
+
subject.set(:users, value)
|
68
|
+
end
|
69
|
+
|
70
|
+
it '#clear' do
|
71
|
+
users_conf.should_receive(:clear)
|
72
|
+
subject.clear(:users)
|
73
|
+
end
|
74
|
+
|
75
|
+
it '#get' do
|
76
|
+
users_conf.should_receive(:get)
|
77
|
+
subject.get(:users)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
context 'aliases' do
|
82
|
+
let(:aliases_conf) { double('aliases_conf') }
|
83
|
+
before(:each) {subject.should_receive(:aliases_conf).and_return(aliases_conf)}
|
84
|
+
|
85
|
+
it '#set' do
|
86
|
+
value = {pn: 'pniemczyk@o2.pl'}
|
87
|
+
aliases_conf.should_receive(:set).with(value)
|
88
|
+
subject.set(:aliases, value)
|
89
|
+
end
|
90
|
+
|
91
|
+
it '#clear' do
|
92
|
+
aliases_conf.should_receive(:clear)
|
93
|
+
subject.clear(:aliases)
|
94
|
+
end
|
95
|
+
|
96
|
+
it '#get' do
|
97
|
+
aliases_conf.should_receive(:get)
|
98
|
+
subject.get(:aliases)
|
99
|
+
end
|
100
|
+
|
101
|
+
it '#delete' do
|
102
|
+
aliases_conf.should_receive(:delete).with(:pn)
|
103
|
+
subject.delete(:aliases, :pn)
|
104
|
+
end
|
105
|
+
|
106
|
+
it '#add' do
|
107
|
+
value = {pn: 'pniemczyk@o2.pl'}
|
108
|
+
aliases_conf.should_receive(:add).with(value)
|
109
|
+
subject.add(:aliases, value)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
context 'irc_notify' do
|
114
|
+
let(:irc_notify_conf) { double('irc_notify_conf') }
|
115
|
+
before(:each) {subject.should_receive(:irc_notify_conf).and_return(irc_notify_conf)}
|
116
|
+
|
117
|
+
it '#set' do
|
118
|
+
value = {
|
119
|
+
nick: 'glman_test',
|
120
|
+
channel: 'test',
|
121
|
+
server: 'irc.super.com',
|
122
|
+
port: 9999,
|
123
|
+
ssl: false
|
124
|
+
}
|
125
|
+
irc_notify_conf.should_receive(:set).with(value)
|
126
|
+
subject.set(:irc_notify, value)
|
127
|
+
end
|
128
|
+
|
129
|
+
it '#clear' do
|
130
|
+
irc_notify_conf.should_receive(:clear)
|
131
|
+
subject.clear(:irc_notify)
|
132
|
+
end
|
133
|
+
|
134
|
+
it '#get' do
|
135
|
+
irc_notify_conf.should_receive(:get)
|
136
|
+
subject.get(:irc_notify)
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
end
|