repos_report 1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 29a106d3799b8a729b1c6eb79cd1781adfb051ba
4
+ data.tar.gz: 59b434a6d3da4deccad501d6e066e8ae159edd47
5
+ SHA512:
6
+ metadata.gz: 542eb8fd6d8241cdf59f4ef807316602f3e8888dae03b10e068344a02606d0b04c4256688c48d1f294759a0dd85cff839c1a2dc0ac01ed5f79f71346ce8a561d
7
+ data.tar.gz: 548fb68ec935d1dc56863ee88e0dda7c588a37c3ca97b77cd08e0e8da84477e0f8da84f5c4d25b2a4497bc071882b6028476ea01079e0a571f866ba81122b592
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+
2
+ .repo_timeline
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 M
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.
data/README.md ADDED
@@ -0,0 +1,12 @@
1
+ # Purpose
2
+
3
+ Prints info on the status of all repos under a given directory.
4
+
5
+ $ gem install repos_report
6
+
7
+ ### How it works
8
+
9
+ To get a report on the status of repos in a directory:
10
+ ```
11
+ rep2 [directory]
12
+ ```
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/bin/rep2 ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../lib/repos_report'
4
+
5
+ if ARGV[0]
6
+ ReposReport.print_status_of_projects_under(ARGV[0])
7
+ else
8
+ puts "Run 'rep2 [directory_path]' get a report on the status of repos in that directory."
9
+ end
@@ -0,0 +1,61 @@
1
+ require_relative 'repo_class'
2
+ require 'colorize'
3
+
4
+ class Repo
5
+ def initialize(directory)
6
+ @directory = directory
7
+ end
8
+
9
+ def project_name_length
10
+ @directory.split("/").last.length
11
+ end
12
+
13
+ def concise_status(error_indentation)
14
+ project_name = @directory.split('/').last
15
+
16
+ error_indentation = error_indentation
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
30
+ else
31
+ message = "#{message}#{whitespace_after_project_name}ALL GOOD".green
32
+ end
33
+
34
+ message
35
+ end
36
+
37
+ def unpulled_or_unpushed_commits
38
+
39
+ ahead_or_behind = `cd #{@directory}; git for-each-ref --format="%(upstream:track) %(upstream:short)" | grep origin/master`
40
+
41
+ if ahead_or_behind.include? 'ahead'
42
+ 'UNPUSHED COMMITS'
43
+ elsif ahead_or_behind.include? 'behind'
44
+ 'UNPULLED COMMITS'
45
+ elsif `cd #{@directory}; git remote`.include? 'origin'
46
+ nil
47
+ else
48
+ 'NO REMOTE ORIGIN'
49
+ end
50
+ end
51
+
52
+ def uncommitted_changes
53
+ changes = false
54
+
55
+ changes = true if `cd #{@directory}; git status | grep 'Changes not staged for commit'`.length > 0
56
+ changes = true if `cd #{@directory}; git status | grep 'Changes to be committed'`.length > 0
57
+ changes = true if `cd #{@directory}; git status | grep 'Untracked files'`.length > 0
58
+
59
+ changes ? "UNCOMMITTED CHANGES" : nil
60
+ end
61
+ end
@@ -0,0 +1,52 @@
1
+ class Repo
2
+ class << self
3
+
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)
7
+ else
8
+ repos = find_all_in(directory)
9
+
10
+ folders_without_repos_in(directory).each do |folder|
11
+ repos += find_all_in_or_below(folder)
12
+ end
13
+
14
+ repos
15
+ end
16
+ end
17
+
18
+ def find_all_in(directory)
19
+ return [] if folders_in(directory).empty?
20
+
21
+ folders_with_repos_in(directory).map { |d| Repo.new(d) }
22
+ end
23
+
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
+
30
+
31
+ private
32
+
33
+ def contains_repo?(directory_path)
34
+ Dir.glob("#{directory_path}/.git").any?
35
+ end
36
+
37
+ def folders_without_repos_in(directory)
38
+ directories = folders_in(directory)
39
+
40
+ directories.reject { |d| contains_repo?(d) }
41
+ end
42
+
43
+ def folders_with_repos_in(directory)
44
+ directories = folders_in(directory)
45
+ directories.select { |d| contains_repo?(d) }
46
+ end
47
+
48
+ def folders_in(directory)
49
+ Dir.glob("#{directory}/*")
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,3 @@
1
+ module ReposReport
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,14 @@
1
+ require_relative 'repos_report/repo'
2
+
3
+ module ReposReport
4
+ def self.print_status_of_projects_under(directory)
5
+
6
+ repos = Repo.find_all_in_or_below(directory)
7
+
8
+ puts "STATUS OF REPOS:\n"
9
+
10
+ repos.each do |r|
11
+ puts r.concise_status(Repo.indentation_of_status_for(repos))
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'repos_report/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "repos_report"
8
+ spec.version = ReposReport::VERSION
9
+ spec.authors = ["neurodynamic"]
10
+ spec.email = ["developer@neurodynamic.io"]
11
+ spec.summary = %q{A gem that reports on the status of all repos under a given directory.}
12
+ spec.description = %q{}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "colorizer", ">= 0.0.2"
24
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: repos_report
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - neurodynamic
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-02-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: colorizer
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 0.0.2
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 0.0.2
55
+ description: ''
56
+ email:
57
+ - developer@neurodynamic.io
58
+ executables:
59
+ - rep2
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - bin/rep2
69
+ - lib/repos_report.rb
70
+ - lib/repos_report/repo.rb
71
+ - lib/repos_report/repo_class.rb
72
+ - lib/repos_report/version.rb
73
+ - repo_timetracker.gemspec
74
+ homepage: ''
75
+ licenses:
76
+ - MIT
77
+ metadata: {}
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements: []
93
+ rubyforge_project:
94
+ rubygems_version: 2.4.5
95
+ signing_key:
96
+ specification_version: 4
97
+ summary: A gem that reports on the status of all repos under a given directory.
98
+ test_files: []