ghi 0.2.0 → 1.2.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.
data/lib/ghi.rb CHANGED
@@ -1,55 +1,167 @@
1
- require "net/http"
2
- require "yaml"
1
+ require 'optparse'
3
2
 
4
3
  module GHI
5
- VERSION = "0.2"
4
+ autoload :Authorization, 'ghi/authorization'
5
+ autoload :Client, 'ghi/client'
6
+ autoload :Commands, 'ghi/commands'
7
+ autoload :Editor, 'ghi/editor'
8
+ autoload :Formatting, 'ghi/formatting'
9
+ autoload :Web, 'ghi/web'
6
10
 
7
11
  class << self
8
- def login
9
- return @login if defined? @login
10
- @login = `git config --get github.user`.chomp
11
- if @login.empty?
12
- begin
13
- print "Please enter your GitHub username: "
14
- @login = gets.chomp
15
- valid = user? @login
16
- warn "invalid username" unless valid
17
- end until valid
18
- `git config --global github.user #@login`
12
+ def execute args
13
+ STDOUT.sync = true
14
+
15
+ double_dash = args.index { |arg| arg == '--' }
16
+ if index = args.index { |arg| arg !~ /^-/ }
17
+ if double_dash.nil? || index < double_dash
18
+ command_name = args.delete_at index
19
+ command_args = args.slice! index, args.length
20
+ end
19
21
  end
20
- @login
21
- end
22
+ command_args ||= []
23
+
24
+ option_parser = OptionParser.new do |opts|
25
+ opts.banner = <<EOF
26
+ usage: ghi [--version] [-p|--paginate|--no-pager] [--help] <command> [<args>]
27
+ [ -- [<user>/]<repo>]
28
+ EOF
29
+ opts.on('--version') { command_name = 'version' }
30
+ opts.on '-p', '--paginate', '--[no-]pager' do |paginate|
31
+ GHI::Formatting.paginate = paginate
32
+ end
33
+ opts.on '--help' do
34
+ command_args.unshift(*args)
35
+ command_args.unshift command_name if command_name
36
+ args.clear
37
+ command_name = 'help'
38
+ end
39
+ opts.on '--[no-]color' do |colorize|
40
+ Formatting::Colors.colorize = colorize
41
+ end
42
+ opts.on '-l' do
43
+ if command_name
44
+ raise OptionParser::InvalidOption
45
+ else
46
+ command_name = 'list'
47
+ end
48
+ end
49
+ opts.on '-v' do
50
+ command_name ? self.v = true : command_name = 'version'
51
+ end
52
+ opts.on('-V') { command_name = 'version' }
53
+ end
54
+
55
+ begin
56
+ option_parser.parse! args
57
+ rescue OptionParser::InvalidOption => e
58
+ warn e.message.capitalize
59
+ abort option_parser.banner
60
+ end
61
+
62
+ if command_name.nil?
63
+ command_name = 'list'
64
+ end
65
+
66
+ if command_name == 'help'
67
+ Commands::Help.execute command_args, option_parser.banner
68
+ else
69
+ command_name = fetch_alias command_name, command_args
70
+ begin
71
+ command = Commands.const_get command_name.capitalize
72
+ rescue NameError
73
+ abort "ghi: '#{command_name}' is not a ghi command. See 'ghi --help'."
74
+ end
75
+
76
+ # Post-command help option parsing.
77
+ Commands::Help.execute [command_name] if command_args.first == '--help'
22
78
 
23
- def token
24
- return @token if defined? @token
25
- @token = `git config --get github.token`.chomp
26
- if @token.empty?
27
79
  begin
28
- print "GitHub token (https://github.com/account): "
29
- @token = gets.chomp
30
- valid = token? @token
31
- warn "invalid token for #{login}" unless valid
32
- end until valid
33
- `git config --global github.token #@token`
80
+ command.execute command_args
81
+ rescue OptionParser::ParseError, Commands::MissingArgument => e
82
+ warn "#{e.message.capitalize}\n"
83
+ abort command.new([]).options.to_s
84
+ rescue Client::Error => e
85
+ if e.response.is_a?(Net::HTTPNotFound) && Authorization.token.nil?
86
+ raise Authorization::Required
87
+ else
88
+ abort e.message
89
+ end
90
+ rescue SocketError => e
91
+ abort "Couldn't find internet."
92
+ rescue Errno::ECONNREFUSED, Errno::ETIMEDOUT => e
93
+ abort "Couldn't find GitHub."
94
+ end
95
+ end
96
+ rescue Authorization::Required => e
97
+ retry if Authorization.authorize!
98
+ warn e.message
99
+ if Authorization.token
100
+ warn <<EOF.chomp
101
+
102
+ Not authorized for this action with your token. To regenerate a new token:
103
+ EOF
34
104
  end
35
- @token
105
+ warn <<EOF
106
+
107
+ Please run 'ghi config --auth <username>'
108
+ EOF
109
+ exit 1
110
+ end
111
+
112
+ def config key, options = {}
113
+ upcase = options.fetch :upcase, true
114
+ flags = options[:flags]
115
+ var = key.gsub('core', 'git').gsub '.', '_'
116
+ var.upcase! if upcase
117
+ value = ENV[var] || `git config #{flags} #{key}`
118
+ value = `#{value[1..-1]}` if value.start_with? '!'
119
+ value = value.chomp
120
+ value unless value.empty?
36
121
  end
37
122
 
123
+ attr_accessor :v
124
+ alias v? v
125
+
38
126
  private
39
127
 
40
- def user?(username)
41
- url = "http://github.com/api/v2/yaml/user/show/#{username}"
42
- !YAML.load(Net::HTTP.get(URI.parse(url)))["user"].nil?
43
- rescue ArgumentError, URI::InvalidURIError
44
- false
45
- end
128
+ ALIASES = Hash.new { |_, key|
129
+ [key] if /^\d+$/ === key
130
+ }.update(
131
+ 'claim' => %w(assign),
132
+ 'create' => %w(open),
133
+ 'e' => %w(edit),
134
+ 'l' => %w(list),
135
+ 'L' => %w(label),
136
+ 'm' => %w(comment),
137
+ 'M' => %w(milestone),
138
+ 'new' => %w(open),
139
+ 'o' => %w(open),
140
+ 'reopen' => %w(open),
141
+ 'rm' => %w(close),
142
+ 's' => %w(show),
143
+ 'st' => %w(list),
144
+ 'tag' => %w(label),
145
+ 'unassign' => %w(assign -d),
146
+ 'update' => %w(edit)
147
+ )
148
+
149
+ def fetch_alias command, args
150
+ return command unless fetched = ALIASES[command]
151
+
152
+ # If the <command> is an issue number, check the options to see if an
153
+ # edit or show is desired.
154
+ if fetched.first =~ /^\d+$/
155
+ edit_options = Commands::Edit.new([]).options.top.list
156
+ edit_options.reject! { |arg| !arg.is_a?(OptionParser::Switch) }
157
+ edit_options.map! { |arg| [arg.short, arg.long] }
158
+ edit_options.flatten!
159
+ fetched.unshift((edit_options & args).empty? ? 'show' : 'edit')
160
+ end
46
161
 
47
- def token?(token)
48
- url = "http://github.com/api/v2/yaml/user/show/#{login}"
49
- url += "?login=#{login}&token=#{token}"
50
- !YAML.load(Net::HTTP.get(URI.parse(url)))["user"]["plan"].nil?
51
- rescue ArgumentError, NoMethodError, URI::InvalidURIError
52
- false
162
+ command = fetched.shift
163
+ args.unshift(*fetched)
164
+ command
53
165
  end
54
166
  end
55
167
  end
metadata CHANGED
@@ -1,70 +1,112 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: ghi
3
- version: !ruby/object:Gem::Version
4
- version: 0.2.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.2.0
5
5
  platform: ruby
6
- authors:
6
+ authors:
7
7
  - Stephen Celis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
-
12
- date: 2009-11-03 00:00:00 -06:00
13
- default_executable: ghi
14
- dependencies: []
15
-
16
- description: GitHub Issues on the command line. Use your `$EDITOR`, not your browser.
17
- email:
18
- - stephen@stephencelis.com
19
- executables:
11
+ date: 2016-04-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: pygments.rb
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: ronn
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: |
56
+ GitHub Issues on the command line. Use your `$EDITOR`, not your browser.
57
+ email: stephen@stephencelis.com
58
+ executables:
20
59
  - ghi
21
60
  extensions: []
22
-
23
- extra_rdoc_files:
24
- - History.rdoc
25
- - Manifest.txt
26
- - README.rdoc
27
- files:
28
- - History.rdoc
29
- - Manifest.txt
30
- - README.rdoc
61
+ extra_rdoc_files: []
62
+ files:
31
63
  - bin/ghi
32
- - lib/ghi/api.rb
33
- - lib/ghi/cli.rb
34
- - lib/ghi/issue.rb
35
64
  - lib/ghi.rb
36
- - spec/ghi/api_spec.rb
37
- - spec/ghi/cli_spec.rb
38
- - spec/ghi/issue_spec.rb
39
- - spec/ghi_spec.rb
40
- has_rdoc: true
41
- homepage: http://github.com/stephencelis/ghi
42
- licenses: []
43
-
65
+ - lib/ghi/authorization.rb
66
+ - lib/ghi/client.rb
67
+ - lib/ghi/commands.rb
68
+ - lib/ghi/commands/assign.rb
69
+ - lib/ghi/commands/close.rb
70
+ - lib/ghi/commands/command.rb
71
+ - lib/ghi/commands/comment.rb
72
+ - lib/ghi/commands/config.rb
73
+ - lib/ghi/commands/disable.rb
74
+ - lib/ghi/commands/edit.rb
75
+ - lib/ghi/commands/enable.rb
76
+ - lib/ghi/commands/help.rb
77
+ - lib/ghi/commands/label.rb
78
+ - lib/ghi/commands/list.rb
79
+ - lib/ghi/commands/milestone.rb
80
+ - lib/ghi/commands/open.rb
81
+ - lib/ghi/commands/show.rb
82
+ - lib/ghi/commands/status.rb
83
+ - lib/ghi/commands/version.rb
84
+ - lib/ghi/editor.rb
85
+ - lib/ghi/formatting.rb
86
+ - lib/ghi/formatting/colors.rb
87
+ - lib/ghi/web.rb
88
+ homepage: https://github.com/stephencelis/ghi
89
+ licenses:
90
+ - MIT
91
+ metadata: {}
44
92
  post_install_message:
45
- rdoc_options:
46
- - --main
47
- - README.rdoc
48
- require_paths:
93
+ rdoc_options: []
94
+ require_paths:
49
95
  - lib
50
- required_ruby_version: !ruby/object:Gem::Requirement
51
- requirements:
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
52
98
  - - ">="
53
- - !ruby/object:Gem::Version
54
- version: "0"
55
- version:
56
- required_rubygems_version: !ruby/object:Gem::Requirement
57
- requirements:
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
58
103
  - - ">="
59
- - !ruby/object:Gem::Version
60
- version: "0"
61
- version:
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
62
106
  requirements: []
63
-
64
- rubyforge_project: ghi
65
- rubygems_version: 1.3.5
107
+ rubyforge_project:
108
+ rubygems_version: 2.4.6
66
109
  signing_key:
67
- specification_version: 3
68
- summary: GitHub Issues on the command line
110
+ specification_version: 4
111
+ summary: GitHub Issues command line interface
69
112
  test_files: []
70
-
data/History.rdoc DELETED
@@ -1,180 +0,0 @@
1
- === 0.2.0 / 2009-11-03
2
-
3
- * Major-minor release!
4
-
5
- * Cleanup! (Better help, warnings and errors.)
6
-
7
-
8
- === 0.1.7 / 2009-08-26
9
-
10
- * 2 bugfixes
11
-
12
- * Allow dots in repo names.
13
- * Fix bug preventing invocation from non-GitHub repo directories.
14
-
15
-
16
- === 0.1.6 / 2009-08-05
17
-
18
- * 1 minor enhancement
19
-
20
- * Support for non-"origin" remotes.
21
-
22
-
23
- * 1 bugfix
24
-
25
- * Graceful offline error.
26
-
27
-
28
- === 0.1.5 / 2009-07-08
29
-
30
- * 2 bugfixes
31
-
32
- * Long titles should wrap in show/verbose issue view.
33
- * If a non-OptionParser argument fails early, re-parse when valid.
34
-
35
-
36
- === 0.1.4 / 2009-05-15
37
-
38
- * 1 minor enhancement
39
-
40
- * Minor Windows support.
41
-
42
-
43
- === 0.1.3 / 2009-05-08
44
-
45
- * 1 minor enhancement
46
-
47
- * Fix bug where `more' was being passed `less' options.
48
- * Fix scoping of commands so `ghi user/repo` can run outside of a repo
49
- directory.
50
-
51
-
52
- === 0.1.2 / 2009-05-07
53
-
54
- * 1 major enhancement
55
-
56
- * Better fallbacks. Enter `ghi open`, `ghi list closed`, `ghi search term`,
57
- `ghi show 2`, `ghi user/repo`, etc., it will try to work. Fallbacks do not
58
- accept options, though.
59
-
60
-
61
- === 0.1.1 / 2009-05-01
62
-
63
- * 3 major enhancements
64
-
65
- * Use `more' (or $GHI_PAGER) to accommodate lengthy output.
66
- * Default to "-l" if Dir.pwd is a git repo.
67
- * Accept numbered args/flags to shortcut "show" (e.g., "ghi -2", "ghi 2")
68
-
69
-
70
- * 1 minor enhancement
71
-
72
- * Update --url flag to GitHub's new convention.
73
-
74
-
75
- === 0.1.0 / 2009-04-27
76
-
77
- * 2 major enhancements
78
-
79
- * Use tempfiles when we should, the gitdir otherwise.
80
- * Now a minor!
81
-
82
-
83
- * 2 minor enhancement
84
-
85
- * Small ANSI tweaks.
86
- * Truncation fix.
87
-
88
-
89
- === 0.0.9 / 2009-04-27
90
-
91
- * 1 major enhancement
92
-
93
- * ANSI colors (honors your .gitconfig).
94
-
95
-
96
- * 1 minor enhancement
97
-
98
- * Bugfixes.
99
-
100
-
101
- === 0.0.8 / 2009-04-26
102
-
103
- * 1 major enhancement
104
-
105
- * Flag to return issues URLs.
106
-
107
-
108
- * 1 minor enhancement
109
-
110
- * Preliminary specs for top-level module and API class.
111
-
112
-
113
- === 0.0.7 / 2009-04-25
114
-
115
- * 1 major enhancement
116
-
117
- * Labels! Label and un-label at your whim.
118
-
119
-
120
- * 1 minor enhancement
121
-
122
- * Tail arguments are sometimes parsed. E.g., ghi -om "Issue message parsed".
123
-
124
-
125
- === 0.0.6 / 2009-04-25
126
-
127
- * 2 minor enhancements
128
-
129
- * Accept comments as arguments in more places.
130
- * Update error message to accommodate both issues and comments.
131
-
132
-
133
- === 0.0.5 / 2009-04-25
134
-
135
- * 3 major enhancements
136
-
137
- * Flag to claim/label issues with your GitHub username (thanks, Jamie).
138
- * Flag for commenting on issues.
139
- * Prompt for GitHub login and token if absent from gitconfig.
140
-
141
-
142
- * 1 minor enhancement
143
-
144
- * Opening issues with a title bypasses your $EDITOR.
145
-
146
-
147
- === 0.0.4 / 2009-04-24
148
-
149
- * 1 major enhancement
150
-
151
- * Cache messages created in $EDITOR.
152
-
153
-
154
- * 2 minor enhancements
155
-
156
- * Refactoring and cleanup.
157
- * Change editing messages.
158
-
159
-
160
- === 0.0.3 / 2009-04-23
161
-
162
- * 2 minor enhancements
163
-
164
- * Typo corrected.
165
- * README updated.
166
-
167
-
168
- === 0.0.2 / 2009-04-22
169
-
170
- * 1 major enhancement
171
-
172
- * Add --search flag.
173
- * Add --repo flag.
174
-
175
-
176
- === 0.0.1 / 2009-04-21
177
-
178
- * 1 major enhancement
179
-
180
- * Birthday!
data/Manifest.txt DELETED
@@ -1,14 +0,0 @@
1
- History.rdoc
2
- Manifest.txt
3
- MIT-LICENSE
4
- Rakefile
5
- README.rdoc
6
- bin/ghi
7
- lib/ghi/api.rb
8
- lib/ghi/cli.rb
9
- lib/ghi/issue.rb
10
- lib/ghi.rb
11
- spec/ghi/api_spec.rb
12
- spec/ghi/cli_spec.rb
13
- spec/ghi/issue_spec.rb
14
- spec/ghi_spec.rb
data/README.rdoc DELETED
@@ -1,92 +0,0 @@
1
- = ghi
2
-
3
- http://github.com/stephencelis/ghi
4
-
5
-
6
- GitHub Issues on the command line. Use your <tt>$EDITOR</tt>, not your
7
- browser.
8
-
9
- == HOW?
10
-
11
- Get:
12
-
13
- % gem install stephencelis-ghi --source=http://gems.github.com
14
-
15
-
16
- Go:
17
-
18
- Usage: ghi [options]
19
- -l, --list [state|term|number]
20
- --search, --show
21
- -v, --verbose
22
- -o, --open [title|number]
23
- --reopen
24
- -c, --closed, --close [number]
25
- -e, --edit [number]
26
- -r, --repo, --repository [name]
27
- -m, --comment [number|comment]
28
- -t, --label [number] [label]
29
- --claim [number]
30
- -d, --unlabel [number] [label]
31
- -u, --url [state|number]
32
- --[no-]color
33
- --[no-]pager
34
- -V, --version
35
- -h, --help
36
-
37
-
38
- == EXAMPLE?
39
-
40
- ghi works simply from within a repository. Some short examples:
41
-
42
- ghi -l # Lists all open issues
43
- ghi # Shorter shorthand for "ghi -l"
44
- ghi -v # Lists all open issues, verbosely (includes body)
45
- ghi -lc # Lists all closed issues
46
- ghi -l "doesn't work" # Searches for open issues matching "doesn't work"
47
- ghi -l invalid -c # Searches for closed issues matching "invalid"
48
- ghi -l1 # Shows issue 1
49
- ghi -1 # Shorter shorthand for "ghi -l1"
50
- ghi 1 # Shorter shorthand still
51
- ghi -o # Opens a new issue (in your $EDITOR)
52
- ghi -o "New issue" # Opens a new issue with the title "New issue"
53
- ghi -o "Title" -m "Body" # Opens a new issue with specified title and body
54
- ghi -e1 # Edits issue number 1 (in your $EDITOR)
55
- ghi -e1 -m "New body" # Edits issue number 1 with the specified body
56
- ghi -c1 # Closes issue 1
57
- ghi -c1 -m # Closes issue with comment (from your $EDITOR)
58
- ghi -c1 -m "Comment" # Closes issue with specified comment
59
- ghi -o1 # Reopens 1 (accepts comments, too)
60
- ghi -m1 # Comments on issue 1 (in your $EDITOR)
61
- ghi -t1 "tag" # Labels issue 1 with "tag"
62
- ghi -d1 "tag" # Removes the label, "tag"
63
- ghi --claim 1 # Tags issue 1 with your GitHub username
64
- ghi -u # Loads issues in your browser.
65
- ghi -u1 # Loads an issue in your browser.
66
-
67
-
68
- ghi also works anywhere:
69
-
70
- ghi -rghi # Your fork of "ghi"
71
- ghi -rstephencelis/ghi # Mine: "stephencelis/ghi"
72
- ghi stephencelis/ghi # Shorthand to merely list open.
73
-
74
-
75
- ghi uses ANSI colors if you use them in git.
76
-
77
- ghi looks for a <tt>$GHI_PAGER</tt> variable for paging.
78
-
79
-
80
- == CONTRIBUTORS
81
-
82
- * Jamie Macey (http://blog.tracefunc.com)
83
- * Hiroshi Nakamura (http://github.com/nahi)
84
-
85
-
86
- === CONTRIBUTE?
87
-
88
- ghi is not under currently under the control of any gem packaging system. To
89
- build, use RubyGems:
90
-
91
- % gem build ghi.gemspec
92
- % sudo gem install ghi*.gem