gh_issues 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b4408bd107953aa18e66a9564141c0c05e682808
4
+ data.tar.gz: c6dd87cc8d8e11ff9fb51d4701e9f508a531ceaa
5
+ SHA512:
6
+ metadata.gz: 83a80fdf5956e3c5f6fe40c8f2184f44093904b312165cfe88bde60a2e7eea92f15a0cadffd35af792e2f998075bbe32d3b14a2e59d59bb41d2e0840eeaf2dd7
7
+ data.tar.gz: 960d5a65caa9936ff5ba339558a8f18646007e1dcc239a927a778a826096bff1592777f01f9ee24731c4afdbe648c54db4de92babb8e8026fb15558799c79d31
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ .rbenv-vars
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.0
5
+ before_install: gem install bundler -v 1.12.5
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at ugurozyilmazel@gmail.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in gh_issues.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Uğur Özyılmazel
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,212 @@
1
+ ![Version](https://img.shields.io/badge/version-0.1.1-yellow.svg)
2
+
3
+ # GitHub Issues
4
+
5
+ Manage your GitHub issues from command-line. If you are dealing with huge
6
+ amount of repos, this tool will become more handy.
7
+
8
+ ## Idea
9
+
10
+ I need this tool for couple of reasons:
11
+
12
+ 1. I need to list all issues of my all repositories without knowing the repo url.
13
+ 1. I need to list a specific issue from a specific repo with full details.
14
+ 1. I need to see my current issues which are related to GitHub account.
15
+
16
+ ## Installation
17
+
18
+ This is a command-line client. You can install via:
19
+
20
+ ```bash
21
+ gem install gh_issues
22
+ ```
23
+
24
+ ## Usage
25
+
26
+ You need to create a [GitHub token](https://github.com/settings/tokens/new) or
27
+ use existing token of yours. Set your environment variable as:
28
+
29
+ ```bash
30
+ export GH_ISSUES_TOKEN=your-token-here
31
+ ```
32
+
33
+ If you like to get colored output by default, set:
34
+ ```bash
35
+ export GH_ISSUES_COLORIZE=1
36
+ ```
37
+
38
+ All commands:
39
+
40
+ ```bash
41
+ Commands:
42
+ gh_issues all # List all open issues, grouped by owner
43
+ gh_issues help [COMMAND] # Describe available commands or one specific command
44
+ gh_issues list OWNER_NAME # List issues belongs to owner
45
+ gh_issues show REPO_NAME [ISSUE_NUMBER] # Show issues of REPO_NAME or ISSUE
46
+ gh_issues version # Version information
47
+
48
+ Options:
49
+ [--color], [--no-color]
50
+ [--sort-by=count]
51
+ # Default: name
52
+ [--sort-order=desc]
53
+ # Default: asc
54
+ ```
55
+
56
+ ### all
57
+
58
+ Lists all repos with open issues. Here is my repos:
59
+
60
+ +------------------------------------------+-----------+
61
+ | f |
62
+ +------------------------------------------+-----------+
63
+ | f/atom-bootstrap3 | 23 |
64
+ +------------------------------------------+-----------+
65
+ | 23 |
66
+ +------------------------------------------+-----------+
67
+ | gelistiriciyiz-biz |
68
+ +------------------------------------------+-----------+
69
+ | gelistiriciyiz-biz/gelistiriciyiz.biz | 1 |
70
+ +------------------------------------------+-----------+
71
+ | 1 |
72
+ +------------------------------------------+-----------+
73
+ | pyistanbul |
74
+ +------------------------------------------+-----------+
75
+ | pyistanbul/docs | 1 |
76
+ | pyistanbul/itspython | 1 |
77
+ | pyistanbul/website | 10 |
78
+ +------------------------------------------+-----------+
79
+ | 12 |
80
+ +------------------------------------------+-----------+
81
+ | thoughtram |
82
+ +------------------------------------------+-----------+
83
+ | thoughtram/git-master-class-exercises | 1 |
84
+ +------------------------------------------+-----------+
85
+ | 1 |
86
+ +------------------------------------------+-----------+
87
+ | vigo |
88
+ +------------------------------------------+-----------+
89
+ | vigo/gh-issues-test | 4 |
90
+ | vigo/git-tips | 1 |
91
+ | vigo/ruby101-kitap | 1 |
92
+ | vigo/textmate-twitterbootstrap.tmbundle | 1 |
93
+ +------------------------------------------+-----------+
94
+ | 7 |
95
+ +------------------------------------------+-----------+
96
+ | webBoxio |
97
+ +------------------------------------------+-----------+
98
+ | webBoxio/atom-backbone | 3 |
99
+ | webBoxio/atom-color | 16 |
100
+ | webBoxio/atom-hashrocket | 4 |
101
+ | webBoxio/atom-html-preview | 47 |
102
+ | webBoxio/atom-htmlizer | 2 |
103
+ | webBoxio/atom-ios | 1 |
104
+ | webBoxio/atom-powersnap | 2 |
105
+ | webBoxio/playbook | 1 |
106
+ | webBoxio/ws-coffee | 1 |
107
+ +------------------------------------------+-----------+
108
+ | 77 |
109
+ +------------------------------------------+-----------+
110
+ | Total amount | 121 |
111
+ +------------------------------------------+-----------+
112
+
113
+ ### list
114
+
115
+ List single repo’s issues:
116
+
117
+ ```bash
118
+ gh_issues list pyistanbul
119
+
120
+ +----------------------+------+
121
+ | pyistanbul |
122
+ +----------------------+------+
123
+ | pyistanbul/docs | 1 |
124
+ | pyistanbul/itspython | 1 |
125
+ | pyistanbul/website | 10 |
126
+ +----------------------+------+
127
+ | 12 |
128
+ +----------------------+------+
129
+ | Total amount | 12 |
130
+ +----------------------+------+
131
+ ```
132
+
133
+ ### show
134
+
135
+ Show selected repo’s issues:
136
+
137
+ ```bash
138
+ gh_issues show pyistanbul/website
139
+
140
+ ```
141
+
142
+ Here is the list:
143
+
144
+ +-----+-----------------------------------------------------------------+-------------------------------------------------+
145
+ | | pyistanbul/website | Url |
146
+ +-----+-----------------------------------------------------------------+-------------------------------------------------+
147
+ | #53 | Sunum linkinin zorunlu olması | https://github.com/pyistanbul/website/issues/53 |
148
+ | #52 | [admin] Jobs listesinde pozisyon adı ve şirket adı listelenmeli | https://github.com/pyistanbul/website/issues/52 |
149
+ | #51 | [jobs] İlanı yayından kaldırmak için seçenek eklenmesi | https://github.com/pyistanbul/website/issues/51 |
150
+ | #49 | Sunum başvuruları için form | https://github.com/pyistanbul/website/issues/49 |
151
+ | #48 | Issue #5: Auth, Social Auth, Profile Sayfalari | https://github.com/pyistanbul/website/pull/48 |
152
+ | #47 | Sitenin database dump'ı? | https://github.com/pyistanbul/website/issues/47 |
153
+ | #46 | Sunumlar sayfasına etkinlik bilgilerinin entegre edimesi | https://github.com/pyistanbul/website/issues/46 |
154
+ | #43 | Sirketler tablo sayfasi | https://github.com/pyistanbul/website/issues/43 |
155
+ | #10 | Implement Facebook Open Graph meta tags | https://github.com/pyistanbul/website/issues/10 |
156
+ | #5 | Profil sayfası | https://github.com/pyistanbul/website/issues/5 |
157
+ +-----+-----------------------------------------------------------------+-------------------------------------------------+
158
+
159
+ If you pass **issue number** as parameter after repo name, you get the issue details:
160
+
161
+ ```bash
162
+ gh_issues show pyistanbul/website 48
163
+ ```
164
+ Result:
165
+
166
+ +------------+--------------------------------------------------------------------------------+
167
+ | Repo/Issue | pyistanbul/website/48 |
168
+ +------------+--------------------------------------------------------------------------------+
169
+ | Title | Issue #5: Auth, Social Auth, Profile Sayfalari |
170
+ +------------+--------------------------------------------------------------------------------+
171
+ | Opener | bahattincinic |
172
+ +------------+--------------------------------------------------------------------------------+
173
+ | Created at | 08 May 2015, 21:18, Friday (481 days ago) |
174
+ | Updated at | 19 May 2015, 14:11, Tuesday (470 days ago) |
175
+ +------------+--------------------------------------------------------------------------------+
176
+ | Body | [ ] Profil Guncelleme sayfasinin yapilmasi. |
177
+ | | [ ] Kullanici ile People merge edilmesi. |
178
+ | | People ile kullanici modelini view/template de merge edicektim ama cok hosuma |
179
+ | | gitmedi. acaba direk modeli ucursak da User tablosuna initial olarak koysak mi |
180
+ | | veya datamigration @berkerpeksag |
181
+ | | Yukaridaki 2 madde kaldi. Onlari yapiyim oyle merge ederiz. Bu arada yorum |
182
+ | | varsa da hemde tartismis oluruz. |
183
+ | | Yaptigim profil sayfasi su. Baya kotu oldu inline css falan yazdim. Fatihin |
184
+ | | ustunden gecmesi lazim :trollface: |
185
+ | | [screen shot 2015-05-07 at 11 19 31 pm ]-[link] |
186
+ +------------+--------------------------------------------------------------------------------+
187
+
188
+
189
+ ## Development
190
+
191
+ After checking out the repo, run `bin/setup` to install dependencies. Then,
192
+ run `rake test` to run the tests. You can also run `bin/console` for an
193
+ interactive prompt that will allow you to experiment.
194
+
195
+ To install this gem onto your local machine, run `bundle exec rake install`. To
196
+ release a new version, update the version number in `version.rb`, and then
197
+ run `bundle exec rake release`, which will create a git tag for the version,
198
+ push git commits and tags, and push the `.gem` file to
199
+ [rubygems.org](https://rubygems.org).
200
+
201
+ ## Contributing
202
+
203
+ Bug reports and pull requests are welcome on GitHub at
204
+ https://github.com/vigo/gh_issues. This project is intended to be a safe,
205
+ welcoming space for collaboration, and contributors are expected to adhere to
206
+ the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
207
+
208
+
209
+ ## License
210
+
211
+ The gem is available as open source under the terms of the
212
+ [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "gh_issues"
5
+ require "pry"
6
+ Pry.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install --path=vendor/bundle
7
+
8
+ # Do any other automated setup that you need to do here
data/exe/gh_issues ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../lib/gh_issues/cli'
4
+ GhIssues::CLI.start(ARGV)
data/gh_issues.gemspec ADDED
@@ -0,0 +1,33 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'gh_issues/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "gh_issues"
8
+ spec.version = GhIssues::VERSION
9
+ spec.authors = ["Uğur Özyılmazel"]
10
+ spec.email = ["ugurozyilmazel@gmail.com"]
11
+
12
+ spec.summary = %q{Manage your GitHub issues from command-line.}
13
+ spec.description = %q{Manage your GitHub issues from command-line.}
14
+ spec.homepage = "https://github.com/vigo/gh-issues"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency 'bundler', '~> 1.12'
23
+ spec.add_development_dependency 'rake', '~> 10.0'
24
+ spec.add_development_dependency 'minitest', '~> 5.0'
25
+ spec.add_development_dependency 'minitest-reporters', '~> 1.1', '>= 1.1.11'
26
+ spec.add_development_dependency 'pry', '~> 0.10.4'
27
+
28
+ spec.add_runtime_dependency 'terminal-table', '~> 1.6'
29
+ spec.add_runtime_dependency 'thor', '~> 0.19.1'
30
+ spec.add_runtime_dependency 'octokit', '~> 4.3'
31
+ spec.add_runtime_dependency 'time_difference', '~> 0.4.2'
32
+ spec.add_runtime_dependency 'redcarpet', '~> 3.3', '>= 3.3.4'
33
+ end
@@ -0,0 +1,192 @@
1
+ require "bundler/setup"
2
+
3
+ require 'thor'
4
+ require 'terminal-table'
5
+ require 'date'
6
+ require 'time_difference'
7
+ require 'redcarpet'
8
+ require 'redcarpet/render_strip'
9
+ require 'gh_issues'
10
+
11
+ TERMINAL_WIDTH = `tput cols`.strip.to_i
12
+ WRAP_TEXT_AT = 78
13
+
14
+ module GhIssues
15
+ class TextRenderer < Redcarpet::Render::StripDown
16
+ def image(link, title, content)
17
+ link = "link" if link.length > WRAP_TEXT_AT
18
+ content &&= content + " "
19
+ "[#{content}]-[#{link}]"
20
+ end
21
+ end
22
+
23
+ class CLI < Thor
24
+ class_option :color, :type => :boolean
25
+ class_option :sort_by, default: 'name', banner: "count"
26
+ class_option :sort_order, default: 'asc', banner: "desc"
27
+
28
+ desc "version", "Version information"
29
+ def version
30
+ puts GhIssues::VERSION
31
+ end
32
+
33
+ desc "all", "List all open issues, grouped by owner"
34
+ long_desc <<-LONGDESC
35
+ List all available repos with open issues according to your GitHub Token.
36
+ Do not forget to set your `GH_ISSUES_TOKEN` environment variable.\n
37
+
38
+ $ gh_issues all\n
39
+ $ gh_issues all --sort-by=count\n
40
+ $ gh_issues all --sort-by=count --sort-order=desc\n
41
+ $ gh_issues all --sort-by=count --sort-order=desc --color
42
+ LONGDESC
43
+ def all
44
+ ENV['GH_ISSUES_COLORIZE'] = '1' if options[:color]
45
+ sort_by = ['name', 'count'].include?(options[:sort_by]) ? options[:sort_by] : 'name'
46
+ sort_order = ['asc', 'desc'].include?(options[:sort_order]) ? options[:sort_order] : 'asc'
47
+ all_issues = GhIssues.all_issues
48
+ if all_issues.count > 0
49
+ puts print_issue_list(all_issues, sort_by: sort_by, sort_order: sort_order)
50
+ else
51
+ puts "Hooray! You have no issue to display..."
52
+ end
53
+ end
54
+
55
+ desc "list OWNER_NAME", "List issues belongs to owner"
56
+ long_desc <<-LONGDESC
57
+ List issues of selected repo. You need to get all issues first. You can
58
+ only list your repos issues.\n
59
+
60
+ $ gh_issues list pyistanbul\n
61
+ $ gh_issues list pyistanbul --sort-by=count\n
62
+ $ gh_issues list pyistanbul --sort-by=count --sort-order=desc\n
63
+ $ gh_issues list pyistanbul --sort-by=count --sort-order=desc --color
64
+ LONGDESC
65
+ def list(owner)
66
+ ENV['GH_ISSUES_COLORIZE'] = '1' if options[:color]
67
+ sort_by = ['name', 'count'].include?(options[:sort_by]) ? options[:sort_by] : 'name'
68
+ sort_order = ['asc', 'desc'].include?(options[:sort_order]) ? options[:sort_order] : 'asc'
69
+ begin
70
+ owner_issues = GhIssues.list_owner_issues(owner)
71
+ rescue GhIssues::InvalidOwnerError => error_message
72
+ puts error_message
73
+ exit
74
+ end
75
+ if owner_issues.count > 0
76
+ only_owners_data = {}
77
+ only_owners_data[owner] = owner_issues
78
+ puts print_issue_list(only_owners_data, sort_by: sort_by, sort_order: sort_order)
79
+ else
80
+ puts "Hooray! You have no issue to display..."
81
+ end
82
+ end
83
+
84
+ desc "show REPO_NAME [ISSUE_NUMBER]", "Show issues of REPO_NAME or ISSUE"
85
+ long_desc <<-LONGDESC
86
+ Show issues of selected repo. If you specify issue number, you'll get
87
+ details of that issue.\
88
+
89
+ $ gh_issues show pyistanbul/website
90
+ $ gh_issues show pyistanbul/website 48
91
+ $ gh_issues show pyistanbul/website 48 --color
92
+ LONGDESC
93
+ def show(repo, issue_number=0)
94
+ ENV['GH_ISSUES_COLORIZE'] = '1' if options[:color]
95
+ issue_number = issue_number.to_i
96
+
97
+ if issue_number > 0
98
+ issue = GhIssues.get_issue(repo, issue_number)
99
+ table = Terminal::Table.new do |t|
100
+ t.add_row [colorize("Repo/Issue", :yellow), colorize("#{repo}/#{issue_number}", :white)]
101
+ t.add_separator
102
+ t.add_row [colorize("Title", :yellow), issue[:title]]
103
+ t.add_separator
104
+ t.add_row [colorize("Opener", :yellow), issue[:user]]
105
+ t.add_row [colorize("Labes", :yellow), issue[:labels].join(',')] if issue[:labels].count > 0
106
+ t.add_row [colorize("Assignees", :yellow), issue[:assignees].join(', ')] if issue[:assignees].count > 0
107
+ t.add_separator
108
+
109
+ created_at = issue[:created_at].strftime("%d %B %Y, %H:%M, %A")
110
+ updated_at = issue[:updated_at].strftime("%d %B %Y, %H:%M, %A")
111
+
112
+ now = Time.now
113
+ created_at_diff = TimeDifference.between(now, issue[:created_at]).in_days.to_i
114
+ updated_at_diff = TimeDifference.between(now, issue[:updated_at]).in_days.to_i
115
+
116
+ t.add_row [colorize("Created at", :yellow), "#{created_at} (#{created_at_diff} days ago)"]
117
+ t.add_row [colorize("Updated at", :yellow), "#{updated_at} (#{updated_at_diff} days ago)"]
118
+ if issue[:body].length > 0
119
+ markdown = Redcarpet::Markdown.new(GhIssues::TextRenderer)
120
+ body_text = markdown.render(issue[:body])
121
+ t.add_separator
122
+ t.add_row [colorize("Body", :yellow), wrap(body_text, WRAP_TEXT_AT)]
123
+ end
124
+ end
125
+ puts table
126
+ else
127
+ issues = GhIssues.show_repos_issues(repo)
128
+ if issues.count > 0
129
+ table = Terminal::Table.new do |t|
130
+ t.add_row ["", colorize(repo, :yellow), colorize("Url", :yellow)]
131
+ t.add_separator
132
+ issues.each do |issue|
133
+ t.add_row [
134
+ {value: colorize("##{issue[:number]}", :white), alignment: :left},
135
+ issue[:title],
136
+ "#{issue[:html_url]}",
137
+ ]
138
+ end
139
+ end
140
+ puts table
141
+ else
142
+ puts "Hooray! You have no issue here..."
143
+ end
144
+ end
145
+ end
146
+
147
+ no_commands do
148
+ def print_issue_list(data, **options)
149
+ sort_by = options[:sort_by]
150
+ sort_order = options[:sort_order]
151
+ all_issues_sum = 0
152
+ table = Terminal::Table.new do |t|
153
+ data.each do |owner, items|
154
+ items.sort_by!{|item| item[:open_issues_count]} if sort_by == 'count'
155
+ items.reverse! if sort_order == 'desc'
156
+ t.add_row [{value: "#{colorize(owner, :yellow)}", colspan: 2, alignment: :center}]
157
+ t.add_separator
158
+ items.map{|item| t.add_row([colorize(item[:full_name], :cyan), {value: colorize(item[:open_issues_count], :white), alignment: :right}])}
159
+ issues_sum = items.map{|item| item[:open_issues_count]}.inject(0){|sum,x| sum + x }
160
+ all_issues_sum = all_issues_sum + issues_sum
161
+ t.add_separator
162
+ t.add_row [{value: colorize(issues_sum, :green), colspan: 2, alignment: :right}]
163
+ t.add_separator
164
+ end
165
+ end
166
+ table.add_row [colorize('Total amount', :white), {value: colorize(all_issues_sum, :white), alignment: :right}]
167
+ table
168
+ end
169
+
170
+ def wrap(s, width=WRAP_TEXT_AT)
171
+ s.gsub(/(.{1,#{width}})(\s+|\Z)/, "\\1\n")
172
+ end
173
+
174
+ def colorize(text, color)
175
+ if ENV['GH_ISSUES_COLORIZE']
176
+ set_color(text, color)
177
+ else
178
+ text
179
+ end
180
+ end
181
+
182
+ def pluralize(singular, plural, number)
183
+ if number > 1
184
+ plural
185
+ else
186
+ singular
187
+ end
188
+ end
189
+ end
190
+
191
+ end
192
+ end
@@ -0,0 +1,3 @@
1
+ module GhIssues
2
+ VERSION = "0.1.1"
3
+ end
data/lib/gh_issues.rb ADDED
@@ -0,0 +1,115 @@
1
+ require 'gh_issues/version'
2
+ require 'octokit'
3
+
4
+ module GhIssues
5
+ @@client = nil
6
+ class GitHubAccessTokenError < StandardError; end
7
+ class GitHubBadCredentialsError < StandardError; end
8
+ class InvalidOwnerError < StandardError; end
9
+
10
+ def self.check_ghi_token_defined
11
+ raise ::GhIssues::GitHubAccessTokenError, "Please define GH_ISSUES_TOKEN environment variable." unless ENV['GH_ISSUES_TOKEN']
12
+ end
13
+
14
+ def self.check_ghi_github_credentials
15
+ begin
16
+ user = @@client.user
17
+ rescue Octokit::Unauthorized => error_message
18
+ raise ::GhIssues::GitHubBadCredentialsError, "Bad GitHub credentials."
19
+ end
20
+ end
21
+
22
+ def self.ghi_access_available?
23
+ begin
24
+ ::GhIssues.check_ghi_token_defined
25
+ rescue ::GhIssues::GitHubAccessTokenError => error_message
26
+ puts error_message
27
+ exit
28
+ end
29
+
30
+ @@client = Octokit::Client.new(:access_token => ENV['GH_ISSUES_TOKEN'])
31
+ @@client.auto_paginate = true
32
+
33
+ begin
34
+ ::GhIssues.check_ghi_github_credentials
35
+ rescue ::GhIssues::GitHubBadCredentialsError => error_message
36
+ puts error_message
37
+ exit
38
+ end
39
+ true
40
+ end
41
+
42
+ def self.list_owner_issues(requested_owner)
43
+ if ::GhIssues.ghi_access_available?
44
+ all_issues = ::GhIssues.all_issues
45
+ if all_issues[requested_owner]
46
+ all_issues[requested_owner]
47
+ else
48
+ raise ::GhIssues::InvalidOwnerError, "Invalid owner requested"
49
+ exit
50
+ end
51
+ end
52
+ end
53
+
54
+ def self.show_repos_issues(repo)
55
+ if ::GhIssues.ghi_access_available?
56
+ begin
57
+ issues = []
58
+ @@client.issues(repo).each do |issue|
59
+ issues << {
60
+ number: issue[:number],
61
+ title: issue[:title],
62
+ html_url: issue[:html_url],
63
+ body: issue[:body],
64
+ }
65
+ end
66
+ issues
67
+ rescue Octokit::InvalidRepository => error_message
68
+ puts error_message
69
+ exit
70
+ end
71
+
72
+ end
73
+ end
74
+
75
+ def self.get_issue(repo, issue_number)
76
+ if ::GhIssues.ghi_access_available?
77
+ begin
78
+ issue = @@client.issue(repo, issue_number)
79
+ {
80
+ number: issue[:number],
81
+ title: issue[:title],
82
+ user: issue[:user][:login],
83
+ labels: issue[:labels].map{|i| i[:name]},
84
+ assignees: issue[:assignees].map{|i| i[:login]},
85
+ body: issue[:body],
86
+ created_at: issue[:created_at],
87
+ updated_at: issue[:updated_at],
88
+ }
89
+ rescue Octokit::NotFound => error_message
90
+ puts "Incorrect issue number (#{issue_number})"
91
+ exit
92
+ end
93
+
94
+ end
95
+ end
96
+
97
+ def self.all_issues
98
+ if ::GhIssues.ghi_access_available?
99
+ open_issues = {}
100
+ @@client.repos.each do |repo|
101
+ if repo[:open_issues_count] > 0
102
+ owner = repo[:owner][:login]
103
+ open_issues[owner] = [] unless open_issues[owner]
104
+ data = {
105
+ full_name: repo[:full_name],
106
+ open_issues_count: repo[:open_issues_count],
107
+ }
108
+ open_issues[owner] << data
109
+ end
110
+ end
111
+ open_issues
112
+ end
113
+
114
+ end
115
+ end
metadata ADDED
@@ -0,0 +1,211 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gh_issues
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Uğur Özyılmazel
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-09-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest-reporters
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.1'
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: 1.1.11
65
+ type: :development
66
+ prerelease: false
67
+ version_requirements: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - "~>"
70
+ - !ruby/object:Gem::Version
71
+ version: '1.1'
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: 1.1.11
75
+ - !ruby/object:Gem::Dependency
76
+ name: pry
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: 0.10.4
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: 0.10.4
89
+ - !ruby/object:Gem::Dependency
90
+ name: terminal-table
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: '1.6'
96
+ type: :runtime
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: '1.6'
103
+ - !ruby/object:Gem::Dependency
104
+ name: thor
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: 0.19.1
110
+ type: :runtime
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - "~>"
115
+ - !ruby/object:Gem::Version
116
+ version: 0.19.1
117
+ - !ruby/object:Gem::Dependency
118
+ name: octokit
119
+ requirement: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - "~>"
122
+ - !ruby/object:Gem::Version
123
+ version: '4.3'
124
+ type: :runtime
125
+ prerelease: false
126
+ version_requirements: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - "~>"
129
+ - !ruby/object:Gem::Version
130
+ version: '4.3'
131
+ - !ruby/object:Gem::Dependency
132
+ name: time_difference
133
+ requirement: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - "~>"
136
+ - !ruby/object:Gem::Version
137
+ version: 0.4.2
138
+ type: :runtime
139
+ prerelease: false
140
+ version_requirements: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - "~>"
143
+ - !ruby/object:Gem::Version
144
+ version: 0.4.2
145
+ - !ruby/object:Gem::Dependency
146
+ name: redcarpet
147
+ requirement: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - "~>"
150
+ - !ruby/object:Gem::Version
151
+ version: '3.3'
152
+ - - ">="
153
+ - !ruby/object:Gem::Version
154
+ version: 3.3.4
155
+ type: :runtime
156
+ prerelease: false
157
+ version_requirements: !ruby/object:Gem::Requirement
158
+ requirements:
159
+ - - "~>"
160
+ - !ruby/object:Gem::Version
161
+ version: '3.3'
162
+ - - ">="
163
+ - !ruby/object:Gem::Version
164
+ version: 3.3.4
165
+ description: Manage your GitHub issues from command-line.
166
+ email:
167
+ - ugurozyilmazel@gmail.com
168
+ executables:
169
+ - gh_issues
170
+ extensions: []
171
+ extra_rdoc_files: []
172
+ files:
173
+ - ".gitignore"
174
+ - ".travis.yml"
175
+ - CODE_OF_CONDUCT.md
176
+ - Gemfile
177
+ - LICENSE.txt
178
+ - README.md
179
+ - Rakefile
180
+ - bin/console
181
+ - bin/setup
182
+ - exe/gh_issues
183
+ - gh_issues.gemspec
184
+ - lib/gh_issues.rb
185
+ - lib/gh_issues/cli.rb
186
+ - lib/gh_issues/version.rb
187
+ homepage: https://github.com/vigo/gh-issues
188
+ licenses:
189
+ - MIT
190
+ metadata: {}
191
+ post_install_message:
192
+ rdoc_options: []
193
+ require_paths:
194
+ - lib
195
+ required_ruby_version: !ruby/object:Gem::Requirement
196
+ requirements:
197
+ - - ">="
198
+ - !ruby/object:Gem::Version
199
+ version: '0'
200
+ required_rubygems_version: !ruby/object:Gem::Requirement
201
+ requirements:
202
+ - - ">="
203
+ - !ruby/object:Gem::Version
204
+ version: '0'
205
+ requirements: []
206
+ rubyforge_project:
207
+ rubygems_version: 2.5.1
208
+ signing_key:
209
+ specification_version: 4
210
+ summary: Manage your GitHub issues from command-line.
211
+ test_files: []