Class: GHI::Commands::Open
Constant Summary
Constants included from Formatting
Formatting::CURSOR, Formatting::THROBBERS
Constants included from Formatting::Colors
Formatting::Colors::ANSI, Formatting::Colors::WEB
Instance Attribute Summary collapse
-
#editor ⇒ Object
Returns the value of attribute editor.
-
#web ⇒ Object
Returns the value of attribute web.
Attributes inherited from Command
Attributes included from Formatting
Instance Method Summary collapse
Methods inherited from Command
#api, #assigns, execute, #initialize, #repo, #repo=
Methods included from Formatting
#columns, #dimensions, #format_comment, #format_comment_editor, #format_comments_and_events, #format_date, #format_editor, #format_event, #format_event_type, #format_issue, #format_issues, #format_issues_header, #format_labels, #format_markdown, #format_milestone, #format_milestone_editor, #format_milestones, #format_number, #format_state, #format_tag, #format_username, #indent, #page, #paginate?, #paging?, #past_due?, #percent, #puts, #throb, #truncate
Methods included from Formatting::Colors
#bg, #blink, #bright, #colorize?, colorize?, #fg, #highlight, #inverse, #no_color, #to_hex, #underline
Constructor Details
This class inherits a constructor from GHI::Commands::Command
Instance Attribute Details
#editor ⇒ Object
Returns the value of attribute editor.
4 5 6 |
# File 'lib/ghi/commands/open.rb', line 4 def editor @editor end |
#web ⇒ Object
Returns the value of attribute web.
5 6 7 |
# File 'lib/ghi/commands/open.rb', line 5 def web @web end |
Instance Method Details
#execute ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/ghi/commands/open.rb', line 52 def execute require_repo self.action = 'create' .parse! args if GHI.config('ghi.infer-issue') != 'false' && extract_issue Edit.execute args.push('-so', issue, '--', repo) exit end case action when 'index' if assigns.key? :assignee args.unshift assigns[:assignee] if assigns[:assignee] args.unshift '-u' end args.unshift '-w' if web List.execute args.push('--', repo) when 'create' if web Web.new(repo).open 'issues/new' else unless args.empty? assigns[:title], assigns[:body] = args.join(' '), assigns[:title] end assigns[:title] = args.join ' ' unless args.empty? if assigns[:title].nil? || editor e = Editor.new 'GHI_ISSUE' = e.gets format_editor(assigns) e.unlink "There's no issue?" if .nil? || .empty? assigns[:title], assigns[:body] = .split(/\n+/, 2) end i = throb { api.post "/repos/#{repo}/issues", assigns }.body e.unlink if e puts format_issue(i) puts "Opened on #{repo}." end end rescue Client::Error => e raise unless error = e.errors.first abort "%s %s %s %s." % [ error['resource'], error['field'], [*error['value']].join(', '), error['code'] ] end |
#options ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/ghi/commands/open.rb', line 7 def OptionParser.new do |opts| opts. = <<EOF usage: ghi open [options] or: ghi reopen [options] <issueno> EOF opts.separator '' opts.on '-l', '--list', 'list open tickets' do self.action = 'index' end opts.on('-w', '--web') { self.web = true } opts.separator '' opts.separator 'Issue modification options' opts.on( '-m', '--message [<text>]', 'describe issue', "use line breaks to separate title from description" ) do |text| if text assigns[:title], assigns[:body] = text.split(/\n+/, 2) else self.editor = true end end opts.on( '-u', '--[no-]assign [<user>]', 'assign to specified user' ) do |assignee| assigns[:assignee] = assignee end opts.on '--claim', 'assign to yourself' do assigns[:assignee] = Authorization.username end opts.on( '-M', '--milestone <n>', 'associate with milestone' ) do |milestone| assigns[:milestone] = milestone end opts.on( '-L', '--label <labelname>...', Array, 'associate with label(s)' ) do |labels| (assigns[:labels] ||= []).concat labels end opts.separator '' end end |