repos_report 1.1.2 → 2.0.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1b16cafc516d147399b90a3f72110a18e73f24bf
4
- data.tar.gz: 6e1c351baf6958132bd3964e551c42d65f66aedd
3
+ metadata.gz: 59a7b5edfc56be0f30a032fb7f9a073625f805b2
4
+ data.tar.gz: e6bd23bdd3ae6099adb75d1d6213ca09516f3924
5
5
  SHA512:
6
- metadata.gz: 521e5d9fd9dfb985f085cfc2dfdc815d5b128db02e2fdf0d2218584ba0a2f3164bcd95a3d3f66b375d702720c7a39ea42c84de164a7b9af964f1d36474d5ed1b
7
- data.tar.gz: 80f2e32472467d2ee17a66cdd1216ba9972f149dbcc03fc6615db375c18c71c3c2556e3f88c124acae264faadd8bd69055ba2c298fba4b2eb2f1276e4bc1fce5
6
+ metadata.gz: b31dbfb62bd1a3bb65c3854a58ca82fe910778666ace509cf561757c7237c8bfe5c3fd3a41bf44289451120b166c544338913cd50a6b4f26638555c2cc65632f
7
+ data.tar.gz: a1a811dbfbbd309ab0a9f64e3257ce6a74df7a3120cabb1a0ce524f226f2d7f5198dbab33c07859d5d7bd5f31bed06dded236b9eacf4066f949e26943e3538a4
@@ -1,4 +1,3 @@
1
- require_relative 'repo_class'
2
1
  require 'colorize'
3
2
 
4
3
  class Repo
@@ -13,25 +12,11 @@ class Repo
13
12
  end
14
13
 
15
14
  def concise_status(error_indentation)
16
-
17
- whitespace_after_project_name = ' '*(error_indentation - project_name_length)
18
-
19
- message = project_name
20
- issues = [
21
- unpulled_or_unpushed_commits,
22
- uncommitted_changes
23
- ].compact.join(', ')
24
-
25
-
26
- if unpulled_or_unpushed_commits or
27
- uncommitted_changes
28
-
29
- message = "#{message}#{whitespace_after_project_name}#{issues}".red
15
+ if issues.any?
16
+ message_with_issues(error_indentation).red
30
17
  else
31
- message = "#{message}#{whitespace_after_project_name}ALL GOOD".green
18
+ message_with_no_issues(error_indentation).green
32
19
  end
33
-
34
- message
35
20
  end
36
21
 
37
22
 
@@ -42,6 +27,25 @@ class Repo
42
27
  @directory.split("/").last
43
28
  end
44
29
 
30
+ def message_with_issues(error_indentation)
31
+ project_name + whitespace_padding(error_indentation) + issues.join(', ')
32
+ end
33
+
34
+ def message_with_no_issues(error_indentation)
35
+ project_name + whitespace_padding(error_indentation) + 'ALL GOOD'
36
+ end
37
+
38
+ def whitespace_padding(error_indentation)
39
+ ' ' * (error_indentation - project_name_length)
40
+ end
41
+
42
+ def issues
43
+ [
44
+ unpulled_or_unpushed_commits,
45
+ uncommitted_changes
46
+ ].compact
47
+ end
48
+
45
49
  def unpulled_or_unpushed_commits
46
50
 
47
51
  ahead_or_behind = `cd #{@directory}; git for-each-ref --format="%(upstream:track) %(upstream:short)" | grep origin/master`
@@ -1,39 +1,33 @@
1
- class Repo
1
+ require_relative 'repo'
2
+
3
+ module RepoFinder
2
4
  class << self
3
5
 
4
- def find_all_in_or_below(directory)
5
- if folders_with_repos_in(directory).sort == folders_in(directory).sort
6
- find_all_in(directory)
6
+ def repos_in_or_below(directory)
7
+ if all_child_folders_have_repos(directory) # Base case
8
+ repos_in(directory)
9
+
7
10
  else
8
- repos = find_all_in(directory)
11
+ repos = repos_in(directory)
9
12
 
10
13
  folders_without_repos_in(directory).each do |folder|
11
- repos += find_all_in_or_below(folder)
14
+ repos += repos_in_or_below(folder)
12
15
  end
13
16
 
14
17
  repos
15
18
  end
16
19
  end
17
20
 
18
- def find_all_in(directory)
21
+ def repos_in(directory)
19
22
  return [] if folders_in(directory).empty?
20
23
 
21
24
  folders_with_repos_in(directory).map { |d| Repo.new(d) }
22
25
  end
23
26
 
24
- def indentation_of_status_for(repos)
25
- longest_project_name = repos.map(&:project_name_length).max
26
- longest_project_name + 3
27
- end
28
-
29
27
 
30
28
 
31
29
  private
32
30
 
33
- def contains_repo?(directory_path)
34
- Dir.glob("#{directory_path}/.git").any?
35
- end
36
-
37
31
  def folders_without_repos_in(directory)
38
32
  directories = folders_in(directory)
39
33
 
@@ -45,6 +39,14 @@ class Repo
45
39
  directories.select { |d| contains_repo?(d) }
46
40
  end
47
41
 
42
+ def all_child_folders_have_repos(directory)
43
+ folders_with_repos_in(directory).sort == folders_in(directory).sort
44
+ end
45
+
46
+ def contains_repo?(directory_path)
47
+ Dir.glob("#{directory_path}/.git").any?
48
+ end
49
+
48
50
  def folders_in(directory)
49
51
  Dir.glob("#{directory}/*")
50
52
  end
@@ -1,3 +1,3 @@
1
1
  module ReposReport
2
- VERSION = "1.1.2"
2
+ VERSION = "2.0.0"
3
3
  end
data/lib/repos_report.rb CHANGED
@@ -1,28 +1,46 @@
1
- require_relative 'repos_report/repo'
1
+ require_relative 'repos_report/repo_finder'
2
2
 
3
3
  module ReposReport
4
- def self.print_status_of_projects_under(directory)
5
-
6
- repos = Repo.find_all_in_or_below(directory)
4
+ class << self
5
+ def print_status_of_projects_under(directory)
6
+
7
+ repos = RepoFinder.repos_in_or_below(directory)
7
8
 
8
- puts
9
+ if repos.any?
10
+ padding_amount = whitespace_padding_for(repos)
9
11
 
10
- repos.each do |r|
11
- puts r.concise_status(Repo.indentation_of_status_for(repos))
12
+ puts
13
+
14
+ repos.each do |r|
15
+ puts r.concise_status(padding_amount)
16
+ end
17
+
18
+ puts
19
+ else
20
+ puts "No repos found in this directory."
21
+ end
12
22
  end
13
23
 
14
- puts
15
- end
24
+ def list_all_repos(directory)
25
+ repos = RepoFinder.repos_in_or_below(directory)
26
+
27
+ puts
16
28
 
17
- def self.list_all_repos(directory)
18
- repos = Repo.find_all_in_or_below(directory)
29
+ repos.each do |repo|
30
+ puts repo.directory
31
+ end
19
32
 
20
- puts
33
+ puts
34
+ end
35
+
36
+ private
21
37
 
22
- repos.each do |repo|
23
- puts repo.directory
38
+ def whitespace_padding_for(repos)
39
+ longest_repo_project_name(repos) + 3
24
40
  end
25
41
 
26
- puts
42
+ def longest_repo_project_name(array_of_repos)
43
+ array_of_repos.map(&:project_name_length).max
44
+ end
27
45
  end
28
46
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: repos_report
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - neurodynamic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-16 00:00:00.000000000 Z
11
+ date: 2016-03-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -68,7 +68,7 @@ files:
68
68
  - bin/rep2
69
69
  - lib/repos_report.rb
70
70
  - lib/repos_report/repo.rb
71
- - lib/repos_report/repo_class.rb
71
+ - lib/repos_report/repo_finder.rb
72
72
  - lib/repos_report/version.rb
73
73
  - repo_timetracker.gemspec
74
74
  homepage: https://github.com/neurodynamic/repos_report
@@ -91,7 +91,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
91
91
  version: '0'
92
92
  requirements: []
93
93
  rubyforge_project:
94
- rubygems_version: 2.4.5
94
+ rubygems_version: 2.5.1
95
95
  signing_key:
96
96
  specification_version: 4
97
97
  summary: A gem that reports on the status of all repos under a given directory.