Skip to content
This repository was archived by the owner on Nov 24, 2025. It is now read-only.

Commit 201ddb9

Browse files
committed
Better debugging and cleaner error handling
1 parent 5c46d9c commit 201ddb9

File tree

17 files changed

+117
-39
lines changed

17 files changed

+117
-39
lines changed

CHANGELOG.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,17 @@ All notable changes to this project will be documented in this file.
55

66
This changelog was automatically generated using [Caretaker](https://github.com/DevelopersToolbox/caretaker) by [Wolf Software](https://github.com/WolfSoftware)
77

8-
### [Unreleased](https://github.com/DevelopersToolbox/github-ripper/compare/v0.1.1...HEAD)
8+
### [v0.1.2](https://github.com/DevelopersToolbox/github-ripper/compare/v0.1.1...v0.1.2)
99

10-
- rebrand [`[head]`](https://github.com/DevelopersToolbox/github-ripper/commit/)
10+
> Released on May, 20th 2022
11+
12+
- Better debugging and cleaner error handling [`[head]`](https://github.com/DevelopersToolbox/github-ripper/commit/)
13+
14+
- rebrand [`[5c46d9c]`](https://github.com/DevelopersToolbox/github-ripper/commit/5c46d9c7fe28dc3be562c7534438fe8163633f52)
1115

1216
- Update travis slack integration due to new slack organisation [`[751d7e3]`](https://github.com/DevelopersToolbox/github-ripper/commit/751d7e3994ba8ab24052568d521dd406b773a47f)
1317

14-
### [v0.1.0](https://github.com/DevelopersToolbox/github-ripper/releases/v0.1.0)
18+
### [v0.1.1](https://github.com/DevelopersToolbox/github-ripper/compare/v0.1.0...v0.1.1)
1519

1620
> Released on June, 12th 2021
1721
@@ -21,5 +25,9 @@ This changelog was automatically generated using [Caretaker](https://github.com/
2125

2226
- Fix travis rvm versions and slack integration [`[13e051b]`](https://github.com/DevelopersToolbox/github-ripper/commit/13e051b88cf6081e2e47665332f035b77c8c4aea)
2327

28+
### [v0.1.0](https://github.com/DevelopersToolbox/github-ripper/releases/v0.1.0)
29+
30+
> Released on March, 12th 2021
31+
2432
- The initial commit [`[d6e8c31]`](https://github.com/DevelopersToolbox/github-ripper/commit/d6e8c3134a2a0f19446da799615aeda8998bc8b4)
2533

VERSION.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.1.1
1+
0.1.2

exe/ghrip

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,23 @@ def add_flag_parameters(parser, options)
5454
[parser, options]
5555
end
5656

57+
# This method reeks of :reek:UtilityFunction, :reek:TooManyStatements
58+
def add_debug_flag_parameters(parser, options)
59+
parser.separator ''
60+
parser.separator 'Flags (Debugging):'
61+
parser.on('-D', '--debug', 'Enable debugging') { |_debug| options[:debug] = true }
62+
parser.on('-v', '--verbose', 'Verbose Output') { |_verbose| options[:verbose] = true }
63+
[parser, options]
64+
end
65+
5766
def create_parser
5867
options = DEFAULT_VALUES.dup
5968

6069
parser = init_default_parser
6170
parser, options = add_parameters(parser, options)
6271
parser, options = add_repo_flag_parameters(parser, options)
6372
parser, options = add_flag_parameters(parser, options)
73+
parser, options = add_debug_flag_parameters(parser, options)
6474

6575
[parser, options]
6676
end

lib/github-ripper.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
require 'rainbow'
66
require 'terminal-table'
77

8+
require_relative 'github-ripper/debugging'
89
require_relative 'github-ripper/function-maps'
910
require_relative 'github-ripper/git'
1011
require_relative 'github-ripper/report'
@@ -27,8 +28,15 @@ def rip(options = {})
2728
options[:use_slugs] = true
2829
options[:base_dir] = "#{File.expand_path('~')}/Downloads/Repos" unless get_option(options, :base_dir)
2930

31+
verbose(options, 'Verbose mode enabled')
32+
debug(options, 'Debug mode enabled')
33+
34+
verbose(options, 'Getting repo list')
3035
repos = get_repo_list(options)
36+
37+
verbose(options, 'Ripping repos')
3138
results = rip_repos(options, repos)
39+
3240
results, repo_count, error_count = process_results(results, options)
3341
draw_report(results, repo_count, error_count, options)
3442
end

lib/github-ripper/debugging.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#
2+
# Class docs to go here
3+
#
4+
class GithubRipper
5+
class << self
6+
#
7+
# Everything below here is private
8+
#
9+
10+
private
11+
12+
def verbose(options, message)
13+
print(Rainbow("[ VERBOSE ] #{message}\n").cyan.bright) if get_option(options, :verbose)
14+
end
15+
16+
def debug(options, message)
17+
print(Rainbow("[ DEBUG ] #{message}\n").yellow.bright) if get_option(options, :debug)
18+
end
19+
end
20+
end

lib/github-ripper/function-maps.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ class << self
2020
private
2121

2222
def function_map_lookup(options)
23+
debug(options, "Function: #{__method__}")
24+
2325
return FUNCTION_MAP[:user_repos] if flag_set?(options, :user_repos) || get_option(options, :user)
2426
return FUNCTION_MAP[:org_members_repos] if flag_set?(options, :org_members_repos)
2527
return FUNCTION_MAP[:all_repos] if flag_set?(options, :all_repos)

lib/github-ripper/git.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ class << self
1414
private
1515

1616
def get_clone_type(options)
17+
debug(options, "Function: #{__method__}")
18+
1719
return 'git clone [email protected]:' if flag_set?(options, :use_git)
1820

1921
return "git clone https://#{options[:token]}@github.com/" if get_option(options, :token)
@@ -22,14 +24,20 @@ def get_clone_type(options)
2224
end
2325

2426
def repo_full_path(options, repo)
27+
debug(options, "Function: #{__method__}")
28+
2529
"#{options[:base_dir]}/#{repo}"
2630
end
2731

2832
def repo_exists?(repo_path)
33+
debug(options, "Function: #{__method__}")
34+
2935
File.directory?(repo_path)
3036
end
3137

3238
def execute_command(command)
39+
debug(options, "Function: #{__method__}")
40+
3341
error_string = ''
3442
return_code = 0
3543

@@ -42,6 +50,8 @@ def execute_command(command)
4250
end
4351

4452
def clone_repo(options, repo, repo_path)
53+
debug(options, "Function: #{__method__}")
54+
4555
return { :repo => repo, :path => repo_path, :status => 'Dry Run', :when => 'git clone', :info => '' } if flag_set?(options, :dry_run)
4656

4757
FileUtils.mkdir_p repo_path
@@ -56,6 +66,8 @@ def clone_repo(options, repo, repo_path)
5666
end
5767

5868
def update_repo(options, repo, repo_path)
69+
debug(options, "Function: #{__method__}")
70+
5971
return { :repo => repo, :path => repo_path, :status => 'Dry Run', :when => 'git clone', :info => '' } if flag_set?(options, :dry_run)
6072

6173
olddir = Dir.pwd
@@ -71,6 +83,8 @@ def update_repo(options, repo, repo_path)
7183
end
7284

7385
def clone_repo_wrapper(options, repo)
86+
debug(options, "Function: #{__method__}")
87+
7488
repo_path = repo_full_path(options, repo)
7589

7690
return update_repo(options, repo, repo_path) if repo_exists?(repo_path)

lib/github-ripper/report.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ class << self
1010
private
1111

1212
def display_table?(error_count, options)
13+
debug(options, "Function: #{__method__}")
14+
1315
# Dry run - force display of all
1416
return true if flag_set?(options, :dry_run)
1517

@@ -27,6 +29,8 @@ def display_table?(error_count, options)
2729
# This method smells of :reek:LongParameterList, :reek:DuplicateMethodCall
2830
#
2931
def draw_report(results, repo_count, error_count, options)
32+
debug(options, "Function: #{__method__}")
33+
3034
return unless display_table?(error_count, options)
3135

3236
table = create_table

lib/github-ripper/repos.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ class << self
1212
# rubocop:disable Metrics/CyclomaticComplexity
1313
# This method smells of :reek:NilCheck
1414
def handle_required_parameters(options)
15+
debug(options, "Function: #{__method__}")
16+
1517
return if get_option(options, :token)
1618

1719
raise StandardError.new('Please supply a username (-u) or a token (-t)') if (flag_set?(options, :user_repos) || flag_set?(options, :org_members_repos) || flag_set?(options, :all_repos)) && get_option(options, :user).nil?
@@ -24,6 +26,8 @@ def handle_required_parameters(options)
2426
# docs go here
2527
#
2628
def get_repo_list(options)
29+
debug(options, "Function: #{__method__}")
30+
2731
handle_required_parameters(options)
2832

2933
function = function_map_lookup(options)
@@ -37,6 +41,8 @@ def get_repo_list(options)
3741
# This method smells of :reek:DuplicateMethodCall
3842
#
3943
def rip_repos(options, repos)
44+
debug(options, "Function: #{__method__}")
45+
4046
repo_count = repos.size
4147

4248
results = if flag_set?(options, :silent)
@@ -48,6 +54,8 @@ def rip_repos(options, repos)
4854
end
4955

5056
def process_results(results, options)
57+
debug(options, "Function: #{__method__}")
58+
5159
repo_count = count_repos(results)
5260
error_count = count_errors(results)
5361
results = filter_results(results, options)

lib/github-ripper/table.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,15 @@ class << self
1111

1212
# This method smells of :reek:UtilityFunction
1313
def create_table
14+
debug(options, "Function: #{__method__}")
15+
1416
Terminal::Table.new :headings => ['Repo', 'Path', 'Status', 'When', 'Information']
1517
end
1618

1719
# This method smells of :reek:ControlParameter, :reek:LongParameterList
1820
def add_title(table, repo_count, error_count, options)
21+
debug(options, "Function: #{__method__}")
22+
1923
title = "There were #{error_count} #{plural(error_count, 'error')}"
2024
title += " from #{repo_count} #{plural(repo_count, 'repository', 'respositories')}" if flag_set?(options, :full_report) || flag_set?(options, :dry_run)
2125

@@ -25,24 +29,32 @@ def add_title(table, repo_count, error_count, options)
2529

2630
# This method smells of :reek:UtilityFunction, :reek:ControlParameter
2731
def visible_row?(repo, options)
32+
debug(options, "Function: #{__method__}")
33+
2834
# Dry run - force display of all
2935
return true if flag_set?(options, :dry_run)
3036

3137
repo[:status] == 'Failed' || flag_set?(options, :full_report)
3238
end
3339

3440
def add_single_row(table, repo, options)
41+
debug(options, "Function: #{__method__}")
42+
3543
status = repo[:status]
3644
table.add_row [set_colour(repo[:repo], status), set_colour(repo[:path], status), set_colour(status, status), set_colour(repo[:when], status), set_colour(repo[:info], status)] if visible_row?(repo, options)
3745
table
3846
end
3947

4048
def add_rows(table, results, options)
49+
debug(options, "Function: #{__method__}")
50+
4151
results.each { |repo| table = add_single_row(table, repo, options) }
4252
table
4353
end
4454

4555
def display_table(table)
56+
debug(options, "Function: #{__method__}")
57+
4658
puts table
4759
end
4860
end

0 commit comments

Comments
 (0)