githuh 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c65591c34bc51c5a7b3074db037db0f26cab2e04b2e08524ccd2f2a7fdaef0d0
4
+ data.tar.gz: 8a6101f582e720ff69ca98d8ee60686099ec20f0146585b65721ed4657e6c876
5
+ SHA512:
6
+ metadata.gz: 6e745d10d18e4e7a63a32911075be060d2168a5741ef03ef06944f7e0d1970dc43a6009616b9f0cd320a74970eb33d7516424241a599e8c56e65fe64531d2356
7
+ data.tar.gz: 142883c54d4a543ea8222d86d9db79ec9441f16891588849364b221260f47e4323c4a3e9df1339daede22592ef793b4c4413be2f6bdaa40b31d8ab11384201f8
data/.envrc ADDED
@@ -0,0 +1,2 @@
1
+
2
+ export PATH=$(pwd)/exe:${PATH}
@@ -0,0 +1,24 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+ .idea/
4
+
5
+ ## TEXTMATE
6
+ *.tmproj
7
+ tmtags
8
+
9
+ ## EMACS
10
+ *~
11
+ \#*
12
+ .\#*
13
+
14
+ ## VIM
15
+ *.swp
16
+
17
+ ## PROJECT::GENERAL
18
+ coverage
19
+ rdoc
20
+ pkg
21
+
22
+ ## PROJECT::SPECIFIC
23
+ .yardoc
24
+ doc
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gemspec
6
+
@@ -0,0 +1,60 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ githuh (0.1.0)
5
+ colored2 (~> 3)
6
+ dry-cli (~> 0.6)
7
+ octokit (~> 4)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ addressable (2.7.0)
13
+ public_suffix (>= 2.0.2, < 5.0)
14
+ awesome_print (1.8.0)
15
+ colored2 (3.1.2)
16
+ concurrent-ruby (1.1.6)
17
+ diff-lcs (1.3)
18
+ dry-cli (0.6.0)
19
+ concurrent-ruby (~> 1.0)
20
+ faraday (1.0.0)
21
+ multipart-post (>= 1.2, < 3)
22
+ multipart-post (2.1.1)
23
+ octokit (4.17.0)
24
+ faraday (>= 0.9)
25
+ sawyer (~> 0.8.0, >= 0.5.3)
26
+ public_suffix (4.0.3)
27
+ rake (13.0.1)
28
+ rspec (3.9.0)
29
+ rspec-core (~> 3.9.0)
30
+ rspec-expectations (~> 3.9.0)
31
+ rspec-mocks (~> 3.9.0)
32
+ rspec-core (3.9.1)
33
+ rspec-support (~> 3.9.1)
34
+ rspec-expectations (3.9.0)
35
+ diff-lcs (>= 1.2.0, < 2.0)
36
+ rspec-support (~> 3.9.0)
37
+ rspec-its (1.3.0)
38
+ rspec-core (>= 3.0.0)
39
+ rspec-expectations (>= 3.0.0)
40
+ rspec-mocks (3.9.1)
41
+ diff-lcs (>= 1.2.0, < 2.0)
42
+ rspec-support (~> 3.9.0)
43
+ rspec-support (3.9.2)
44
+ sawyer (0.8.2)
45
+ addressable (>= 2.3.5)
46
+ faraday (> 0.8, < 2.0)
47
+
48
+ PLATFORMS
49
+ ruby
50
+
51
+ DEPENDENCIES
52
+ awesome_print (~> 1)
53
+ bundler (~> 2)
54
+ githuh!
55
+ rake (~> 13)
56
+ rspec (~> 3)
57
+ rspec-its (~> 1)
58
+
59
+ BUNDLED WITH
60
+ 2.1.2
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright © 2016 Konstantin Gredeskoul, all rights reserved.
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,21 @@
1
+ # Repos Markdown
2
+
3
+ List my github repos and generate pretty markdown.
4
+
5
+ ## Setup
6
+
7
+ Add your Github Token to the global config:
8
+
9
+ ```bash
10
+ git config --global --set user.token <token>
11
+ ```
12
+
13
+ After that:
14
+
15
+ ```bash
16
+ bin/repos-markdown output-file
17
+ ```
18
+
19
+ ## Copyright
20
+
21
+ © 2020 Konstantin Gredeskoul
@@ -0,0 +1,32 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+ require 'timeout'
4
+
5
+ def shell(*args)
6
+ puts "running: #{args.join(' ')}"
7
+ system(args.join(' '))
8
+ end
9
+
10
+ task :clean do
11
+ shell('rm -rf pkg/ tmp/ coverage/ doc/ ' )
12
+ end
13
+
14
+ task :gem => [:build] do
15
+ shell('gem install pkg/*')
16
+ end
17
+
18
+ task :permissions => [ :clean ] do
19
+ shell("chmod -v o+r,g+r * */* */*/* */*/*/* */*/*/*/* */*/*/*/*/*")
20
+ shell("find . -type d -exec chmod o+x,g+x {} \\;")
21
+ end
22
+
23
+ task :build => :permissions
24
+
25
+ RSpec::Core::RakeTask.new(:spec)
26
+
27
+ task :default => :spec
28
+
29
+
30
+
31
+
32
+
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby -W0
2
+ # frozen_string_literal: true
3
+
4
+ # vim: ft=ruby
5
+
6
+ require 'octokit'
7
+ require 'colored2'
8
+ require 'dry/cli'
9
+
10
+ lib_path = File.expand_path("../lib", __dir__)
11
+ $LOAD_PATH << lib_path if File.exist?(lib_path)
12
+
13
+ require 'githuh'
14
+
15
+ Dry::CLI.new(Githuh::CLI::Commands).call
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'githuh'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'githuh'
9
+ spec.version = '0.1.0'
10
+ spec.authors = ['Konstantin Gredeskoul']
11
+ spec.email = %w(kigster@gmail.com)
12
+
13
+ spec.summary = "Extensible CLI helper client for Github, for automating various tasks, such as — generating a list of org's repos and converting it into a pretty markdown, etc"
14
+ spec.license = 'MIT'
15
+
16
+ spec.description = "Generate repository list, show user info and more."
17
+
18
+ spec.homepage = 'https://github.com/kigster/githuh'
19
+
20
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ spec.bindir = 'exe'
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ['lib']
24
+ spec.required_ruby_version = '>= 2.3'
25
+
26
+ spec.add_dependency 'colored2', '~> 3'
27
+ spec.add_dependency 'dry-cli', '~> 0.6'
28
+ spec.add_dependency 'octokit', '~> 4'
29
+
30
+ spec.add_development_dependency 'awesome_print', '~> 1'
31
+ spec.add_development_dependency 'bundler', '~> 2'
32
+ spec.add_development_dependency 'rake', '~> 13'
33
+ spec.add_development_dependency 'rspec', '~> 3'
34
+ spec.add_development_dependency 'rspec-its', '~> 1'
35
+ end
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ # vim: ft=ruby
5
+
6
+ require 'octokit'
7
+ require 'colored2'
8
+ require 'dry/cli'
9
+
10
+ module Githuh
11
+ VERSION = '0.1.0'
12
+
13
+ module CLI
14
+ module Commands
15
+ extend Dry::CLI::Registry
16
+ end
17
+ end
18
+ end
19
+
20
+ require 'githuh/cli/commands/base'
21
+ require 'githuh/cli/commands/user/info'
22
+ require 'githuh/cli/commands/version'
23
+ require 'githuh/cli/commands/repo/list'
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Githuh
4
+ module CLI
5
+ module Commands
6
+ DEFAULT_PAGE_SIZE = 50
7
+
8
+ class Base < Dry::CLI::Command
9
+ class << self
10
+ def inherited(base)
11
+ super
12
+ base.instance_eval do
13
+ option :api_token, required: false, desc: "Github API token; if not given, user.token is read from ~/.gitconfig"
14
+ option :per_page, required: false, default: DEFAULT_PAGE_SIZE, desc: "Pagination page size for Github API"
15
+ option :verbose, type: :boolean, default: true, desc: 'Print verbose info'
16
+
17
+ end
18
+ end
19
+ end
20
+
21
+ attr_accessor :client, :token, :per_page, :verbose
22
+
23
+ def call(api_token: nil,
24
+ per_page: DEFAULT_PAGE_SIZE,
25
+ verbose: true)
26
+
27
+ self.verbose = verbose
28
+ self.token = api_token || token_from_gitconfig
29
+ self.per_page = per_page || DEFAULT_PAGE_SIZE
30
+ self.client = Octokit::Client.new(access_token: token)
31
+ end
32
+
33
+ private
34
+
35
+ def token_from_gitconfig
36
+ `git config --global --get user.token`.chomp
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,109 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ # vim: ft=ruby
5
+ require 'bundler/setup'
6
+ require 'dry/cli'
7
+ require 'json'
8
+
9
+ require_relative '../base'
10
+
11
+ module Githuh
12
+ module CLI
13
+ module Commands
14
+ module Repo
15
+ class List < Base
16
+ FORMATS = %w(markdown json).freeze
17
+ FORK_OPTIONS = %w(include only exclude).freeze
18
+
19
+ attr_accessor :file, :output, :repos, :format, :forks
20
+
21
+ desc 'List owned repositories and render the output in markdown or JSON'
22
+
23
+ option :file, required: false, desc: 'Output file. If not provided, STDERR is used.'
24
+ option :format, values: FORMATS, default: FORMATS.first, required: false, desc: 'Output format'
25
+ option :forks, type: :string, values: FORK_OPTIONS, default: FORK_OPTIONS.first, required: false, desc: 'Include or exclude forks'
26
+
27
+ def call(file: nil, format: nil, forks: nil, **opts)
28
+ super(**opts)
29
+
30
+ self.forks = forks
31
+ self.format = (format || FORMATS.first).to_sym
32
+ self.repos = []
33
+ self.output = StringIO.new
34
+ self.file = STDOUT
35
+ self.file = file ? File.open(file, 'w') : STDERR
36
+
37
+ self.file.write send("render_as_#{format}", repositories)
38
+ ensure
39
+ file.close if file.respond_to?(:close) && !file.closed?
40
+ end
41
+
42
+ private
43
+
44
+ def repositories
45
+ page = 0
46
+ [].tap do |repo_list|
47
+ loop do
48
+ print '.'.green if verbose
49
+ options = {
50
+ page: page,
51
+ per_page: per_page,
52
+ type: :owner,
53
+ }
54
+
55
+ result = client.repos({}, query: options)
56
+ result.reject! do |r|
57
+ case forks
58
+ when 'exclude'
59
+ r.fork
60
+ when 'only'
61
+ !r.fork
62
+ when 'include'
63
+ false
64
+ end
65
+ end
66
+ break if result.empty?
67
+
68
+ result.size.times { print '.'.green } if verbose
69
+
70
+ repo_list << result
71
+ page += 1
72
+ end
73
+ puts " ✓".bold.green if verbose
74
+ end.flatten.sort_by(&:stargazers_count).reverse.uniq(&:name)
75
+ end
76
+
77
+ def render_as_markdown(repositories)
78
+ output.puts "### #{client.user.name}'s Repos\n"
79
+ repositories.each_with_index do |repo, index|
80
+ output.puts repo_as_markdown(index, repo)
81
+ end
82
+ output.string
83
+ end
84
+
85
+ def render_as_json(repositories)
86
+ JSON.pretty_generate(repositories.map(&:to_hash))
87
+ end
88
+
89
+ def repo_as_markdown(index, repo)
90
+ <<~REPO
91
+
92
+ ### #{index + 1}. [#{repo.name}](#{repo.url}) (#{repo.stargazers_count} ★)
93
+
94
+ #{repo.language ? "**#{repo.language}**. " : ''}
95
+ #{repo.license ? "Distributed under the **#{repo.license.name}** license." : ''}
96
+
97
+ #{repo.description}
98
+
99
+ REPO
100
+ end
101
+ end
102
+ end
103
+
104
+ register 'repo', aliases: ['r'] do |prefix|
105
+ prefix.register 'list', Repo::List
106
+ end
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ # vim: ft=ruby
5
+ require "bundler/setup"
6
+ require "dry/cli"
7
+ require_relative '../base'
8
+ require 'awesome_print'
9
+
10
+ module Githuh
11
+ module CLI
12
+ module Commands
13
+ module User
14
+ class Info < Base
15
+ desc "Print user information"
16
+
17
+ def call(**opts)
18
+ super(**opts)
19
+ ap client.user.to_hash
20
+ end
21
+ end
22
+ end
23
+
24
+ register "user", aliases: ["u"] do |prefix|
25
+ prefix.register "info", User::Info
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ # vim: ft=ruby
5
+ require "bundler/setup"
6
+ require "dry/cli"
7
+ require 'githuh'
8
+
9
+ module Githuh
10
+ module CLI
11
+ module Commands
12
+ class Version < Dry::CLI::Command
13
+ desc "Print version"
14
+
15
+ def call(*)
16
+ puts Githuh::VERSION
17
+ end
18
+ end
19
+
20
+ register 'version', Version, aliases: %w(v -v --version)
21
+ end
22
+ end
23
+ end
metadata ADDED
@@ -0,0 +1,173 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: githuh
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Konstantin Gredeskoul
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-03-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: colored2
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: dry-cli
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.6'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: octokit
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '4'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '4'
55
+ - !ruby/object:Gem::Dependency
56
+ name: awesome_print
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1'
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '2'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '2'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '13'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '13'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '3'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rspec-its
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '1'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '1'
125
+ description: Generate repository list, show user info and more.
126
+ email:
127
+ - kigster@gmail.com
128
+ executables:
129
+ - githuh
130
+ extensions: []
131
+ extra_rdoc_files: []
132
+ files:
133
+ - ".envrc"
134
+ - ".gitignore"
135
+ - ".rspec"
136
+ - Gemfile
137
+ - Gemfile.lock
138
+ - LICENSE
139
+ - README.md
140
+ - Rakefile
141
+ - exe/githuh
142
+ - githuh.gemspec
143
+ - lib/githuh.rb
144
+ - lib/githuh/cli/commands/base.rb
145
+ - lib/githuh/cli/commands/repo/list.rb
146
+ - lib/githuh/cli/commands/user/info.rb
147
+ - lib/githuh/cli/commands/version.rb
148
+ homepage: https://github.com/kigster/githuh
149
+ licenses:
150
+ - MIT
151
+ metadata: {}
152
+ post_install_message:
153
+ rdoc_options: []
154
+ require_paths:
155
+ - lib
156
+ required_ruby_version: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - ">="
159
+ - !ruby/object:Gem::Version
160
+ version: '2.3'
161
+ required_rubygems_version: !ruby/object:Gem::Requirement
162
+ requirements:
163
+ - - ">="
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
166
+ requirements: []
167
+ rubygems_version: 3.1.2
168
+ signing_key:
169
+ specification_version: 4
170
+ summary: Extensible CLI helper client for Github, for automating various tasks, such
171
+ as — generating a list of org's repos and converting it into a pretty markdown,
172
+ etc
173
+ test_files: []