glman 0.0.9 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MjEzMDQ2MTEwMzQwZTFhNmEzODcwMjUwZTFiNzA5NDFkZjkzYTNlZg==
4
+ YWY3Zjg2ZWY3ZDI1ZWEwM2I5ZjdhYWNjZTUzOTBlYmIzMWU1MjNjNw==
5
5
  data.tar.gz: !binary |-
6
- NTE4NTBiNjJlOWJiMGQwZjU3MTBlYTY1OGM2N2RlYzM5ZWQ0OWIwOA==
6
+ YjkyODhmYzJjODUxYWEzMWRlODRmYWM1OWY1ZGIxMjM4ZjdkODNiNg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ODVkMGM4MWQ1ZmUwMzU1YTFmZDNiNzhmNzU3NDk2ODk2NDVlYWM1NzNmYTEz
10
- OGIzYjQ1ZWEyYmMzZWM4NTVlYTRjOTE0ZDU4OTE1YWZjNzBmY2RiZmNmNzMy
11
- ZTM0MDNmYzc0NjkzNDY2YzVlNjFhZWEwOTYxMDU1ODVlNWNlNjE=
9
+ YzlmMmE1OWE0ODIwZjgzMmEzZWU5OWU5YzNjYjUxZGExNmViZGUyMGVlNWYx
10
+ ODYyOTVkZGJlYWEyMWNjMTYxY2Y3YjgyYmRkNzJiYTM1ZWVlYWVjOTY1MTMw
11
+ YTRjMmJiYjljYThkMWVkYjgzOThiODk2YWRlYTEyZjQ4MDcxMjk=
12
12
  data.tar.gz: !binary |-
13
- OTk5NTUyZWYyODEzMWUyYTI1MGI1YjRmM2E4MjEwZjNkYjFjMzQ1MzM3Njc3
14
- Y2JkNTliNzc4Y2NhYjhlYjBmZDcyNmMyNDdlMjMyMjhjYmUzODlmZDMxOWUx
15
- MTBlYTMxMDI5Yjg0NzNiNDA2NjY4M2E1MjVmNDc4NGMzMTQxYmE=
13
+ OGJjM2U5ZDk5MWQ2ZjhhN2NkYmU1M2M5MmJhM2U0YTAzMjU0ZDhiY2JiMTBl
14
+ NTM2YzQzZWUyODQyOTRjY2U0Zjk0NTFlM2E4YmI3M2NkZTdjMzkyMjFhZTcw
15
+ ZDJhYTRiOTM2YmVkMzM4YTUyYjg2NmNmNDNjMmMzYjAzZGM1NWI=
data/README.md CHANGED
@@ -12,7 +12,7 @@ GitLab bash manager
12
12
 
13
13
  setup
14
14
 
15
- $ glman config <gitlab_url> <private_token> --init
15
+ $ glman config gitlab url:http://site private_token:123 --set
16
16
 
17
17
  show
18
18
 
@@ -20,23 +20,27 @@ show
20
20
 
21
21
  ### Aliases
22
22
 
23
- create
23
+ add
24
24
 
25
- $ glman alias <user_email> <alias>
25
+ $ glman config aliases pn:pawel@o2.pl --add
26
+
27
+ delete
28
+
29
+ $ glman config aliases pn --del
26
30
 
27
31
  clear all aliases
28
32
 
29
- $ glman alias --clear
33
+ $ glman config aliases --clear
30
34
 
31
35
  ### User cache
32
36
 
33
37
  build cache
34
38
 
35
- $ glman cache
39
+ $ glman cache_users
36
40
 
37
41
  clear cache
38
42
 
39
- $ glman cache --clear
43
+ $ glman cache_users --clear
40
44
 
41
45
  ### Merge requests
42
46
 
@@ -52,9 +56,13 @@ make full syntax
52
56
 
53
57
  $ glman mr <user_email_or_alias> <message> <target_branch>
54
58
 
59
+ make optional options (push repo, create mr and notify on irc)
60
+
61
+ $ glman mr <user_email_or_alias> --push --notify
62
+
55
63
  show merge requests
56
64
 
57
- $ glman mr --show
65
+ $ glman mr
58
66
 
59
67
 
60
68
  ## Contributing
@@ -21,6 +21,7 @@ Gem::Specification.new do |spec|
21
21
  spec.require_paths = ["lib"]
22
22
 
23
23
  spec.add_development_dependency "bundler", "~> 1.3"
24
+ spec.add_development_dependency "rspec"
24
25
  spec.add_development_dependency "rake"
25
26
  spec.add_dependency "httpclient"
26
27
  spec.add_dependency "executable"
@@ -28,4 +29,5 @@ Gem::Specification.new do |spec|
28
29
  spec.add_dependency "active_support"
29
30
  spec.add_dependency "awesome_print"
30
31
  spec.add_dependency "hashie"
32
+ spec.add_dependency "irc-notify"
31
33
  end
@@ -1,3 +1,4 @@
1
+ require "glman/kernel"
1
2
  require "glman/version"
2
3
  require "active_support/dependencies"
3
4
 
@@ -10,137 +10,115 @@ module Glman
10
10
 
11
11
  # merge_request user_name/email message target_branch
12
12
  def mr(params)
13
- return show_all_mrs if show?
14
- user_name = params[0]
15
- current_branch = git_repo.current_branch
16
-
17
- if current_branch == 'master'
18
- p 'Merge request from master to master is not so good idea!'
19
- return
20
- end
21
-
22
- target_branch = params[2] || 'master'
23
- user_id = get_user_id(user_name)
24
- message = params[1] || git_repo.last_commit_message || current_branch
25
- repository_name = git_repo.repository_name
26
-
27
- params = {assignee_id: user_id, title: message, source_branch: current_branch, target_branch: target_branch}
13
+ return dp mr_command.get_all if params.length == 0
14
+ user_name = params[0]
15
+ user_id = get_user_id(user_name)
16
+ target_branch = params[2] || 'master'
17
+ current_branch = git_repo.current_branch
18
+ msg = params[1] || git_repo.last_commit_message || current_branch
28
19
 
29
20
  push_branch_first(origin, current_branch) unless origin.nil?
30
21
 
31
- opts = projects_repo.create_merge_request(repository_name, params)
32
- assignee = opts['assignee'] || {}
33
- author = opts['author'] || {}
34
- info = {
35
- url: "#{configuration.load[:gitlab_url]}/#{repository_name}/merge_requests/#{opts['iid']}",
36
- assignee: {
37
- username: assignee['username'],
38
- email: assignee['email'],
39
- name: assignee['name']
40
- },
41
- author: {
42
- username: author['username'],
43
- email: author['email'],
44
- name: author['name']
45
- },
46
- id: opts['id'],
47
- iid: opts['iid'],
48
- created_at: assignee['created_at']
49
- }
50
- ap params.merge({repository_name: repository_name}.merge(info))
22
+ result = mr_command.create(user_id: user_id, msg: msg, target_branch: target_branch)
23
+ dp result
24
+ irc_notify("Please review my merge request: #{result[:diff_url]}") if notify?
25
+ rescue Exception => e
26
+ dp e.message
51
27
  end
52
28
 
53
29
  def push=(origin=nil)
54
30
  @origin = origin || 'origin'
55
31
  end
56
32
 
57
- def show=(bool)
58
- @show = bool
59
- end
60
-
61
- def show?
62
- @show
63
- end
64
-
65
33
  def get_user_id(name)
66
34
  user = nil
67
- email = (configuration.load[:aliases] || {})[name]
68
- user = (configuration.load[:users] || {})[email] if email
35
+ email = (configuration.get(:aliases) || {})[name]
36
+ user = (configuration.get(:users) || {})[email] if email
69
37
  user = users_repo.find(email: name) unless user
70
38
  user[:id] if user
71
39
  end
72
40
 
73
- # Set/Get configuration
74
- def config(params=[])
75
- build_config(*params) if init?
76
- ap configuration.load || "No configuration yet"
77
- end
41
+ # Make Cache for user
42
+ def users_cache
43
+ return configuration.clear(:users) if clear?
78
44
 
79
- # Set user alias
80
- def user_alias(params)
81
- if clear?
82
- configuration.clear_user_aliases
83
- else
84
- params.empty? ? configuration.show_aliases : configuration.add_user_alias(email: params[0], alias: params[1])
45
+ users = {}.tap do |h|
46
+ users_repo.list.each{ |u| h[u['email']] = u }
85
47
  end
86
- config
48
+
49
+ configuration.set(:users, users)
87
50
  end
88
51
 
89
- # Make Cache for user
90
- def cache
91
- if clear?
92
- configuration.set_user_list({})
93
- else
94
- users = {}.tap do |h|
95
- users_repo.list.each{ |u| h[u['email']] = u }
96
- end
97
- configuration.set_user_list(users)
52
+ # Set/Get configuration
53
+ def config(params=[])
54
+ return configuration.show(params) unless [set?, del?, add?, clear?].any?
55
+ key = params.shift.to_sym
56
+
57
+ configuration.delete(key, params[0]) if del?
58
+ configuration.clear(key) if clear?
59
+
60
+ if set? || add?
61
+ opts = build_configuration_params(params)
62
+ configuration.set(key, opts) if set?
63
+ configuration.add(key, opts) if add?
98
64
  end
99
- config
100
- end
101
65
 
102
- def clear=(bool)
103
- @clear = bool
104
- end
66
+ #TODO later
67
+ key = ['notify', 'irc'] if key == :notify_irc
105
68
 
106
- def clear?
107
- @clear
69
+ configuration.show(key)
108
70
  end
109
71
 
72
+ #flags
73
+ def s=(bool); @set = bool; end
74
+ def set=(bool); @set = bool; end
75
+ def set?; @set; end
110
76
 
111
- #initialize configutation | cmd glman config [gitlab_url] [private_token] --init
112
- def init=(bool)
113
- @init = bool
114
- end
77
+ def a=(bool); @add = bool; end
78
+ def add=(bool); @add = bool; end
79
+ def add?; @add; end
115
80
 
116
- #
117
- def init?
118
- @init
119
- end
81
+ def d=(bool); @del = bool; end
82
+ def del=(bool); @del = bool; end
83
+ def del?; @del; end
84
+
85
+ def c=(bool); @clear = bool; end
86
+ def clear=(bool); @clear = bool; end
87
+ def clear?; @clear; end
88
+
89
+ def n=(bool); @notify = bool; end
90
+ def notify=(bool); @notify = bool; end
91
+ def notify?; @notify; end
120
92
 
121
- # Show help
122
93
  def help!
123
- puts 'Need help :D'
124
- puts help_page
94
+ puts Glman::Commands::HelpMessages.show
125
95
  exit
126
96
  end
127
97
  alias :h! :help!
128
98
 
129
99
  #Exec
130
100
  def call(name=nil, *params)
131
- intro
101
+ puts Glman::Commands::HelpMessages.intro
132
102
  case name.to_s.strip
133
- when 'config' then config(params)
134
- when 'alias' then user_alias(params)
135
- when 'cache' then cache
136
- when 'mr' then mr(params)
137
- when '' then puts '-'
103
+ when 'config' then config(params)
104
+ when 'alias' then user_alias(params)
105
+ when 'users_cache' then users_cache
106
+ when 'mr' then mr(params)
107
+ when '' then puts Glman::Commands::HelpMessages.unknown_command
138
108
  else puts "what ?"
139
109
  end
140
110
  end
111
+
141
112
  private
113
+
142
114
  attr_reader :origin
143
115
 
116
+ def build_configuration_params(params)
117
+ Hash.new.tap do |h|
118
+ params.each{ |e| e = e.split(':'); h[e.shift.to_sym] = e.join(':') }
119
+ end
120
+ end
121
+
144
122
  def push_branch_first(origin, branch)
145
123
  p "push branch: #{branch} to origin: origin"
146
124
  git_repo.push('origin', branch)
@@ -150,68 +128,38 @@ module Glman
150
128
  ap projects_repo.get_merge_requests(git_repo.repository_name)
151
129
  end
152
130
 
153
- def build_config(gitlab_url, private_token)
154
- configuration.build_config(gitlab_url: gitlab_url, private_token: private_token)
155
- end
156
-
157
131
  def configuration
158
- @configuration ||= Configuration.new
132
+ @configuration ||= Glman::Commands::Config.new(config_manager: ConfigManager.new)
159
133
  end
160
134
 
161
135
  def users_repo
162
- @users_repo ||= Repos::UsersRepo.new(configuration.load)
136
+ @users_repo ||= Repos::UsersRepo.new(configuration.get(:gitlab))
163
137
  end
164
138
 
165
139
  def projects_repo
166
- @projects_repo ||= Repos::ProjectsRepo.new(configuration.load)
140
+ @projects_repo ||= Repos::ProjectsRepo.new(configuration.get(:gitlab))
167
141
  end
168
142
 
169
143
  def git_repo
170
144
  @git_repo ||= Repos::GitRepo.new
171
145
  end
172
146
 
173
- def notify(msg)
174
- nick = configuration.load[:irc][:channel] || 'glman'
175
- irc_client.register(nick)
176
- irc_client.notify(configuration.load[:irc][:channel], msg)
177
- client.quit
147
+ def mr_command
148
+ @mr_command ||= Glman::Commands::Mr.new(git_repo: git_repo, projects_repo: projects_repo, config: configuration.get(:gitlab))
178
149
  end
179
150
 
180
- def irc_client
181
- @irc_client ||= (
182
- irc_config = configuration.load[:irc]
183
- server = irc_config[:server] || "irc.freenode.net"
184
- port = (irc_config[:port] || 6697).to_i
185
- ssl = irc_config[:ssl] == true ? true : false
186
- IrcNotify::Client.build(server, port, ssl: ssl)
187
- )
188
- end
189
-
190
- def help_page
191
- %{
192
- commands:
193
-
194
- config # display current configuration
195
- config <gitlab_url> <private_token> --init # init configuration
196
- notify_config <server:port> <channel> <ssl> # setup irc configuration for notifications
197
-
198
- alias # display aliases
199
- alias <user_email> <alias> # make alias for user email
200
- alias --clear # clear all aliases
201
-
202
- cache # build user cache for better performance RECOMMENDED
203
- cache --clear # clear user cache
204
-
205
- mr <user_email_or_alias> # create merge request for user for current branch to master with title as last commit message
206
-
207
- mr <user_email_or_alias> <message> <target_branch> --push <origin> # full options for merge request (default origin is a origin :D)
208
151
 
209
- Any questions pniemczyk@o2.pl or go to https://github.com/pniemczyk/glman
210
- }
152
+ def irc_conf
153
+ @irc_conf ||= configuration.get(:notify_irc)
211
154
  end
212
155
 
213
- def intro
214
- puts "Glman ver: #{VERSION}"
156
+ def irc_notify(msg)
157
+ c = IrcNotify::Client.build(irc_conf[:server], irc_conf[:port], ssl: irc_conf[:ssl])
158
+ nick = irc_conf[:nick] || "glman-#{git_repo.user_name.strip.downcase.gsub(' ','-')}"
159
+ channel = '#' + irc_conf[:channel].gsub('#', '')
160
+ c.register(nick)
161
+ c.notify(channel, msg)
162
+ c.quit
215
163
  end
216
164
  end
217
165
  end
@@ -0,0 +1,65 @@
1
+ require "irc-notify"
2
+
3
+ module Glman
4
+ module Commands
5
+ class Config
6
+
7
+ include InitRequired
8
+
9
+ attr_required :config_manager
10
+
11
+ def show(params=[])
12
+ get_configuration_by_key(params).tap do |conf|
13
+ dp conf.blank? ? "No configuration yet" : conf
14
+ end
15
+ end
16
+
17
+ def set(name, hash={})
18
+ send("#{name}_conf").set(hash)
19
+ end
20
+
21
+ def get(name)
22
+ send("#{name}_conf").get
23
+ end
24
+
25
+ def clear(name)
26
+ send("#{name}_conf").clear
27
+ end
28
+
29
+ def add(name, params)
30
+ send("#{name}_conf").add(params)
31
+ end
32
+
33
+ def delete(name, params)
34
+ send("#{name}_conf").delete(params)
35
+ end
36
+
37
+ private
38
+
39
+ def get_configuration_by_key(params)
40
+ return config_manager.get if params.blank?
41
+ return config_manager.get[params.to_sym] unless params.kind_of?(Array)
42
+
43
+ conf = config_manager.get
44
+ params.compact.each{ |key| conf = conf[key.to_sym] || {} }
45
+ conf
46
+ end
47
+
48
+ def users_conf
49
+ @users_conf ||= Glman::Commands::Configs::UsersConfig.new(config_manager: config_manager)
50
+ end
51
+
52
+ def notify_irc_conf
53
+ @notify_irc_conf ||= Glman::Commands::Configs::NotifyIrcConfig.new(config_manager: config_manager)
54
+ end
55
+
56
+ def gitlab_conf
57
+ @gitlab_conf ||= Glman::Commands::Configs::GitlabConfig.new(config_manager: config_manager)
58
+ end
59
+
60
+ def aliases_conf
61
+ @aliases_conf ||= Glman::Commands::Configs::AliasesConfig.new(config_manager: config_manager)
62
+ end
63
+ end
64
+ end
65
+ end