class Glman::Commands::Base
Attributes
origin[R]
Public Instance Methods
a=(bool)
click to toggle source
# File lib/glman/commands/base.rb, line 77 def a=(bool); @add = bool; end
add=(bool)
click to toggle source
# File lib/glman/commands/base.rb, line 78 def add=(bool); @add = bool; end
add?()
click to toggle source
# File lib/glman/commands/base.rb, line 79 def add?; @add; end
c=(bool)
click to toggle source
# File lib/glman/commands/base.rb, line 85 def c=(bool); @clear = bool; end
call(name=nil, *params)
click to toggle source
Exec
# File lib/glman/commands/base.rb, line 100 def call(name=nil, *params) puts Glman::Commands::HelpMessages.intro case name.to_s.strip when 'config' then config(params) when 'alias' then user_alias(params) when 'users_cache' then users_cache when 'mr' then mr(params) when '' then puts Glman::Commands::HelpMessages.unknown_command else puts "what ?" end end
clear=(bool)
click to toggle source
# File lib/glman/commands/base.rb, line 86 def clear=(bool); @clear = bool; end
clear?()
click to toggle source
# File lib/glman/commands/base.rb, line 87 def clear?; @clear; end
config(params=[])
click to toggle source
Set/Get configuration
# File lib/glman/commands/base.rb, line 53 def config(params=[]) return configuration.show(params) unless [set?, del?, add?, clear?].any? key = params.shift.to_sym configuration.delete(key, params[0]) if del? configuration.clear(key) if clear? if set? || add? opts = build_configuration_params(params) configuration.set(key, opts) if set? configuration.add(key, opts) if add? end #TODO later key = ['notify', 'irc'] if key == :notify_irc configuration.show(key) end
d=(bool)
click to toggle source
# File lib/glman/commands/base.rb, line 81 def d=(bool); @del = bool; end
del=(bool)
click to toggle source
# File lib/glman/commands/base.rb, line 82 def del=(bool); @del = bool; end
del?()
click to toggle source
# File lib/glman/commands/base.rb, line 83 def del?; @del; end
get_user_id(name)
click to toggle source
# File lib/glman/commands/base.rb, line 33 def get_user_id(name) user = nil email = (configuration.get(:aliases) || {})[name] user = (configuration.get(:users) || {})[email] if email user = users_repo.find(email: name) unless user user[:id] || user['id'] if user end
help!()
click to toggle source
# File lib/glman/commands/base.rb, line 93 def help! puts Glman::Commands::HelpMessages.show exit end
Also aliased as: h!
mr(params)
click to toggle source
merge_request user_name/email message target_branch
# File lib/glman/commands/base.rb, line 12 def mr(params) return dp mr_command.get_all if params.length == 0 user_name = params[0] user_id = get_user_id(user_name) target_branch = params[2] || 'master' current_branch = git_repo.current_branch msg = params[1] || git_repo.last_commit_message || current_branch push_branch_first(origin, current_branch) unless origin.nil? result = mr_command.create(user_id: user_id, msg: msg, target_branch: target_branch) dp result irc_notify("Please review my merge request: #{result[:diff_url]}") if notify? rescue Exception => e dp e.message end
n=(bool)
click to toggle source
# File lib/glman/commands/base.rb, line 89 def n=(bool); @notify = bool; end
notify=(bool)
click to toggle source
# File lib/glman/commands/base.rb, line 90 def notify=(bool); @notify = bool; end
notify?()
click to toggle source
# File lib/glman/commands/base.rb, line 91 def notify?; @notify; end
push=(origin=nil)
click to toggle source
# File lib/glman/commands/base.rb, line 29 def push=(origin=nil) @origin = origin || 'origin' end
s=(bool)
click to toggle source
flags
# File lib/glman/commands/base.rb, line 73 def s=(bool); @set = bool; end
set=(bool)
click to toggle source
# File lib/glman/commands/base.rb, line 74 def set=(bool); @set = bool; end
set?()
click to toggle source
# File lib/glman/commands/base.rb, line 75 def set?; @set; end
users_cache()
click to toggle source
Make Cache for user
# File lib/glman/commands/base.rb, line 42 def users_cache return configuration.clear(:users) if clear? users = {}.tap do |h| users_repo.list.each{ |u| h[u['email']] = u } end configuration.set(:users, users) end
Private Instance Methods
build_configuration_params(params)
click to toggle source
# File lib/glman/commands/base.rb, line 116 def build_configuration_params(params) Hash.new.tap do |h| params.each{ |e| e = e.split(':'); h[e.shift.to_sym] = e.join(':') } end end
configuration()
click to toggle source
# File lib/glman/commands/base.rb, line 131 def configuration @configuration ||= Glman::Commands::Config.new(config_manager: ConfigManager.new) end
git_repo()
click to toggle source
# File lib/glman/commands/base.rb, line 143 def git_repo @git_repo ||= Repos::GitRepo.new end
irc_conf()
click to toggle source
# File lib/glman/commands/base.rb, line 152 def irc_conf @irc_conf ||= configuration.get(:notify_irc) end
irc_notify(msg)
click to toggle source
# File lib/glman/commands/base.rb, line 156 def irc_notify(msg) c = IrcNotify::Client.build(irc_conf[:server], irc_conf[:port], ssl: irc_conf[:ssl]) nick = irc_conf[:nick] || "glman-#{git_repo.user_name.strip.downcase.gsub(' ','-')}" channel = '#' + irc_conf[:channel].gsub('#', '') c.register(nick) c.notify(channel, msg) c.quit end
mr_command()
click to toggle source
# File lib/glman/commands/base.rb, line 147 def mr_command @mr_command ||= Glman::Commands::Mr.new(git_repo: git_repo, projects_repo: projects_repo, config: configuration.get(:gitlab)) end
projects_repo()
click to toggle source
# File lib/glman/commands/base.rb, line 139 def projects_repo @projects_repo ||= Repos::ProjectsRepo.new(configuration.get(:gitlab)) end
push_branch_first(origin, branch)
click to toggle source
# File lib/glman/commands/base.rb, line 122 def push_branch_first(origin, branch) p "push branch: #{branch} to origin: origin" git_repo.push('origin', branch) end
show_all_mrs()
click to toggle source
# File lib/glman/commands/base.rb, line 127 def show_all_mrs ap projects_repo.get_merge_requests(git_repo.repository_name) end
users_repo()
click to toggle source
# File lib/glman/commands/base.rb, line 135 def users_repo @users_repo ||= Repos::UsersRepo.new(configuration.get(:gitlab)) end