k_ext-github 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7d5b45fe84e6b83feec59c4f83c163c5caf362cba680d4e206e6610830997cfc
4
- data.tar.gz: 6055446e7bf8334c3284a7e8c807c6803ed450216711f372525ba5efacfa5f4a
3
+ metadata.gz: a2c9862027020fc728f735425e078dca3451555ed55941bcadb4cd61bcf8b7d3
4
+ data.tar.gz: 105e15847f190a1bea23250687962a00be3db249bd3c2ba5495ab25af214f8fe
5
5
  SHA512:
6
- metadata.gz: 48e9ac5682bb7f21be6a13c0edf934e6e397d85bda9611ac25d685d36099612432a94631ba3537c0b8d70c67b01644e3b2c4ee1a72c7520bbe5a41ff8abf3fb6
7
- data.tar.gz: 18eaeab365570929f264d4686e9a05da3b235ebaefc513ae19d907889a88ae33995bc6b61a1bf73af0e87563890c0a06e7e5bdbe328adc08138c6aaa566fa5eb
6
+ metadata.gz: 3f81c9ac640ab78e68e2d2df9b612a7b3c15a349f7e9a614989c952695e949d590a047e430294e0cfca467c834f5ca360ff076d120af46e038c87da80140c9f9
7
+ data.tar.gz: 7de7c88c18837ecd0b43bf090aba878e9bb6cf274c4a275c6211730ca3c98741160bb4fb8b8206b0ad48d0ff7a82603b9de6cb78b4340d2209c91f28cefbaa80
data/Guardfile CHANGED
@@ -1,31 +1,31 @@
1
- # frozen_string_literal: true
2
-
3
- guard :bundler, cmd: 'bundle install' do
4
- watch('Gemfile')
5
- watch('k_ext_github.gemspec')
6
- end
7
-
8
- group :green_pass_then_cop, halt_on_fail: true do
9
- guard :rspec, cmd: 'bundle exec rspec -f doc' do
10
- require 'guard/rspec/dsl'
11
- dsl = Guard::RSpec::Dsl.new(self)
12
-
13
- # RSpec files
14
- rspec = dsl.rspec
15
- watch(rspec.spec_helper) { rspec.spec_dir }
16
- watch(rspec.spec_support) { rspec.spec_dir }
17
- watch(rspec.spec_files)
18
-
19
- # Ruby files
20
- ruby = dsl.ruby
21
- dsl.watch_spec_files_for(ruby.lib_files)
22
- watch(%r{^lib/k_ext/github/(.+)\.rb$}) { |m| "spec/k_ext/#{m[1]}_spec.rb" }
23
- watch(%r{^lib/k_ext/github/models/(.+)\.rb$}) { |m| "spec/k_ext/models/#{m[1]}_spec.rb" }
24
- watch(%r{^lib/k_ext/github/commands/(.+)\.rb$}) { |m| "spec/unit/commands/#{m[1]}_spec.rb" }
25
- end
26
-
27
- guard :rubocop, all_on_start: false, cli: ['--format', 'clang'] do
28
- watch(/{.+\.rb$/)
29
- watch(%r{(?:.+/)?\.rubocop(?:_todo)?\.yml$}) { |m| File.dirname(m[0]) }
30
- end
31
- end
1
+ # frozen_string_literal: true
2
+
3
+ guard :bundler, cmd: 'bundle install' do
4
+ watch('Gemfile')
5
+ watch('k_ext_github.gemspec')
6
+ end
7
+
8
+ group :green_pass_then_cop, halt_on_fail: true do
9
+ guard :rspec, cmd: 'bundle exec rspec -f doc' do
10
+ require 'guard/rspec/dsl'
11
+ dsl = Guard::RSpec::Dsl.new(self)
12
+
13
+ # RSpec files
14
+ rspec = dsl.rspec
15
+ watch(rspec.spec_helper) { rspec.spec_dir }
16
+ watch(rspec.spec_support) { rspec.spec_dir }
17
+ watch(rspec.spec_files)
18
+
19
+ # Ruby files
20
+ ruby = dsl.ruby
21
+ dsl.watch_spec_files_for(ruby.lib_files)
22
+ watch(%r{^lib/k_ext/github/(.+)\.rb$}) { |m| "spec/k_ext/#{m[1]}_spec.rb" }
23
+ watch(%r{^lib/k_ext/github/models/(.+)\.rb$}) { |m| "spec/k_ext/models/#{m[1]}_spec.rb" }
24
+ watch(%r{^lib/k_ext/github/commands/(.+)\.rb$}) { |m| "spec/unit/commands/#{m[1]}_spec.rb" }
25
+ end
26
+
27
+ guard :rubocop, all_on_start: false, cli: ['--format', 'clang'] do
28
+ watch(/{.+\.rb$/)
29
+ watch(%r{(?:.+/)?\.rubocop(?:_todo)?\.yml$}) { |m| File.dirname(m[0]) }
30
+ end
31
+ end
data/Rakefile CHANGED
@@ -15,9 +15,9 @@ require 'rake/extensiontask'
15
15
  desc 'Compile all the extensions'
16
16
  task build: :compile
17
17
 
18
- Rake::ExtensionTask.new('k_ext_github') do |ext|
19
- ext.lib_dir = 'lib/k_ext_github'
20
- end
18
+ # Rake::ExtensionTask.new('k_ext_github') do |ext|
19
+ # ext.lib_dir = 'lib/k_ext/github'
20
+ # end
21
21
 
22
22
  desc 'Publish the gem to RubyGems.org'
23
23
  task :publish do
data/k_ext-github.gemspec CHANGED
@@ -1,47 +1,47 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'lib/k_ext/github/version'
4
-
5
- Gem::Specification.new do |spec|
6
- spec.required_ruby_version = '>= 2.5'
7
- spec.name = 'k_ext-github'
8
- spec.version = KExt::Github::VERSION
9
- spec.authors = ['David Cruwys']
10
- spec.email = ['david@ideasmen.com.au']
11
-
12
- spec.summary = 'KExt/Github provides useful github extensions specifically for the klueless code generator'
13
- spec.description = <<-TEXT
14
- KExt/Github provides useful github extensions specifically for the klueless code generator
15
- TEXT
16
- spec.homepage = 'http://appydave.com/gems/k-ext-github'
17
- spec.license = 'MIT'
18
-
19
- # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
20
- # to allow pushing to a single host or delete this section to allow pushing to any host.
21
- raise 'RubyGems 2.0 or newer is required to protect against public gem pushes.' unless spec.respond_to?(:metadata)
22
-
23
- # spec.metadata['allowed_push_host'] = "Set to 'http://mygemserver.com'"
24
-
25
- spec.metadata['homepage_uri'] = spec.homepage
26
- spec.metadata['source_code_uri'] = 'https://github.com/klueless-io/k_ext-github'
27
- spec.metadata['changelog_uri'] = 'https://github.com/klueless-io/k_ext-github/commits/master'
28
-
29
- # Specify which files should be added to the gem when it is released.
30
- # The `git ls-files -z` loads the RubyGem files that have been added into git.
31
- spec.files = Dir.chdir(File.expand_path(__dir__)) do
32
- `git ls-files -z`.split("\x0").reject do |f|
33
- f.match(%r{^(test|spec|features)/})
34
- end
35
- end
36
- spec.bindir = 'exe'
37
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
38
- spec.require_paths = ['lib']
39
- # spec.extensions = ['ext/k_ext_github/extconf.rb']
40
-
41
- spec.add_dependency 'k_log', '~> 0.0.0'
42
- spec.add_dependency 'k_type', '~> 0.0.0'
43
- # spec.add_dependency 'k_util' , '~> 0.0.0'
44
- spec.add_dependency 'octokit', '~> 4.0'
45
-
46
- spec.add_dependency 'virtus', '~> 1.0.5'
47
- end
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/k_ext/github/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.required_ruby_version = '>= 2.5'
7
+ spec.name = 'k_ext-github'
8
+ spec.version = KExt::Github::VERSION
9
+ spec.authors = ['David Cruwys']
10
+ spec.email = ['david@ideasmen.com.au']
11
+
12
+ spec.summary = 'KExt/Github provides useful github extensions specifically for the klueless code generator'
13
+ spec.description = <<-TEXT
14
+ KExt/Github provides useful github extensions specifically for the klueless code generator
15
+ TEXT
16
+ spec.homepage = 'http://appydave.com/gems/k-ext-github'
17
+ spec.license = 'MIT'
18
+
19
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
20
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
21
+ raise 'RubyGems 2.0 or newer is required to protect against public gem pushes.' unless spec.respond_to?(:metadata)
22
+
23
+ # spec.metadata['allowed_push_host'] = "Set to 'http://mygemserver.com'"
24
+
25
+ spec.metadata['homepage_uri'] = spec.homepage
26
+ spec.metadata['source_code_uri'] = 'https://github.com/klueless-io/k_ext-github'
27
+ spec.metadata['changelog_uri'] = 'https://github.com/klueless-io/k_ext-github/commits/master'
28
+
29
+ # Specify which files should be added to the gem when it is released.
30
+ # The `git ls-files -z` loads the RubyGem files that have been added into git.
31
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
32
+ `git ls-files -z`.split("\x0").reject do |f|
33
+ f.match(%r{^(test|spec|features)/})
34
+ end
35
+ end
36
+ spec.bindir = 'exe'
37
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
38
+ spec.require_paths = ['lib']
39
+ # spec.extensions = ['ext/k_ext_github/extconf.rb']
40
+
41
+ spec.add_dependency 'k_log', '~> 0.0.0'
42
+ spec.add_dependency 'k_type', '~> 0.0.0'
43
+ spec.add_dependency 'k_util', '~> 0.0.0'
44
+ spec.add_dependency 'octokit', '~> 4.0'
45
+
46
+ spec.add_dependency 'virtus', '~> 1.0.5'
47
+ end
data/lib/k_ext/github.rb CHANGED
@@ -1,40 +1,41 @@
1
- # frozen_string_literal: true
2
-
3
- require 'virtus'
4
- require 'k_log'
5
-
6
- require 'k_ext/github/version'
7
- require 'k_ext/github/configuration'
8
- require 'k_ext/github/models/hook'
9
- require 'k_ext/github/models/owner'
10
- require 'k_ext/github/models/repository'
11
- require 'k_ext/github/printer'
12
- require 'k_ext/github/api'
13
-
14
- module KExt
15
- module Github
16
- # raise KExt::Github::Error, 'Sample message'
17
- class Error < StandardError; end
18
-
19
- class << self
20
- def configuration
21
- @configuration ||= KExt::Github::Configuration.new
22
- end
23
-
24
- def reset
25
- @configuration = KExt::Github::Configuration.new
26
- end
27
-
28
- def configure
29
- yield(configuration)
30
- end
31
- end
32
- end
33
- end
34
-
35
- if ENV['KLUE_DEBUG']&.to_s&.downcase == 'true'
36
- namespace = 'KExt::Github::Version'
37
- file_path = $LOADED_FEATURES.find { |f| f.include?('k_ext/github/version') }
38
- version = KExt::Github::VERSION.ljust(9)
39
- puts "#{namespace.ljust(35)} : #{version.ljust(9)} : #{file_path}"
40
- end
1
+ # frozen_string_literal: true
2
+
3
+ require 'virtus'
4
+ require 'k_log'
5
+ require 'k_util'
6
+
7
+ require 'k_ext/github/version'
8
+ require 'k_ext/github/configuration'
9
+ require 'k_ext/github/models/hook'
10
+ require 'k_ext/github/models/owner'
11
+ require 'k_ext/github/models/repository'
12
+ require 'k_ext/github/printer'
13
+ require 'k_ext/github/api'
14
+
15
+ module KExt
16
+ module Github
17
+ # raise KExt::Github::Error, 'Sample message'
18
+ class Error < StandardError; end
19
+
20
+ class << self
21
+ def configuration
22
+ @configuration ||= KExt::Github::Configuration.new
23
+ end
24
+
25
+ def reset
26
+ @configuration = KExt::Github::Configuration.new
27
+ end
28
+
29
+ def configure
30
+ yield(configuration)
31
+ end
32
+ end
33
+ end
34
+ end
35
+
36
+ if ENV['KLUE_DEBUG']&.to_s&.downcase == 'true'
37
+ namespace = 'KExt::Github::Version'
38
+ file_path = $LOADED_FEATURES.find { |f| f.include?('k_ext/github/version') }
39
+ version = KExt::Github::VERSION.ljust(9)
40
+ puts "#{namespace.ljust(35)} : #{version.ljust(9)} : #{file_path}"
41
+ end
@@ -1,124 +1,124 @@
1
- # frozen_string_literal: true
2
-
3
- module KExt
4
- module Github
5
- # Print formatted log for GitHub data such as repositories
6
- require 'octokit'
7
-
8
- # The API provides a limited set of service methods for working against GitHub
9
- class Api
10
- include KLog::Logging
11
- include Virtus.model
12
-
13
- # attribute :client_id, String, :writer => :private
14
- # attribute :secret, String, :writer => :private
15
-
16
- # attribute :sites, Array[Netlify::Site], :writer => :private
17
- attribute :client, Octokit::Client, writer: :private
18
-
19
- def self.instance(access_token)
20
- GithubApi.new(token: access_token)
21
- end
22
-
23
- # Create API for communicating with GitHub
24
- #
25
- # Provide token OR login/password
26
- #
27
- # Create a token here
28
- # https://github.com/settings/tokens/new
29
- #
30
- # @param [String] token
31
- # @param [String] login
32
- # @param [String] password
33
- def initialize(token: nil, login: nil, password: nil)
34
- auth(token: token, login: login, password: password) if token || login || password
35
- end
36
-
37
- # Authenticate against GitHub with username and password or token
38
- #
39
- # Provide token OR login/password
40
- #
41
- # Create a token here
42
- # https://github.com/settings/tokens/new
43
- # @param [String] token
44
- # @param [String] login
45
- # @param [String] password
46
- def auth(token: nil, login: nil, password: nil)
47
- raise 'Provide credentials. Token or username/password' if token.nil? && (login.nil? || password.nil?)
48
-
49
- self.client = if token.nil?
50
- Octokit::Client.new(login: login, password: password)
51
- else
52
- Octokit::Client.new(access_token: token)
53
- end
54
-
55
- # Fetch the current user
56
- log.kv 'GitHub User', client.user.name
57
- end
58
-
59
- # --------------------------------------------------------------------------------
60
- # Service Actions
61
- # --------------------------------------------------------------------------------
62
-
63
- # list of repositories for this user
64
- #
65
- def repositories
66
- items = @client.repositories({}, query: { per_page: 100 })
67
-
68
- items.map { |item| KExt::Github::Models::Repository.new(item) }
69
- end
70
-
71
- # create repository
72
- #
73
- # @param [String] repository_name e.g. klueless-io/z-test-aerial.com
74
- def create_repository(repository_name, **options)
75
- @client.create_repository(repository_name, options)
76
- end
77
-
78
- # delete repository
79
- #
80
- # @param [String] repository_name e.g. klueless-io/z-test-aerial.com
81
- def delete_repository(repository_name, **options)
82
- @client.delete_repository(repository_name, **options)
83
- end
84
-
85
- # list of hooks for repository
86
- #
87
- # @param [String] repository_name e.g. klueless-io/z-test-aerial.com
88
- def hooks(repository_name)
89
- items = @client.hooks(repository_name)
90
-
91
- items.map { |item| KExt::Github::Models::Hook.new(item) }
92
- end
93
-
94
- # list of repositories for organization
95
- #
96
- # @param [String] org_name Organization name
97
- def organization_repositories(org_name)
98
- items = @client.repositories(org_name, query: { per_page: 100 })
99
-
100
- items.map { |item| KExt::Github::Models::Repository.new(item) }
101
- end
102
- # organization_repositories(org, options = {}) => Array<Sawyer::Resource> (also: #org_repositories, #org_repos)
103
-
104
- # remove hook from repository by id
105
- #
106
- # @param [String] repository_name e.g. klueless-io/z-test-aerial.com
107
- # @param [Integer] id hook ID
108
- def remove_hook(repository_name, id)
109
- @client.remove_hook(repository_name, id)
110
- end
111
-
112
- # remove all hooks in a repository
113
- #
114
- # @param [String] repository_name e.g. klueless-io/z-test-aerial.com
115
- def remove_hooks(repository_name)
116
- hooks = hooks(repository_name)
117
-
118
- hooks.each do |hook|
119
- @client.remove_hook(repository_name, hook.id)
120
- end
121
- end
122
- end
123
- end
124
- end
1
+ # frozen_string_literal: true
2
+
3
+ module KExt
4
+ module Github
5
+ # Print formatted log for GitHub data such as repositories
6
+ require 'octokit'
7
+
8
+ # The API provides a limited set of service methods for working against GitHub
9
+ class Api
10
+ include KLog::Logging
11
+ include Virtus.model
12
+
13
+ # attribute :client_id, String, :writer => :private
14
+ # attribute :secret, String, :writer => :private
15
+
16
+ # attribute :sites, Array[Netlify::Site], :writer => :private
17
+ attribute :client, Octokit::Client, writer: :private
18
+
19
+ def self.instance(access_token)
20
+ GithubApi.new(token: access_token)
21
+ end
22
+
23
+ # Create API for communicating with GitHub
24
+ #
25
+ # Provide token OR login/password
26
+ #
27
+ # Create a token here
28
+ # https://github.com/settings/tokens/new
29
+ #
30
+ # @param [String] token
31
+ # @param [String] login
32
+ # @param [String] password
33
+ def initialize(token: nil, login: nil, password: nil)
34
+ auth(token: token, login: login, password: password) if token || login || password
35
+ end
36
+
37
+ # Authenticate against GitHub with username and password or token
38
+ #
39
+ # Provide token OR login/password
40
+ #
41
+ # Create a token here
42
+ # https://github.com/settings/tokens/new
43
+ # @param [String] token
44
+ # @param [String] login
45
+ # @param [String] password
46
+ def auth(token: nil, login: nil, password: nil)
47
+ raise 'Provide credentials. Token or username/password' if token.nil? && (login.nil? || password.nil?)
48
+
49
+ self.client = if token.nil?
50
+ Octokit::Client.new(login: login, password: password)
51
+ else
52
+ Octokit::Client.new(access_token: token)
53
+ end
54
+
55
+ # Fetch the current user
56
+ log.kv 'GitHub User', client.user.name
57
+ end
58
+
59
+ # --------------------------------------------------------------------------------
60
+ # Service Actions
61
+ # --------------------------------------------------------------------------------
62
+
63
+ # list of repositories for this user
64
+ #
65
+ def repositories
66
+ items = @client.repositories({}, query: { per_page: 100 })
67
+
68
+ items.map { |item| KExt::Github::Models::Repository.new(item) }
69
+ end
70
+
71
+ # create repository
72
+ #
73
+ # @param [String] repository_name e.g. klueless-io/z-test-aerial.com
74
+ def create_repository(repository_name, **options)
75
+ @client.create_repository(repository_name, options)
76
+ end
77
+
78
+ # delete repository
79
+ #
80
+ # @param [String] repository_name e.g. klueless-io/z-test-aerial.com
81
+ def delete_repository(repository_name, **options)
82
+ @client.delete_repository(repository_name, **options)
83
+ end
84
+
85
+ # list of hooks for repository
86
+ #
87
+ # @param [String] repository_name e.g. klueless-io/z-test-aerial.com
88
+ def hooks(repository_name)
89
+ items = @client.hooks(repository_name)
90
+
91
+ items.map { |item| KExt::Github::Models::Hook.new(item) }
92
+ end
93
+
94
+ # list of repositories for organization
95
+ #
96
+ # @param [String] org_name Organization name
97
+ def organization_repositories(org_name)
98
+ items = @client.repositories(org_name, query: { per_page: 100 })
99
+
100
+ items.map { |item| KExt::Github::Models::Repository.new(item) }
101
+ end
102
+ # organization_repositories(org, options = {}) => Array<Sawyer::Resource> (also: #org_repositories, #org_repos)
103
+
104
+ # remove hook from repository by id
105
+ #
106
+ # @param [String] repository_name e.g. klueless-io/z-test-aerial.com
107
+ # @param [Integer] id hook ID
108
+ def remove_hook(repository_name, id)
109
+ @client.remove_hook(repository_name, id)
110
+ end
111
+
112
+ # remove all hooks in a repository
113
+ #
114
+ # @param [String] repository_name e.g. klueless-io/z-test-aerial.com
115
+ def remove_hooks(repository_name)
116
+ hooks = hooks(repository_name)
117
+
118
+ hooks.each do |hook|
119
+ @client.remove_hook(repository_name, hook.id)
120
+ end
121
+ end
122
+ end
123
+ end
124
+ end
@@ -1,18 +1,20 @@
1
- # frozen_string_literal: true
2
-
3
- module KExt
4
- module Github
5
- # Configuration class for KExt::Github
6
- class Configuration
7
- attr_accessor :user
8
- attr_accessor :personal_access_token
9
- attr_accessor :personal_access_token_delete
10
-
11
- def initialize
12
- @user = ENV['GITHUB_USER']
13
- @personal_access_token = ENV['GITHUB_PERSONAL_ACCESS_TOKEN']
14
- @personal_access_token_delete = ENV['GITHUB_PERSONAL_ACCESS_TOKEN_DELETE']
15
- end
16
- end
17
- end
18
- end
1
+ # frozen_string_literal: true
2
+
3
+ module KExt
4
+ module Github
5
+ # Configuration class for KExt::Github
6
+ class Configuration
7
+ include KUtil::Data::InstanceVariablesToH
8
+
9
+ attr_accessor :user
10
+ attr_accessor :personal_access_token
11
+ attr_accessor :personal_access_token_delete
12
+
13
+ def initialize
14
+ @user = ENV['GITHUB_USER']
15
+ @personal_access_token = ENV['GITHUB_PERSONAL_ACCESS_TOKEN']
16
+ @personal_access_token_delete = ENV['GITHUB_PERSONAL_ACCESS_TOKEN_DELETE']
17
+ end
18
+ end
19
+ end
20
+ end
@@ -1,30 +1,30 @@
1
- # frozen_string_literal: true
2
-
3
- module KExt
4
- module Github
5
- module Models
6
- # This model represents a GitHub hook
7
- class Hook
8
- include Virtus.model
9
-
10
- def initialize(attributes = nil)
11
- # Virtus will take your attributes and match them to the attribute definitions listed below
12
- super(attributes)
13
- end
14
-
15
- attribute :type, String
16
- attribute :id, String
17
- attribute :name, String
18
- attribute :active, String
19
- attribute :events, String
20
- attribute :config, Hash
21
- attribute :updated_at, String
22
- attribute :created_at, String
23
- attribute :url, String
24
- attribute :test_url, String
25
- attribute :ping_url, String
26
- attribute :last_response, String
27
- end
28
- end
29
- end
30
- end
1
+ # frozen_string_literal: true
2
+
3
+ module KExt
4
+ module Github
5
+ module Models
6
+ # This model represents a GitHub hook
7
+ class Hook
8
+ include Virtus.model
9
+
10
+ def initialize(attributes = nil)
11
+ # Virtus will take your attributes and match them to the attribute definitions listed below
12
+ super(attributes)
13
+ end
14
+
15
+ attribute :type, String
16
+ attribute :id, String
17
+ attribute :name, String
18
+ attribute :active, String
19
+ attribute :events, String
20
+ attribute :config, Hash
21
+ attribute :updated_at, String
22
+ attribute :created_at, String
23
+ attribute :url, String
24
+ attribute :test_url, String
25
+ attribute :ping_url, String
26
+ attribute :last_response, String
27
+ end
28
+ end
29
+ end
30
+ end
@@ -1,19 +1,19 @@
1
- # frozen_string_literal: true
2
-
3
- module KExt
4
- module Github
5
- module Models
6
- # This model represents a GitHub owner
7
- class Owner
8
- include Virtus.model
9
-
10
- def initialize(attributes = nil)
11
- # Virtus will take your attributes and match them to the attribute definitions listed below
12
- super(attributes)
13
- end
14
-
15
- attribute :login, String
16
- end
17
- end
18
- end
19
- end
1
+ # frozen_string_literal: true
2
+
3
+ module KExt
4
+ module Github
5
+ module Models
6
+ # This model represents a GitHub owner
7
+ class Owner
8
+ include Virtus.model
9
+
10
+ def initialize(attributes = nil)
11
+ # Virtus will take your attributes and match them to the attribute definitions listed below
12
+ super(attributes)
13
+ end
14
+
15
+ attribute :login, String
16
+ end
17
+ end
18
+ end
19
+ end
@@ -1,30 +1,30 @@
1
- # frozen_string_literal: true
2
-
3
- module KExt
4
- module Github
5
- module Models
6
- # This model represents a GitHub Repository
7
- class Repository
8
- include Virtus.model
9
-
10
- def initialize(attributes = nil)
11
- # Virtus will take your attributes and match them to the attribute definitions listed below
12
- super(attributes)
13
- end
14
-
15
- attribute :id, String
16
- attribute :node_id, String
17
- attribute :name, String
18
- attribute :full_name, String
19
- attribute :private, String
20
- attribute :description, String
21
- attribute :url, String
22
- attribute :created_at, String
23
- attribute :updated_at, String
24
- attribute :pushed_at, String
25
- attribute :git_url, String
26
- attribute :owner, KExt::Github::Models::Owner
27
- end
28
- end
29
- end
30
- end
1
+ # frozen_string_literal: true
2
+
3
+ module KExt
4
+ module Github
5
+ module Models
6
+ # This model represents a GitHub Repository
7
+ class Repository
8
+ include Virtus.model
9
+
10
+ def initialize(attributes = nil)
11
+ # Virtus will take your attributes and match them to the attribute definitions listed below
12
+ super(attributes)
13
+ end
14
+
15
+ attribute :id, String
16
+ attribute :node_id, String
17
+ attribute :name, String
18
+ attribute :full_name, String
19
+ attribute :private, String
20
+ attribute :description, String
21
+ attribute :url, String
22
+ attribute :created_at, String
23
+ attribute :updated_at, String
24
+ attribute :pushed_at, String
25
+ attribute :git_url, String
26
+ attribute :owner, KExt::Github::Models::Owner
27
+ end
28
+ end
29
+ end
30
+ end
@@ -1,160 +1,160 @@
1
- # frozen_string_literal: true
2
-
3
- module KExt
4
- module Github
5
- # Print formatted log for GitHub data such as repositories
6
- class Printer
7
- extend KLog::Logging
8
-
9
- # ---------------------------------------------
10
- # Print Repositories
11
- # ---------------------------------------------
12
-
13
- def self.repositories(rows = nil, format = 'default')
14
- log.block 'Repositories'
15
-
16
- if rows.nil?
17
- Repository.all.each do |_r|
18
- repository_with_format(repo, format)
19
- end
20
- else
21
- rows.each do |_r|
22
- repository_with_format(repo, format)
23
- end
24
- end
25
- end
26
-
27
- def self.repositories_as_table(rows = nil, format = 'default')
28
- log.block 'Repositories'
29
-
30
- rows = Repository.all if rows.nil?
31
-
32
- case format
33
- when 'detailed'
34
- # tp rows
35
- tp rows, :id, :node_id, :name, :full_name, :private, :description, :url, 'owner.login', :created_at, :updated_at, :pushed_at, :git_url
36
- else
37
- tp rows, :id, :name, :git_url, :full_name, :private, :description, :url, 'owner.login'
38
- end
39
- end
40
-
41
- def self.repository_with_format(repo, format)
42
- case format
43
- when 'detailed'
44
- repository_detailed(repo)
45
- else
46
- repository(repo)
47
- end
48
- end
49
-
50
- def self.repository(repo)
51
- data = repo_key_values(repo)
52
-
53
- log.kv_hash(data)
54
- log.line
55
- end
56
-
57
- def self.repository_detailed(repo)
58
- data = repo_key_values(repo)
59
-
60
- log.kv_hash(data)
61
- log.line
62
-
63
- # Print Relations
64
-
65
- log.line
66
- end
67
-
68
- # ---------------------------------------------
69
- # Print Hooks
70
- # ---------------------------------------------
71
-
72
- def self.hooks(rows = nil, format = 'default')
73
- log.block 'Hooks'
74
-
75
- if rows.nil?
76
- Hook.all.each do |_r|
77
- hook_with_format(repo, format)
78
- end
79
- else
80
- rows.each do |_r|
81
- hook_with_format(repo, format)
82
- end
83
- end
84
- end
85
-
86
- def self.hooks_as_table(rows = nil, format = 'default')
87
- log.block 'Hooks'
88
-
89
- rows = Hook.all if rows.nil?
90
-
91
- case format
92
- when 'detailed'
93
- tp rows, :type, :id, :name, :active, :events, :config, :updated_at, :created_at, :url, :test_url, :ping_url, :last_response
94
- else
95
- tp rows, :type, :id, :name, :active, :url, :config
96
- end
97
- end
98
-
99
- def self.hook_with_format(repo, format)
100
- case format
101
- when 'detailed'
102
- hook_detailed(repo)
103
- else
104
- hook(repo)
105
- end
106
- end
107
-
108
- def self.hook(hook)
109
- hook_key_values(hook).each do |key_value|
110
- log.kv key_value.key, key_value.vale
111
- end
112
-
113
- log.line
114
- end
115
-
116
- def self.hook_detailed(hook)
117
- hook_key_values(hook).each do |key_value|
118
- log.kv key_value.key, key_value.vale
119
- end
120
-
121
- # Print Relations
122
-
123
- log.line
124
- end
125
-
126
- def self.repo_key_values(repo)
127
- {
128
- id: repo.id,
129
- node_id: repo.node_id,
130
- name: repo.name,
131
- full_name: repo.full_name,
132
- private: repo.private,
133
- description: repo.description,
134
- url: repo.url,
135
- created_at: repo.created_at,
136
- updated_at: repo.updated_at,
137
- pushed_at: repo.pushed_at,
138
- git_url: repo.git_url
139
- }
140
- end
141
-
142
- def self.hook_key_values(hook)
143
- {
144
- type: hook.type,
145
- id: hook.id,
146
- name: hook.name,
147
- active: hook.active,
148
- events: hook.events,
149
- config: hook.config,
150
- updated_at: hook.updated_at,
151
- created_at: hook.created_at,
152
- url: hook.url,
153
- test_url: hook.test_url,
154
- ping_url: hook.ping_url,
155
- last_response: hook.last_response
156
- }
157
- end
158
- end
159
- end
160
- end
1
+ # frozen_string_literal: true
2
+
3
+ module KExt
4
+ module Github
5
+ # Print formatted log for GitHub data such as repositories
6
+ class Printer
7
+ extend KLog::Logging
8
+
9
+ # ---------------------------------------------
10
+ # Print Repositories
11
+ # ---------------------------------------------
12
+
13
+ def self.repositories(rows = nil, format = 'default')
14
+ log.block 'Repositories'
15
+
16
+ if rows.nil?
17
+ Repository.all.each do |_r|
18
+ repository_with_format(repo, format)
19
+ end
20
+ else
21
+ rows.each do |_r|
22
+ repository_with_format(repo, format)
23
+ end
24
+ end
25
+ end
26
+
27
+ def self.repositories_as_table(rows = nil, format = 'default')
28
+ log.block 'Repositories'
29
+
30
+ rows = Repository.all if rows.nil?
31
+
32
+ case format
33
+ when 'detailed'
34
+ # tp rows
35
+ tp rows, :id, :node_id, :name, :full_name, :private, :description, :url, 'owner.login', :created_at, :updated_at, :pushed_at, :git_url
36
+ else
37
+ tp rows, :id, :name, :git_url, :full_name, :private, :description, :url, 'owner.login'
38
+ end
39
+ end
40
+
41
+ def self.repository_with_format(repo, format)
42
+ case format
43
+ when 'detailed'
44
+ repository_detailed(repo)
45
+ else
46
+ repository(repo)
47
+ end
48
+ end
49
+
50
+ def self.repository(repo)
51
+ data = repo_key_values(repo)
52
+
53
+ log.kv_hash(data)
54
+ log.line
55
+ end
56
+
57
+ def self.repository_detailed(repo)
58
+ data = repo_key_values(repo)
59
+
60
+ log.kv_hash(data)
61
+ log.line
62
+
63
+ # Print Relations
64
+
65
+ log.line
66
+ end
67
+
68
+ # ---------------------------------------------
69
+ # Print Hooks
70
+ # ---------------------------------------------
71
+
72
+ def self.hooks(rows = nil, format = 'default')
73
+ log.block 'Hooks'
74
+
75
+ if rows.nil?
76
+ Hook.all.each do |_r|
77
+ hook_with_format(repo, format)
78
+ end
79
+ else
80
+ rows.each do |_r|
81
+ hook_with_format(repo, format)
82
+ end
83
+ end
84
+ end
85
+
86
+ def self.hooks_as_table(rows = nil, format = 'default')
87
+ log.block 'Hooks'
88
+
89
+ rows = Hook.all if rows.nil?
90
+
91
+ case format
92
+ when 'detailed'
93
+ tp rows, :type, :id, :name, :active, :events, :config, :updated_at, :created_at, :url, :test_url, :ping_url, :last_response
94
+ else
95
+ tp rows, :type, :id, :name, :active, :url, :config
96
+ end
97
+ end
98
+
99
+ def self.hook_with_format(repo, format)
100
+ case format
101
+ when 'detailed'
102
+ hook_detailed(repo)
103
+ else
104
+ hook(repo)
105
+ end
106
+ end
107
+
108
+ def self.hook(hook)
109
+ hook_key_values(hook).each do |key_value|
110
+ log.kv key_value.key, key_value.vale
111
+ end
112
+
113
+ log.line
114
+ end
115
+
116
+ def self.hook_detailed(hook)
117
+ hook_key_values(hook).each do |key_value|
118
+ log.kv key_value.key, key_value.vale
119
+ end
120
+
121
+ # Print Relations
122
+
123
+ log.line
124
+ end
125
+
126
+ def self.repo_key_values(repo)
127
+ {
128
+ id: repo.id,
129
+ node_id: repo.node_id,
130
+ name: repo.name,
131
+ full_name: repo.full_name,
132
+ private: repo.private,
133
+ description: repo.description,
134
+ url: repo.url,
135
+ created_at: repo.created_at,
136
+ updated_at: repo.updated_at,
137
+ pushed_at: repo.pushed_at,
138
+ git_url: repo.git_url
139
+ }
140
+ end
141
+
142
+ def self.hook_key_values(hook)
143
+ {
144
+ type: hook.type,
145
+ id: hook.id,
146
+ name: hook.name,
147
+ active: hook.active,
148
+ events: hook.events,
149
+ config: hook.config,
150
+ updated_at: hook.updated_at,
151
+ created_at: hook.created_at,
152
+ url: hook.url,
153
+ test_url: hook.test_url,
154
+ ping_url: hook.ping_url,
155
+ last_response: hook.last_response
156
+ }
157
+ end
158
+ end
159
+ end
160
+ end
@@ -1,7 +1,7 @@
1
- # frozen_string_literal: true
2
-
3
- module KExt
4
- module Github
5
- VERSION = '0.0.2'
6
- end
7
- end
1
+ # frozen_string_literal: true
2
+
3
+ module KExt
4
+ module Github
5
+ VERSION = '0.0.3'
6
+ end
7
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: k_ext-github
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Cruwys
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-04-17 00:00:00.000000000 Z
11
+ date: 2021-04-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: k_log
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: 0.0.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: k_util
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.0.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.0.0
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: octokit
43
57
  requirement: !ruby/object:Gem::Requirement