gitview 0.1.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.
Files changed (4) hide show
  1. checksums.yaml +7 -0
  2. data/bin/gitview +51 -0
  3. data/lib/gitview.rb +168 -0
  4. metadata +76 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1439ba339382c9d5223f16b62860cbd6a0a3ef1f
4
+ data.tar.gz: 73254c49d80076f7a6299e72a88c177946dfa387
5
+ SHA512:
6
+ metadata.gz: 456c540c68aef50790e56ebaef57bea3e3041c604c0de4bb8ccc02dd326b068f8b1c8365175a9b008d12ceb2c09e5e464c125cb1c695051cdba6ab41a01baabf
7
+ data.tar.gz: 3cccd063efbd548917154c13045ae8f97dd5b74e79fc2cb3f82f9d0ead11018e996c5d211a07987af9b1dbcf1f8720c7e571121c49331e827447ced27d135b42
data/bin/gitview ADDED
@@ -0,0 +1,51 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ ##
4
+ # Driver for lib/gitview.rb
5
+ #
6
+
7
+ ### Author::Rick Crelia
8
+ ### Email::rcrelia@gmail.com
9
+
10
+ #$LOAD_PATH.unshift("#{File.dirname(__FILE__)}/../lib")
11
+ require 'gitview'
12
+
13
+ @g = Gitview.new
14
+
15
+ # check if there's a repo and bail if there isn't one
16
+ @g.repo_exists?
17
+
18
+ system "clear"
19
+
20
+ puts "------------------------------------------------------------------------"
21
+ puts "Repository: #{@g.repo_name} - (#{@g.git_version}) "
22
+ puts "------------------------------------------------------------------------"
23
+ puts ""
24
+ puts "Repo status: #{@g.repo_status}"
25
+ puts ""
26
+ puts "Total number of files: #{@g.repo_files}"
27
+ puts ""
28
+ puts "Repo user name: #{@g.repo_user}"
29
+ puts "Repo user email: #{@g.repo_email}"
30
+ puts ""
31
+ puts "Remote repo(s):"
32
+ @g.repo_remotes.each { |r| puts "#{r}" }
33
+ puts ""
34
+ puts "Number of non-master branches: #{@g.repo_branches}"
35
+ puts ""
36
+ @g.repo_commits
37
+ puts "Total number of commits: #{@g.repo_commits}"
38
+ puts " Oldest commit on: #{@g.repo_firstcommit}"
39
+ puts " Newest commit on: #{@g.repo_lastcommit}"
40
+ puts ""
41
+ puts "Most changed files: "
42
+ @g.repo_mostchanged.each { |k,v| puts " #{v} #{k}" }
43
+ puts ""
44
+ puts "Least changed files: "
45
+ @g.repo_leastchanged.each { |k,v| puts " #{v} #{k}" }
46
+ puts ""
47
+ puts "Most active committers:"
48
+ @g.repo_committers.each { |c| puts "#{c}" }
49
+ puts ""
50
+ puts "------------------------------------------------------------------------"
51
+
data/lib/gitview.rb ADDED
@@ -0,0 +1,168 @@
1
+ ##
2
+ # This class is used to gather git repo information using backticks or
3
+ # system(). None of the methods expects parameters to be passed into them.
4
+ # Future versions will take arguments for more extensible operation.
5
+
6
+ class Gitview
7
+
8
+ ### Author::Rick Crelia
9
+ ### Email::rcrelia@gmail.com
10
+
11
+ include Enumerable
12
+
13
+ ##
14
+ # Checks to see if a repo exists in the current working directory.
15
+ # If one is not found, the program is aborted.
16
+
17
+ def repo_exists?
18
+ direxists = File.directory?("./.git")
19
+ if direxists == false
20
+ abort "No repo found in current working directory!\n\n"
21
+ else
22
+ cfgexists = File.exists?("./.git/config")
23
+ if cfgexists == false
24
+ abort "No repo config found!\n\n"
25
+ else
26
+ @repo_exists = true
27
+ end
28
+ end
29
+ end
30
+
31
+ ##
32
+ # Use the name of the current working directory as the name of the
33
+ # git repository.
34
+
35
+ def repo_name
36
+ @repo_name = `git rev-parse --show-toplevel`.chomp.split("/").last
37
+ @repo_name.to_s
38
+ "#{@repo_name}"
39
+ end
40
+
41
+ ##
42
+ # Get the version of git
43
+
44
+ def git_version
45
+ @git_version = `git --version`.chomp
46
+ end
47
+
48
+ ##
49
+ # Check the repo to see if it is current or not
50
+
51
+ def repo_status
52
+ status = system("git status --porcelain -z")
53
+ if status == ""
54
+ @repo_status = "Not current!"
55
+ else
56
+ @repo_status = "Current"
57
+ end
58
+ end
59
+
60
+ ##
61
+ # Determine repo user name. If unset locally and globally, "unset" is reported.
62
+
63
+ def repo_user
64
+ local_user = `git config --local user.name`
65
+ global_user = `git config --global user.name`
66
+ if local_user == ""
67
+ @repo_user = global_user
68
+ @repo_user = "unset" if global_user == ""
69
+ else
70
+ @repo_user = local_user
71
+ end
72
+ end
73
+
74
+ ##
75
+ # Determine repo user email. If unset locally and globally, "unset@unset"
76
+ # is reported.
77
+
78
+ def repo_email
79
+ local_email = `git config --local user.email`
80
+ global_email = `git config --global user.email`
81
+ if local_email == ""
82
+ @repo_email = global_email
83
+ @repo_email = "unset@unset" if global_email == ""
84
+ else
85
+ @repo_email = local_email
86
+ end
87
+ end
88
+
89
+ ##
90
+ # Count files in the repository.
91
+
92
+ def repo_files
93
+ @repo_files = `git ls-files`.split(/\n/).length
94
+ end
95
+
96
+ ##
97
+ # Gather list of non-local copies of the repository.
98
+
99
+ def repo_remotes
100
+ @repo_remotes = `git remote -v`.split(/\n/)
101
+ end
102
+
103
+ ##
104
+ # Count branches of the repository.
105
+
106
+ def repo_branches
107
+ branches = `git branch`.split(/\n/)
108
+ @repo_branches = branches.select { |b| b !~ /master.*/ }
109
+ @repo_branches.count
110
+ end
111
+
112
+ ##
113
+ # Count total commits in the master branch excluding merges.
114
+
115
+ def repo_commits
116
+ @@repo_commits = `git log master --no-merges --reverse --format="%ai"`.split(/\n/)
117
+ @@repo_commits.count
118
+ end
119
+
120
+ ##
121
+ # Identify first commit in the repository.
122
+
123
+ def repo_firstcommit
124
+ # let's reuse the class variable @@repo_commits
125
+ @@repo_commits.first
126
+ end
127
+
128
+ ##
129
+ # Identify most recent commit in the repository.
130
+
131
+ def repo_lastcommit
132
+ # let's reuse the class variable @@repo_commits
133
+ @@repo_commits.last
134
+ end
135
+
136
+ ##
137
+ # Identify most changed files in the repository
138
+
139
+ def repo_mostchanged
140
+ changes = `git log master --pretty=format: --name-only`.split(/\n/)
141
+ mostchanged = changes.select { |c| c =~ /[[:alpha:]]/ }
142
+ deduped = Hash.new 0
143
+ mostchanged.each { |v| deduped.store(v,deduped[v]+1) }
144
+ @@allchanged = deduped.sort_by { |k, v| v }
145
+ mc = @@allchanged.last(3).reverse
146
+ @repo_mostchanged = Hash[*mc.flatten]
147
+ end
148
+
149
+ ##
150
+ # Identify least changed files in the repository, using the class array
151
+ # @@allchanged created by repo_mostchanged()
152
+
153
+ def repo_leastchanged
154
+ # let's reuse our deduped array from repo_mostchanged()
155
+ lc = @@allchanged.first(3).reverse
156
+ @repo_leastchanged = Hash[*lc.flatten]
157
+ end
158
+
159
+ ##
160
+ # Use output of git shortlog -sn and truncate to array with first 3 lines
161
+ # to create a list of the 3 most active committers to the repository.
162
+
163
+ def repo_committers
164
+ committers = `git shortlog -sn`.split(/\n/)
165
+ @repo_committers = committers.values_at(0..2)
166
+ end
167
+
168
+ end
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gitview
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Rick Crelia
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-12-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '10.4'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '10.4'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.1'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.1'
41
+ description: ''
42
+ email:
43
+ - rcrelia@gmail.com
44
+ executables:
45
+ - gitview
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - bin/gitview
50
+ - lib/gitview.rb
51
+ homepage: http://rubygems.org/gems/gitview
52
+ licenses:
53
+ - Apache License, v2.0
54
+ metadata: {}
55
+ post_install_message:
56
+ rdoc_options: []
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ requirements:
70
+ - git 1.9.0.0, or greater
71
+ rubyforge_project:
72
+ rubygems_version: 2.2.2
73
+ signing_key:
74
+ specification_version: 4
75
+ summary: Summary information and stats on a local git repository
76
+ test_files: []