githuh 0.1.0 → 0.1.2
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.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +24 -0
- data/.gitignore +1 -2
- data/.rspec +1 -0
- data/Gemfile +1 -2
- data/Gemfile.lock +64 -1
- data/README.md +81 -4
- data/Rakefile +6 -9
- data/WARRANTY.md +7 -0
- data/docs/img/coverage.svg +19 -0
- data/exe/githuh +1 -1
- data/githuh.gemspec +8 -2
- data/lib/githuh.rb +67 -1
- data/lib/githuh/cli/commands/base.rb +76 -6
- data/lib/githuh/cli/commands/repo/list.rb +92 -32
- data/lib/githuh/cli/commands/user/info.rb +2 -1
- data/lib/githuh/cli/launcher.rb +62 -0
- data/lib/githuh/version.rb +5 -0
- metadata +77 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3b4517eedc84850ed85b10e50952ffc26302a915d023f2c165dafeaa8b357534
|
|
4
|
+
data.tar.gz: 2f723bd311807a98a62c6e8bf5438386a02907ff81cfc1ef1e35cb686aa1b346
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8a664c0091551871d5105c80ad0ad4e09f1fb6b3111d073519064ed4d26b13318e61d11277c0c2d03c9b49198b53c16f181191ac9c6091fb8707f0c90599b7bd
|
|
7
|
+
data.tar.gz: d7888af02067237199ad0bab8880c643370c7f23645ee36e2dbfdd5deb771b32808d274dca4f669937b968b1f5b684098194acfd5ab807be14cafb5a0db1511d
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
name: Ruby
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [ master ]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [ master ]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
build:
|
|
11
|
+
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
|
|
14
|
+
steps:
|
|
15
|
+
- uses: actions/checkout@v2
|
|
16
|
+
- name: Set up Ruby 2.6
|
|
17
|
+
uses: actions/setup-ruby@v1
|
|
18
|
+
with:
|
|
19
|
+
ruby-version: 2.6.x
|
|
20
|
+
- name: Build and test with Rake
|
|
21
|
+
run: |
|
|
22
|
+
gem install bundler
|
|
23
|
+
bundle install --jobs 4 --retry 3
|
|
24
|
+
bundle exec rspec
|
data/.gitignore
CHANGED
data/.rspec
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
|
@@ -1,28 +1,66 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
githuh (0.1.
|
|
4
|
+
githuh (0.1.2)
|
|
5
5
|
colored2 (~> 3)
|
|
6
6
|
dry-cli (~> 0.6)
|
|
7
7
|
octokit (~> 4)
|
|
8
|
+
tty-box (~> 0.5)
|
|
9
|
+
tty-progressbar
|
|
8
10
|
|
|
9
11
|
GEM
|
|
10
12
|
remote: https://rubygems.org/
|
|
11
13
|
specs:
|
|
12
14
|
addressable (2.7.0)
|
|
13
15
|
public_suffix (>= 2.0.2, < 5.0)
|
|
16
|
+
aruba (1.0.0)
|
|
17
|
+
childprocess (~> 3.0)
|
|
18
|
+
contracts (~> 0.16.0)
|
|
19
|
+
cucumber (>= 2.4, < 4.0)
|
|
20
|
+
ffi (~> 1.9)
|
|
21
|
+
rspec-expectations (~> 3.4)
|
|
22
|
+
thor (~> 1.0)
|
|
14
23
|
awesome_print (1.8.0)
|
|
24
|
+
backports (3.16.1)
|
|
25
|
+
builder (3.2.4)
|
|
26
|
+
childprocess (3.0.0)
|
|
15
27
|
colored2 (3.1.2)
|
|
16
28
|
concurrent-ruby (1.1.6)
|
|
29
|
+
contracts (0.16.0)
|
|
30
|
+
cucumber (3.1.2)
|
|
31
|
+
builder (>= 2.1.2)
|
|
32
|
+
cucumber-core (~> 3.2.0)
|
|
33
|
+
cucumber-expressions (~> 6.0.1)
|
|
34
|
+
cucumber-wire (~> 0.0.1)
|
|
35
|
+
diff-lcs (~> 1.3)
|
|
36
|
+
gherkin (~> 5.1.0)
|
|
37
|
+
multi_json (>= 1.7.5, < 2.0)
|
|
38
|
+
multi_test (>= 0.1.2)
|
|
39
|
+
cucumber-core (3.2.1)
|
|
40
|
+
backports (>= 3.8.0)
|
|
41
|
+
cucumber-tag_expressions (~> 1.1.0)
|
|
42
|
+
gherkin (~> 5.0)
|
|
43
|
+
cucumber-expressions (6.0.1)
|
|
44
|
+
cucumber-tag_expressions (1.1.1)
|
|
45
|
+
cucumber-wire (0.0.1)
|
|
17
46
|
diff-lcs (1.3)
|
|
47
|
+
docile (1.3.2)
|
|
18
48
|
dry-cli (0.6.0)
|
|
19
49
|
concurrent-ruby (~> 1.0)
|
|
50
|
+
equatable (0.6.1)
|
|
20
51
|
faraday (1.0.0)
|
|
21
52
|
multipart-post (>= 1.2, < 3)
|
|
53
|
+
ffi (1.12.2)
|
|
54
|
+
gherkin (5.1.0)
|
|
55
|
+
multi_json (1.14.1)
|
|
56
|
+
multi_test (0.1.2)
|
|
22
57
|
multipart-post (2.1.1)
|
|
23
58
|
octokit (4.17.0)
|
|
24
59
|
faraday (>= 0.9)
|
|
25
60
|
sawyer (~> 0.8.0, >= 0.5.3)
|
|
61
|
+
pastel (0.7.3)
|
|
62
|
+
equatable (~> 0.6)
|
|
63
|
+
tty-color (~> 0.5)
|
|
26
64
|
public_suffix (4.0.3)
|
|
27
65
|
rake (13.0.1)
|
|
28
66
|
rspec (3.9.0)
|
|
@@ -44,17 +82,42 @@ GEM
|
|
|
44
82
|
sawyer (0.8.2)
|
|
45
83
|
addressable (>= 2.3.5)
|
|
46
84
|
faraday (> 0.8, < 2.0)
|
|
85
|
+
simplecov (0.18.5)
|
|
86
|
+
docile (~> 1.1)
|
|
87
|
+
simplecov-html (~> 0.11)
|
|
88
|
+
simplecov-formatter-badge (0.1.0)
|
|
89
|
+
simplecov-html (0.12.2)
|
|
90
|
+
strings (0.1.8)
|
|
91
|
+
strings-ansi (~> 0.1)
|
|
92
|
+
unicode-display_width (~> 1.5)
|
|
93
|
+
unicode_utils (~> 1.4)
|
|
94
|
+
strings-ansi (0.2.0)
|
|
95
|
+
thor (1.0.1)
|
|
96
|
+
tty-box (0.5.0)
|
|
97
|
+
pastel (~> 0.7.2)
|
|
98
|
+
strings (~> 0.1.6)
|
|
99
|
+
tty-cursor (~> 0.7)
|
|
100
|
+
tty-color (0.5.1)
|
|
101
|
+
tty-cursor (0.7.1)
|
|
102
|
+
tty-progressbar (0.11.0)
|
|
103
|
+
tty-screen (~> 0.5.0)
|
|
104
|
+
tty-screen (0.5.1)
|
|
105
|
+
unicode-display_width (1.7.0)
|
|
106
|
+
unicode_utils (1.4.0)
|
|
47
107
|
|
|
48
108
|
PLATFORMS
|
|
49
109
|
ruby
|
|
50
110
|
|
|
51
111
|
DEPENDENCIES
|
|
112
|
+
aruba (= 1.0.0)
|
|
52
113
|
awesome_print (~> 1)
|
|
53
114
|
bundler (~> 2)
|
|
54
115
|
githuh!
|
|
55
116
|
rake (~> 13)
|
|
56
117
|
rspec (~> 3)
|
|
57
118
|
rspec-its (~> 1)
|
|
119
|
+
simplecov
|
|
120
|
+
simplecov-formatter-badge
|
|
58
121
|
|
|
59
122
|
BUNDLED WITH
|
|
60
123
|
2.1.2
|
data/README.md
CHANGED
|
@@ -1,8 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+

|
|
2
|
+

|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
# Githuh — GitHub API client
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
As in... **git? huh?**.
|
|
7
|
+
|
|
8
|
+
Github API client wrapper on top of Octokit, that provides extensible command pattern for wrapping Github functionality.
|
|
9
|
+
|
|
10
|
+
At the moment two features are implemented:
|
|
11
|
+
|
|
12
|
+
* Generating a list of org's (or personal) repositories and rending in either markdown or JSON
|
|
13
|
+
* Printing info of the logged in user.
|
|
14
|
+
|
|
15
|
+
## Using `githuh`
|
|
6
16
|
|
|
7
17
|
Add your Github Token to the global config:
|
|
8
18
|
|
|
@@ -13,7 +23,74 @@ git config --global --set user.token <token>
|
|
|
13
23
|
After that:
|
|
14
24
|
|
|
15
25
|
```bash
|
|
16
|
-
|
|
26
|
+
❯ githuh
|
|
27
|
+
Commands:
|
|
28
|
+
githuh repo [SUBCOMMAND]
|
|
29
|
+
githuh user [SUBCOMMAND]
|
|
30
|
+
githuh version # Print version
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Githuh works by implement subcomands:
|
|
34
|
+
|
|
35
|
+
### `repo list`
|
|
36
|
+
|
|
37
|
+
#### Motivation
|
|
38
|
+
|
|
39
|
+
This functionality was born out of the need to generate a brief but comprehensive, well-formatted list of prior inventions for a typical employment contract.
|
|
40
|
+
|
|
41
|
+
> NOTE: nothing in this library constitutes a legal advice. Use it at your own risk. For more information, please see [WARRANTY](WARANTY.md).
|
|
42
|
+
|
|
43
|
+
Please watch the following Ascii Screen cast to see this command in action:
|
|
44
|
+
|
|
45
|
+
[](https://asciinema.org/a/CW8NbYfu9RsifQJVU6tKRtRkU)
|
|
46
|
+
|
|
47
|
+
#### Usage
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
❯ githuh repo list --help
|
|
51
|
+
|
|
52
|
+
Githuh CLI 0.1.2 — API client for Github.com.
|
|
53
|
+
© 2020 Konstantin Gredeskoul, All rights reserved. MIT License.
|
|
54
|
+
|
|
55
|
+
Usage:
|
|
56
|
+
githuh repo list
|
|
57
|
+
|
|
58
|
+
Description:
|
|
59
|
+
List owned repositories and render the output in markdown or JSON
|
|
60
|
+
Default output file is <username>.repositories.<format>
|
|
61
|
+
|
|
62
|
+
Options:
|
|
63
|
+
--api-token=VALUE # Github API token; if not given, user.token is read from ~/.gitconfig
|
|
64
|
+
--per-page=VALUE # Pagination page size for Github API, default: 20
|
|
65
|
+
--[no-]info # Print UI elements, like a the progress bar, default: true
|
|
66
|
+
--[no-]verbose # Print additional debugging info, default: false
|
|
67
|
+
--file=VALUE # Output file, overrides <username>.repositories.<format>
|
|
68
|
+
--format=VALUE # Output format: (markdown/json), default: "markdown"
|
|
69
|
+
--forks=VALUE # Include or exclude forks: (exclude/include/only), default: "exclude"
|
|
70
|
+
--[no-]private # If specified, returns only private repos for true, public for false
|
|
71
|
+
--help, -h # Print this help
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
#### Example
|
|
75
|
+
|
|
76
|
+
For instance, to generate a markdown list of all of your **public** repos that are also **not forks**, run the following:
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
$ githuh repo list --format=markdown --no-private --forks=exclude --file=repos.md
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### `user info`
|
|
83
|
+
|
|
84
|
+
This command prints the info about currently authenticated user.
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
❯ githuh user info
|
|
88
|
+
{
|
|
89
|
+
:login => "kigster",
|
|
90
|
+
:url => "https://api.github.com/users/kigster",
|
|
91
|
+
:html_url => "https://github.com/kigster",
|
|
92
|
+
..............
|
|
93
|
+
|
|
17
94
|
```
|
|
18
95
|
|
|
19
96
|
## Copyright
|
data/Rakefile
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'bundler/gem_tasks'
|
|
2
4
|
require 'rspec/core/rake_task'
|
|
3
5
|
require 'timeout'
|
|
@@ -11,22 +13,17 @@ task :clean do
|
|
|
11
13
|
shell('rm -rf pkg/ tmp/ coverage/ doc/ ' )
|
|
12
14
|
end
|
|
13
15
|
|
|
14
|
-
task :
|
|
16
|
+
task gem: [:build] do
|
|
15
17
|
shell('gem install pkg/*')
|
|
16
18
|
end
|
|
17
19
|
|
|
18
|
-
task :
|
|
20
|
+
task permissions: [:clean] do
|
|
19
21
|
shell("chmod -v o+r,g+r * */* */*/* */*/*/* */*/*/*/* */*/*/*/*/*")
|
|
20
22
|
shell("find . -type d -exec chmod o+x,g+x {} \\;")
|
|
21
23
|
end
|
|
22
24
|
|
|
23
|
-
task :
|
|
25
|
+
task build: :permissions
|
|
24
26
|
|
|
25
27
|
RSpec::Core::RakeTask.new(:spec)
|
|
26
28
|
|
|
27
|
-
task :
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
29
|
+
task default: :spec
|
data/WARRANTY.md
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# WARRANTY CLAUSE
|
|
2
|
+
|
|
3
|
+
EXCEPT AS REPRESENTED IN THIS AGREEMENT, ALL WORK PRODUCT BY DEVELOPER IS PROVIDED "AS IS".
|
|
4
|
+
OTHER THAN AS PROVIDED IN THIS AGREEMENT, DEVELOPER MAKES NO OTHER WARRANTIES, EXPRESS OR
|
|
5
|
+
IMPLIED, AND HEREBY DISCLAIMS ALL IMPLIED WARRANTIES, INCLUDING ANY WARRANTY OF
|
|
6
|
+
MERCHANTABILITY AND WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE.
|
|
7
|
+
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="94" height="20">
|
|
2
|
+
<linearGradient id="b" x2="0" y2="100%">
|
|
3
|
+
<stop offset="0" stop-color="#bbb" stop-opacity=".1"/>
|
|
4
|
+
<stop offset="1" stop-opacity=".1"/>
|
|
5
|
+
</linearGradient>
|
|
6
|
+
<clipPath id="a">
|
|
7
|
+
<rect width="94" height="20" rx="3" fill="#fff"/>
|
|
8
|
+
</clipPath>
|
|
9
|
+
<g clip-path="url(#a)">
|
|
10
|
+
<path fill="#555" d="M0 0h59v20H0z"/>
|
|
11
|
+
<path fill="#e05d44" d="M59 0h35v20H59z"/>
|
|
12
|
+
<path fill="url(#b)" d="M0 0h94v20H0z"/>
|
|
13
|
+
</g>
|
|
14
|
+
<g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="110">
|
|
15
|
+
<text x="305" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="490">coverage</text>
|
|
16
|
+
<text x="305" y="140" transform="scale(.1)" textLength="490">coverage</text>
|
|
17
|
+
<text x="755" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="250">67%</text>
|
|
18
|
+
<text x="755" y="140" transform="scale(.1)" textLength="250">67%</text></g>
|
|
19
|
+
</svg>
|
data/exe/githuh
CHANGED
data/githuh.gemspec
CHANGED
|
@@ -2,11 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
lib = File.expand_path('lib', __dir__)
|
|
4
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
5
|
-
|
|
5
|
+
|
|
6
|
+
require_relative 'lib/githuh/version'
|
|
6
7
|
|
|
7
8
|
Gem::Specification.new do |spec|
|
|
8
9
|
spec.name = 'githuh'
|
|
9
|
-
spec.version =
|
|
10
|
+
spec.version = Githuh::VERSION
|
|
10
11
|
spec.authors = ['Konstantin Gredeskoul']
|
|
11
12
|
spec.email = %w(kigster@gmail.com)
|
|
12
13
|
|
|
@@ -26,10 +27,15 @@ Gem::Specification.new do |spec|
|
|
|
26
27
|
spec.add_dependency 'colored2', '~> 3'
|
|
27
28
|
spec.add_dependency 'dry-cli', '~> 0.6'
|
|
28
29
|
spec.add_dependency 'octokit', '~> 4'
|
|
30
|
+
spec.add_dependency 'tty-box', '~> 0.5'
|
|
31
|
+
spec.add_dependency 'tty-progressbar'
|
|
29
32
|
|
|
33
|
+
spec.add_development_dependency 'aruba', '= 1.0.0'
|
|
30
34
|
spec.add_development_dependency 'awesome_print', '~> 1'
|
|
31
35
|
spec.add_development_dependency 'bundler', '~> 2'
|
|
32
36
|
spec.add_development_dependency 'rake', '~> 13'
|
|
33
37
|
spec.add_development_dependency 'rspec', '~> 3'
|
|
34
38
|
spec.add_development_dependency 'rspec-its', '~> 1'
|
|
39
|
+
spec.add_development_dependency 'simplecov'
|
|
40
|
+
spec.add_development_dependency 'simplecov-formatter-badge'
|
|
35
41
|
end
|
data/lib/githuh.rb
CHANGED
|
@@ -6,9 +6,13 @@
|
|
|
6
6
|
require 'octokit'
|
|
7
7
|
require 'colored2'
|
|
8
8
|
require 'dry/cli'
|
|
9
|
+
require 'forwardable'
|
|
10
|
+
|
|
11
|
+
require_relative 'githuh/version'
|
|
9
12
|
|
|
10
13
|
module Githuh
|
|
11
|
-
|
|
14
|
+
BANNER = "Githuh Version #{VERSION}"
|
|
15
|
+
BINARY = File.expand_path('../exe/githuh', __dir__).freeze
|
|
12
16
|
|
|
13
17
|
module CLI
|
|
14
18
|
module Commands
|
|
@@ -17,6 +21,68 @@ module Githuh
|
|
|
17
21
|
end
|
|
18
22
|
end
|
|
19
23
|
|
|
24
|
+
require 'githuh/cli/launcher'
|
|
25
|
+
|
|
26
|
+
module Githuh
|
|
27
|
+
class << self
|
|
28
|
+
attr_accessor :launcher, :in_test
|
|
29
|
+
|
|
30
|
+
extend Forwardable
|
|
31
|
+
|
|
32
|
+
def_delegators :launcher, :stdout, :stderr, :stdin, :kernel, :argv
|
|
33
|
+
|
|
34
|
+
def configure_kernel_behavior!(help: false)
|
|
35
|
+
Kernel.module_eval do
|
|
36
|
+
alias original_exit exit
|
|
37
|
+
alias original_puts puts
|
|
38
|
+
alias original_warn warn
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
Kernel.module_eval do
|
|
42
|
+
def puts(*args)
|
|
43
|
+
::Githuh.stdout.puts(*args)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def warn(*args)
|
|
47
|
+
::Githuh.stderr.puts(*args)
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
if in_test
|
|
52
|
+
Kernel.module_eval do
|
|
53
|
+
def exit(code)
|
|
54
|
+
::Githuh.stderr.puts("RSpec: intercepted exit code: #{code}")
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
elsif help
|
|
58
|
+
Kernel.module_eval do
|
|
59
|
+
def exit(_code)
|
|
60
|
+
# for help, override default exit code with 0
|
|
61
|
+
original_exit(0)
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
else
|
|
65
|
+
Kernel.module_eval do
|
|
66
|
+
def exit(code)
|
|
67
|
+
original_exit(code)
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
Dry::CLI
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def restore_kernel_behavior!
|
|
76
|
+
Kernel.module_eval do
|
|
77
|
+
alias exit original_exit
|
|
78
|
+
alias puts original_puts
|
|
79
|
+
alias warn original_warn
|
|
80
|
+
alias exit original_exit
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
20
86
|
require 'githuh/cli/commands/base'
|
|
21
87
|
require 'githuh/cli/commands/user/info'
|
|
22
88
|
require 'githuh/cli/commands/version'
|
|
@@ -1,39 +1,109 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require 'tty/box'
|
|
4
|
+
require 'stringio'
|
|
5
|
+
require 'githuh/version'
|
|
6
|
+
require 'forwardable'
|
|
7
|
+
|
|
3
8
|
module Githuh
|
|
4
9
|
module CLI
|
|
5
10
|
module Commands
|
|
6
|
-
DEFAULT_PAGE_SIZE =
|
|
11
|
+
DEFAULT_PAGE_SIZE = 20
|
|
7
12
|
|
|
8
13
|
class Base < Dry::CLI::Command
|
|
14
|
+
extend Forwardable
|
|
15
|
+
|
|
16
|
+
def_delegators :context, :stdout, :stderr, :stdin, :kernel, :argv
|
|
17
|
+
|
|
9
18
|
class << self
|
|
10
19
|
def inherited(base)
|
|
11
20
|
super
|
|
12
21
|
base.instance_eval do
|
|
13
22
|
option :api_token, required: false, desc: "Github API token; if not given, user.token is read from ~/.gitconfig"
|
|
14
23
|
option :per_page, required: false, default: DEFAULT_PAGE_SIZE, desc: "Pagination page size for Github API"
|
|
15
|
-
option :
|
|
16
|
-
|
|
24
|
+
option :info, type: :boolean, default: true, desc: 'Print UI elements, like a the progress bar'
|
|
25
|
+
option :verbose, type: :boolean, default: false, desc: 'Print additional debugging info'
|
|
17
26
|
end
|
|
18
27
|
end
|
|
19
28
|
end
|
|
20
29
|
|
|
21
|
-
attr_accessor :client, :token, :per_page, :verbose
|
|
30
|
+
attr_accessor :client, :token, :per_page, :verbose, :info, :box, :context
|
|
22
31
|
|
|
23
32
|
def call(api_token: nil,
|
|
24
33
|
per_page: DEFAULT_PAGE_SIZE,
|
|
25
|
-
verbose:
|
|
34
|
+
verbose: false,
|
|
35
|
+
info: true)
|
|
26
36
|
|
|
37
|
+
self.context = Githuh
|
|
27
38
|
self.verbose = verbose
|
|
39
|
+
self.info = info
|
|
28
40
|
self.token = api_token || token_from_gitconfig
|
|
29
41
|
self.per_page = per_page || DEFAULT_PAGE_SIZE
|
|
30
42
|
self.client = Octokit::Client.new(access_token: token)
|
|
43
|
+
|
|
44
|
+
print_userinfo if info
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
protected
|
|
48
|
+
|
|
49
|
+
def puts(*args)
|
|
50
|
+
stdout.puts(*args)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def warn(*args)
|
|
54
|
+
stderr.puts(*args)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def user_info
|
|
58
|
+
@user_info ||= client.user
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def ui_width
|
|
62
|
+
80
|
|
31
63
|
end
|
|
32
64
|
|
|
33
65
|
private
|
|
34
66
|
|
|
67
|
+
def print_userinfo
|
|
68
|
+
duration = DateTime.now - DateTime.parse(user_info[:created_at].to_s)
|
|
69
|
+
years = (duration / 365).to_i
|
|
70
|
+
months = ((duration - years * 365) / 30).to_i
|
|
71
|
+
days = (duration - years * 365 - months * 30).to_i
|
|
72
|
+
|
|
73
|
+
lines = []
|
|
74
|
+
lines << sprintf(" Github API Token: %s", h("#{token[0..9]}#{'.' * 20}#{token[-11..-1]}"))
|
|
75
|
+
lines << sprintf(" Current User: %s", h(user_info.login))
|
|
76
|
+
lines << sprintf(" Public Repos: %s", h(user_info.public_repos.to_s))
|
|
77
|
+
lines << sprintf(" Followers: %s", h(user_info.followers.to_s))
|
|
78
|
+
lines << sprintf(" Member For: %s", h(sprintf("%d years, %d months, %d days", years, months, days)))
|
|
79
|
+
|
|
80
|
+
self.box = TTY::Box.frame *lines,
|
|
81
|
+
padding: 1,
|
|
82
|
+
width: ui_width,
|
|
83
|
+
align: :left,
|
|
84
|
+
title: { top_center: Githuh::BANNER },
|
|
85
|
+
style: {
|
|
86
|
+
fg: :white,
|
|
87
|
+
border: {
|
|
88
|
+
fg: :bright_green
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
Githuh.stdout.print box
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def h(arg)
|
|
96
|
+
arg.to_s.bold.blue
|
|
97
|
+
end
|
|
98
|
+
|
|
35
99
|
def token_from_gitconfig
|
|
36
|
-
`git config --global --get user.token`.chomp
|
|
100
|
+
@token_from_gitconfig ||= `git config --global --get user.token`.chomp
|
|
101
|
+
|
|
102
|
+
return @token_from_gitconfig unless @token_from_gitconfig.empty?
|
|
103
|
+
|
|
104
|
+
raise "No token was found in your ~/.gitconfig.\n" \
|
|
105
|
+
"To add, run the following command: \n" \
|
|
106
|
+
"git config --global --set user.token YOUR_GITHUB_TOKEN"
|
|
37
107
|
end
|
|
38
108
|
end
|
|
39
109
|
end
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
require 'bundler/setup'
|
|
6
6
|
require 'dry/cli'
|
|
7
7
|
require 'json'
|
|
8
|
+
require 'tty/progressbar'
|
|
8
9
|
|
|
9
10
|
require_relative '../base'
|
|
10
11
|
|
|
@@ -13,67 +14,100 @@ module Githuh
|
|
|
13
14
|
module Commands
|
|
14
15
|
module Repo
|
|
15
16
|
class List < Base
|
|
16
|
-
FORMATS
|
|
17
|
-
|
|
17
|
+
FORMATS = {
|
|
18
|
+
markdown: 'md',
|
|
19
|
+
json: 'json'
|
|
20
|
+
}.freeze
|
|
18
21
|
|
|
19
|
-
|
|
22
|
+
DEFAULT_FORMAT = :markdown
|
|
23
|
+
DEFAULT_OUTPUT_FORMAT = "<username>.repositories.<format>"
|
|
24
|
+
FORK_OPTIONS = %w(exclude include only).freeze
|
|
20
25
|
|
|
21
|
-
|
|
26
|
+
attr_accessor :filename, :file, :output, :repos, :format, :forks, :private, :record_count
|
|
22
27
|
|
|
23
|
-
|
|
24
|
-
|
|
28
|
+
desc "List owned repositories and render the output in markdown or JSON\n" \
|
|
29
|
+
" Default output file is " + DEFAULT_OUTPUT_FORMAT.bold.yellow
|
|
30
|
+
|
|
31
|
+
option :file, required: false, desc: 'Output file, overrides ' + DEFAULT_OUTPUT_FORMAT
|
|
32
|
+
option :format, values: FORMATS.keys, default: DEFAULT_FORMAT.to_s, required: false, desc: 'Output format'
|
|
25
33
|
option :forks, type: :string, values: FORK_OPTIONS, default: FORK_OPTIONS.first, required: false, desc: 'Include or exclude forks'
|
|
34
|
+
option :private, type: :boolean, default: nil, required: false, desc: 'If specified, returns only private repos for true, public for false'
|
|
26
35
|
|
|
27
|
-
def call(file: nil, format: nil, forks: nil, **opts)
|
|
36
|
+
def call(file: nil, format: nil, forks: nil, private: nil, **opts)
|
|
28
37
|
super(**opts)
|
|
29
38
|
|
|
30
|
-
self.
|
|
31
|
-
self.
|
|
32
|
-
self.
|
|
33
|
-
self.
|
|
34
|
-
self.
|
|
35
|
-
self.
|
|
36
|
-
|
|
39
|
+
self.record_count = 0
|
|
40
|
+
self.forks = forks
|
|
41
|
+
self.private = private
|
|
42
|
+
self.repos = []
|
|
43
|
+
self.output = StringIO.new
|
|
44
|
+
self.format = (format || DEFAULT_FORMAT).to_sym
|
|
45
|
+
|
|
46
|
+
self.filename = file || "#{user_info.login}.repositories.#{FORMATS[self.format]}"
|
|
47
|
+
self.file = File.open(filename, 'w')
|
|
48
|
+
|
|
49
|
+
puts
|
|
50
|
+
puts TTY::Box.info("Format : #{self.format}\n" \
|
|
51
|
+
"File : #{filename}\n" \
|
|
52
|
+
"Forks : #{self.forks}\n",
|
|
53
|
+
width: ui_width,
|
|
54
|
+
padding: 1)
|
|
55
|
+
puts
|
|
56
|
+
# —————————— actually get all repositories ———————————————
|
|
37
57
|
self.file.write send("render_as_#{format}", repositories)
|
|
58
|
+
# ————————————————————————————————————————————————————————
|
|
59
|
+
|
|
60
|
+
puts
|
|
61
|
+
puts TTY::Box.info("Success: written a total of #{record_count} records to #{filename}",
|
|
62
|
+
width: ui_width, padding: 1)
|
|
63
|
+
puts
|
|
38
64
|
ensure
|
|
39
65
|
file.close if file.respond_to?(:close) && !file.closed?
|
|
40
66
|
end
|
|
41
67
|
|
|
42
|
-
private
|
|
43
|
-
|
|
44
68
|
def repositories
|
|
45
69
|
page = 0
|
|
70
|
+
bar = nil
|
|
71
|
+
|
|
46
72
|
[].tap do |repo_list|
|
|
47
73
|
loop do
|
|
48
|
-
print '.'.green if verbose
|
|
49
74
|
options = {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
75
|
+
page: page,
|
|
76
|
+
per_page: per_page,
|
|
77
|
+
type: :owner,
|
|
53
78
|
}
|
|
54
79
|
|
|
55
80
|
result = client.repos({}, query: options)
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
!r.fork
|
|
62
|
-
when 'include'
|
|
63
|
-
false
|
|
64
|
-
end
|
|
65
|
-
end
|
|
81
|
+
bar = create_progress_bar if info && !verbose && page == 0
|
|
82
|
+
|
|
83
|
+
bar&.advance
|
|
84
|
+
filter_result!(result)
|
|
85
|
+
|
|
66
86
|
break if result.empty?
|
|
67
87
|
|
|
68
|
-
result.
|
|
88
|
+
result.each { |repo| printf "%s\n", repo.name } if verbose
|
|
69
89
|
|
|
70
90
|
repo_list << result
|
|
91
|
+
|
|
71
92
|
page += 1
|
|
93
|
+
|
|
94
|
+
self.record_count += result.size
|
|
72
95
|
end
|
|
73
|
-
|
|
96
|
+
|
|
97
|
+
bar&.finish; puts
|
|
74
98
|
end.flatten.sort_by(&:stargazers_count).reverse.uniq(&:name)
|
|
75
99
|
end
|
|
76
100
|
|
|
101
|
+
def create_progress_bar
|
|
102
|
+
number_of_pages = client.last_response.rels[:last].href.match(/page=(\d+).*$/)[1]
|
|
103
|
+
TTY::ProgressBar.new("[:bar]",
|
|
104
|
+
title: 'Fetching Repositories',
|
|
105
|
+
total: number_of_pages.to_i,
|
|
106
|
+
width: ui_width - 2,
|
|
107
|
+
head: '',
|
|
108
|
+
complete: '▉'.magenta)
|
|
109
|
+
end
|
|
110
|
+
|
|
77
111
|
def render_as_markdown(repositories)
|
|
78
112
|
output.puts "### #{client.user.name}'s Repos\n"
|
|
79
113
|
repositories.each_with_index do |repo, index|
|
|
@@ -98,6 +132,32 @@ module Githuh
|
|
|
98
132
|
|
|
99
133
|
REPO
|
|
100
134
|
end
|
|
135
|
+
|
|
136
|
+
private
|
|
137
|
+
|
|
138
|
+
def filter_result!(result)
|
|
139
|
+
result.reject! do |r|
|
|
140
|
+
fork_reject = case forks
|
|
141
|
+
when 'exclude'
|
|
142
|
+
r.fork
|
|
143
|
+
when 'only'
|
|
144
|
+
!r.fork
|
|
145
|
+
when 'include'
|
|
146
|
+
false
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
private_reject = case private
|
|
150
|
+
when true
|
|
151
|
+
!r.private
|
|
152
|
+
when false
|
|
153
|
+
r.private
|
|
154
|
+
when nil
|
|
155
|
+
false
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
fork_reject || private_reject
|
|
159
|
+
end
|
|
160
|
+
end
|
|
101
161
|
end
|
|
102
162
|
end
|
|
103
163
|
|
|
@@ -6,6 +6,7 @@ require "bundler/setup"
|
|
|
6
6
|
require "dry/cli"
|
|
7
7
|
require_relative '../base'
|
|
8
8
|
require 'awesome_print'
|
|
9
|
+
require 'json'
|
|
9
10
|
|
|
10
11
|
module Githuh
|
|
11
12
|
module CLI
|
|
@@ -16,7 +17,7 @@ module Githuh
|
|
|
16
17
|
|
|
17
18
|
def call(**opts)
|
|
18
19
|
super(**opts)
|
|
19
|
-
|
|
20
|
+
puts JSON.pretty_generate(client.user.to_hash)
|
|
20
21
|
end
|
|
21
22
|
end
|
|
22
23
|
end
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'dry/cli'
|
|
4
|
+
require 'forwardable'
|
|
5
|
+
require 'tty/box'
|
|
6
|
+
|
|
7
|
+
module Githuh
|
|
8
|
+
module CLI
|
|
9
|
+
class Launcher
|
|
10
|
+
attr_accessor :argv, :stdin, :stdout, :stderr, :kernel
|
|
11
|
+
|
|
12
|
+
def initialize(argv, stdin = STDIN, stdout = STDOUT, stderr = STDERR, kernel = nil)
|
|
13
|
+
if ::Githuh.launcher
|
|
14
|
+
raise(ArgumentError, "Another instance of CLI Launcher was detected, aborting.")
|
|
15
|
+
else
|
|
16
|
+
Githuh.launcher = self
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
self.argv = argv
|
|
20
|
+
self.stdin = stdin
|
|
21
|
+
self.stdout = stdout
|
|
22
|
+
self.stderr = stderr
|
|
23
|
+
self.kernel = kernel
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def execute!
|
|
27
|
+
if argv.empty? || !(%w(--help -h) & argv).empty?
|
|
28
|
+
stdout.puts <<~BANNER
|
|
29
|
+
|
|
30
|
+
#{'Githuh CLI'.bold.yellow} #{::Githuh::VERSION.bold.green} — API client for Github.com.
|
|
31
|
+
#{'© 2020 Konstantin Gredeskoul, All rights reserved. MIT License.'.cyan}
|
|
32
|
+
|
|
33
|
+
BANNER
|
|
34
|
+
|
|
35
|
+
Githuh.configure_kernel_behavior! help: true
|
|
36
|
+
else
|
|
37
|
+
Githuh.configure_kernel_behavior!
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
::Dry::CLI.new(Commands).call(arguments: argv, out: stdout, err: stderr)
|
|
41
|
+
rescue StandardError => e
|
|
42
|
+
box = TTY::Box.frame('ERROR:', ' ',
|
|
43
|
+
e.message,
|
|
44
|
+
padding: 1,
|
|
45
|
+
align: :left,
|
|
46
|
+
title: { top_center: Githuh::BANNER },
|
|
47
|
+
width: 80,
|
|
48
|
+
style: {
|
|
49
|
+
bg: :red,
|
|
50
|
+
border: {
|
|
51
|
+
fg: :bright_yellow,
|
|
52
|
+
bg: :red
|
|
53
|
+
}
|
|
54
|
+
})
|
|
55
|
+
stderr.print box
|
|
56
|
+
ensure
|
|
57
|
+
Githuh.restore_kernel_behavior!
|
|
58
|
+
exit(10) unless Githuh.in_test
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: githuh
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Konstantin Gredeskoul
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2020-03-
|
|
11
|
+
date: 2020-03-18 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: colored2
|
|
@@ -52,6 +52,48 @@ dependencies:
|
|
|
52
52
|
- - "~>"
|
|
53
53
|
- !ruby/object:Gem::Version
|
|
54
54
|
version: '4'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: tty-box
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - "~>"
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '0.5'
|
|
62
|
+
type: :runtime
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - "~>"
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '0.5'
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: tty-progressbar
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - ">="
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '0'
|
|
76
|
+
type: :runtime
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - ">="
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '0'
|
|
83
|
+
- !ruby/object:Gem::Dependency
|
|
84
|
+
name: aruba
|
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
|
86
|
+
requirements:
|
|
87
|
+
- - '='
|
|
88
|
+
- !ruby/object:Gem::Version
|
|
89
|
+
version: 1.0.0
|
|
90
|
+
type: :development
|
|
91
|
+
prerelease: false
|
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
93
|
+
requirements:
|
|
94
|
+
- - '='
|
|
95
|
+
- !ruby/object:Gem::Version
|
|
96
|
+
version: 1.0.0
|
|
55
97
|
- !ruby/object:Gem::Dependency
|
|
56
98
|
name: awesome_print
|
|
57
99
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -122,6 +164,34 @@ dependencies:
|
|
|
122
164
|
- - "~>"
|
|
123
165
|
- !ruby/object:Gem::Version
|
|
124
166
|
version: '1'
|
|
167
|
+
- !ruby/object:Gem::Dependency
|
|
168
|
+
name: simplecov
|
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
|
170
|
+
requirements:
|
|
171
|
+
- - ">="
|
|
172
|
+
- !ruby/object:Gem::Version
|
|
173
|
+
version: '0'
|
|
174
|
+
type: :development
|
|
175
|
+
prerelease: false
|
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
177
|
+
requirements:
|
|
178
|
+
- - ">="
|
|
179
|
+
- !ruby/object:Gem::Version
|
|
180
|
+
version: '0'
|
|
181
|
+
- !ruby/object:Gem::Dependency
|
|
182
|
+
name: simplecov-formatter-badge
|
|
183
|
+
requirement: !ruby/object:Gem::Requirement
|
|
184
|
+
requirements:
|
|
185
|
+
- - ">="
|
|
186
|
+
- !ruby/object:Gem::Version
|
|
187
|
+
version: '0'
|
|
188
|
+
type: :development
|
|
189
|
+
prerelease: false
|
|
190
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
191
|
+
requirements:
|
|
192
|
+
- - ">="
|
|
193
|
+
- !ruby/object:Gem::Version
|
|
194
|
+
version: '0'
|
|
125
195
|
description: Generate repository list, show user info and more.
|
|
126
196
|
email:
|
|
127
197
|
- kigster@gmail.com
|
|
@@ -131,6 +201,7 @@ extensions: []
|
|
|
131
201
|
extra_rdoc_files: []
|
|
132
202
|
files:
|
|
133
203
|
- ".envrc"
|
|
204
|
+
- ".github/workflows/ruby.yml"
|
|
134
205
|
- ".gitignore"
|
|
135
206
|
- ".rspec"
|
|
136
207
|
- Gemfile
|
|
@@ -138,6 +209,8 @@ files:
|
|
|
138
209
|
- LICENSE
|
|
139
210
|
- README.md
|
|
140
211
|
- Rakefile
|
|
212
|
+
- WARRANTY.md
|
|
213
|
+
- docs/img/coverage.svg
|
|
141
214
|
- exe/githuh
|
|
142
215
|
- githuh.gemspec
|
|
143
216
|
- lib/githuh.rb
|
|
@@ -145,6 +218,8 @@ files:
|
|
|
145
218
|
- lib/githuh/cli/commands/repo/list.rb
|
|
146
219
|
- lib/githuh/cli/commands/user/info.rb
|
|
147
220
|
- lib/githuh/cli/commands/version.rb
|
|
221
|
+
- lib/githuh/cli/launcher.rb
|
|
222
|
+
- lib/githuh/version.rb
|
|
148
223
|
homepage: https://github.com/kigster/githuh
|
|
149
224
|
licenses:
|
|
150
225
|
- MIT
|