class GHI::Commands::Command
Attributes
detected_repo[RW]
action[RW]
args[R]
issue[W]
verbose[RW]
Public Class Methods
execute(args)
click to toggle source
# File lib/ghi/commands/command.rb, line 12 def execute args command = new args if i = args.index('--') command.repo = args.slice!(i, args.length)[1] # Raise if too many? end command.execute end
new(args)
click to toggle source
# File lib/ghi/commands/command.rb, line 26 def initialize args @args = args.map! { |a| a.dup } end
Public Instance Methods
api()
click to toggle source
# File lib/ghi/commands/command.rb, line 34 def api @api ||= Client.new end
assigns()
click to toggle source
# File lib/ghi/commands/command.rb, line 30 def assigns @assigns ||= {} end
repo()
click to toggle source
# File lib/ghi/commands/command.rb, line 38 def repo return @repo if defined? @repo @repo = GHI.config('ghi.repo', :flags => '--local') || detect_repo if @repo && !@repo.include?('/') @repo = [Authorization.username, @repo].join '/' end @repo end
Also aliased as: extract_repo
repo=(repo)
click to toggle source
# File lib/ghi/commands/command.rb, line 48 def repo= repo @repo = repo.dup unless @repo.include? '/' @repo.insert 0, "#{Authorization.username}/" end @repo end
Private Instance Methods
any_or_none_or(input)
click to toggle source
Handles, e.g. ‘–[no-]milestone [<n>]`.
# File lib/ghi/commands/command.rb, line 124 def any_or_none_or input input ? input : { nil => '*', false => 'none' }[input] end
detect_repo()
click to toggle source
# File lib/ghi/commands/command.rb, line 76 def detect_repo remote = remotes.find { |r| r[:remote] == 'upstream' } remote ||= remotes.find { |r| r[:remote] == 'origin' } remote ||= remotes.find { |r| r[:user] == Authorization.username } Command.detected_repo = true and remote[:repo] if remote end
infer_issue_from_branch_prefix()
click to toggle source
# File lib/ghi/commands/command.rb, line 110 def infer_issue_from_branch_prefix @issue = `git symbolic-ref --short HEAD 2>/dev/null`[/^\d+/]; warn "(Inferring issue from branch prefix: ##@issue)" if @issue end
issue()
click to toggle source
# File lib/ghi/commands/command.rb, line 97 def issue return @issue if defined? @issue if index = args.index { |arg| /^\d+$/ === arg } @issue = args.delete_at index else infer_issue_from_branch_prefix end @issue end
remotes()
click to toggle source
# File lib/ghi/commands/command.rb, line 83 def remotes return @remotes if defined? @remotes @remotes = `git config --get-regexp remote\..+\.url`.split "\n" github_host = GHI.config('github.host') || 'github.com' @remotes.reject! { |r| !r.include? github_host} @remotes.map! { |r| remote, user, repo = r.scan( %r{remote\.([^\.]+)\.url .*?([^:/]+)/([^/\s]+?)(?:\.git)?$} ).flatten { :remote => remote, :user => user, :repo => "#{user}/#{repo}" } } @remotes end
require_issue()
click to toggle source
# File lib/ghi/commands/command.rb, line 115 def require_issue raise MissingArgument, 'Issue required.' unless issue end
require_milestone()
click to toggle source
# File lib/ghi/commands/command.rb, line 119 def require_milestone raise MissingArgument, 'Milestone required.' unless milestone end
require_repo()
click to toggle source
# File lib/ghi/commands/command.rb, line 58 def require_repo return true if repo warn 'Not a GitHub repo.' warn '' abort options.to_s end
require_repo_name()
click to toggle source
# File lib/ghi/commands/command.rb, line 65 def require_repo_name require_repo repo_array = repo.partition "/" if repo_array.length >= 2 repo_name = repo_array[2] else repo_name = nil end return repo_name end
sort_by_creation(arr)
click to toggle source
# File lib/ghi/commands/command.rb, line 128 def sort_by_creation(arr) arr.sort_by { |el| el['created_at'] } end