augit 0.0.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2309674756759ab5ecec61613fc5ee70ef94a7e1
4
+ data.tar.gz: 4076dc8852e2b58bedfde0a1e28dd0d60927ed08
5
+ SHA512:
6
+ metadata.gz: 4673ad51463400f89d6695281a2ad96cc0ea96548122e16cf8928f7cca666952f961b7729855070b3a7080a022ef40f30e5efd18f3829637f839272f07f187c3
7
+ data.tar.gz: 9cf0807546cc59e07937784f8cbb1f01e5fdb70ecb0643e184a6b827331926e4e08d275e8377dbb895e36841364735bc8012f60075ec350be4fc5258449f181a
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in augit.gemspec
4
+ gemspec
@@ -0,0 +1,57 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ augit (0.0.1)
5
+ actionview
6
+ colorize
7
+ highline
8
+ thor
9
+
10
+ GEM
11
+ remote: https://rubygems.org/
12
+ specs:
13
+ actionview (4.2.1)
14
+ activesupport (= 4.2.1)
15
+ builder (~> 3.1)
16
+ erubis (~> 2.7.0)
17
+ rails-dom-testing (~> 1.0, >= 1.0.5)
18
+ rails-html-sanitizer (~> 1.0, >= 1.0.1)
19
+ activesupport (4.2.1)
20
+ i18n (~> 0.7)
21
+ json (~> 1.7, >= 1.7.7)
22
+ minitest (~> 5.1)
23
+ thread_safe (~> 0.3, >= 0.3.4)
24
+ tzinfo (~> 1.1)
25
+ builder (3.2.2)
26
+ colorize (0.7.5)
27
+ erubis (2.7.0)
28
+ highline (1.7.1)
29
+ i18n (0.7.0)
30
+ json (1.8.2)
31
+ loofah (2.0.1)
32
+ nokogiri (>= 1.5.9)
33
+ mini_portile (0.6.2)
34
+ minitest (5.5.1)
35
+ nokogiri (1.6.6.2)
36
+ mini_portile (~> 0.6.0)
37
+ rails-deprecated_sanitizer (1.0.3)
38
+ activesupport (>= 4.2.0.alpha)
39
+ rails-dom-testing (1.0.6)
40
+ activesupport (>= 4.2.0.beta, < 5.0)
41
+ nokogiri (~> 1.6.0)
42
+ rails-deprecated_sanitizer (>= 1.0.1)
43
+ rails-html-sanitizer (1.0.2)
44
+ loofah (~> 2.0)
45
+ rake (10.4.2)
46
+ thor (0.19.1)
47
+ thread_safe (0.3.5)
48
+ tzinfo (1.2.2)
49
+ thread_safe (~> 0.1)
50
+
51
+ PLATFORMS
52
+ ruby
53
+
54
+ DEPENDENCIES
55
+ augit!
56
+ bundler (~> 1.7)
57
+ rake (~> 10.0)
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Matthew Werner
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.
@@ -0,0 +1,26 @@
1
+ # Augit
2
+
3
+ Audit your git branches
4
+
5
+ ## Installation
6
+
7
+ ```shell
8
+ $ gem install augit
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ Augit will inspect your repository and evaluate the age and diffs of all remote and local branches.
14
+
15
+
16
+ It will display all the remote branches that have been merged into master and give you the option of removing all of them in one go.
17
+
18
+ Augit will then iterate through all unmerged branches one by one and give you the age, author and files changed. It will also print a link to a compare page on Github.
19
+
20
+ ## Contributing
21
+
22
+ 1. Fork it ( https://github.com/[my-github-username]/augit/fork )
23
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
24
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
25
+ 4. Push to the branch (`git push origin my-new-feature`)
26
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'augit/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "augit"
8
+ spec.version = Augit::VERSION
9
+ spec.authors = ["Matthew Werner"]
10
+ spec.email = ["m@mjw.io"]
11
+ spec.summary = %q{Audit your git}
12
+ spec.description = %q{Clean up your git branches}
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_dependency 'thor'
22
+ spec.add_dependency 'colorize'
23
+ spec.add_dependency 'highline'
24
+ spec.add_dependency 'actionview'
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.7"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ end
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env ruby
2
+ require 'thor'
3
+ require 'augit'
4
+
5
+ module Augit
6
+ class Command < Thor
7
+ desc "audit", "Audit the current directory"
8
+ def audit
9
+ Augit.audit
10
+ end
11
+
12
+ private
13
+
14
+ def directory
15
+ `pwd`.rstrip
16
+ end
17
+ end
18
+ end
19
+
20
+ Augit::Command.start(ARGV)
@@ -0,0 +1,12 @@
1
+ require "augit/version"
2
+
3
+ module Augit
4
+ autoload :Repo, 'augit/repo'
5
+ autoload :Branch, 'augit/branch'
6
+ autoload :Inspector, 'augit/inspector'
7
+ autoload :Presenter, 'augit/presenter'
8
+
9
+ def self.audit(options = {})
10
+ Augit::Inspector.new.list
11
+ end
12
+ end
@@ -0,0 +1,65 @@
1
+ module Augit
2
+ class Branch
3
+ attr_reader :name, :author, :origin, :commits, :age
4
+
5
+ def initialize(name, origin)
6
+ @name = name
7
+ @origin = origin
8
+ @commits = {}
9
+ @age = Time.now
10
+
11
+ populate
12
+ end
13
+
14
+ def compare_url
15
+ "https://github.com/#{origin}/compare/#{name}"
16
+ end
17
+
18
+ def files
19
+ commits.values.flatten.uniq
20
+ end
21
+
22
+ def commit_count
23
+ commits.keys.length
24
+ end
25
+
26
+ private
27
+
28
+ def populate
29
+ sha = nil
30
+
31
+ changes.each do |line|
32
+ next if line.nil? || line == ''
33
+
34
+ checks.each do |check|
35
+ value = line.match(check[:regex])
36
+ next if value.nil?
37
+
38
+ case check[:name].to_sym
39
+ when :commit
40
+ sha = value[1]
41
+ @commits[sha] ||= []
42
+ when :author
43
+ @author = value[1]
44
+ when :file
45
+ @commits[sha] << value[1] unless sha.nil?
46
+ when :timestamp
47
+ committed_at = Time.parse(value[1])
48
+ @age = committed_at if committed_at < @age
49
+ end
50
+ end
51
+ end
52
+ end
53
+
54
+ def changes
55
+ `git whatchanged --abbrev-commit master.. origin/#{name}`.split("\n")
56
+ end
57
+
58
+ def checks
59
+ [{ name: 'commit', regex: /^commit\s(.*)/ },
60
+ { name: 'author', regex: /^Author:\s(.*)\s</ },
61
+ { name: 'timestamp', regex: /^Date:\s*(.*)$/ },
62
+ { name: 'file', regex: /^:.*\s(.*)/ }]
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,89 @@
1
+ require 'action_view'
2
+ require 'colorize'
3
+ require 'highline/import'
4
+
5
+ module Augit
6
+ class Inspector
7
+ include ::ActionView::Helpers::DateHelper
8
+ include ::ActionView::Helpers::TextHelper
9
+ attr_reader :term, :origin, :branches, :merged, :unmerged, :repo
10
+
11
+ def initialize(term = nil)
12
+ @term = term
13
+
14
+ @repo = Augit::Repo.new
15
+ @origin = repo.origin
16
+ @branches = repo.branch_names
17
+ @merged = repo.merged_branches
18
+ @unmerged = branches - merged
19
+ end
20
+
21
+ def list
22
+ print "Searching remote branches:"
23
+
24
+ if merged.any?
25
+ merged_actions
26
+ else
27
+ puts "\n> All remote branches that are merged have been deleted".green
28
+ end
29
+
30
+ if unmerged.any?
31
+ print_key
32
+ unmerged_actions
33
+ else
34
+ puts "\n> All unmerged remote branches have been deleted".green
35
+ end
36
+ end
37
+
38
+ def prompt(message)
39
+ choice = ask("#{message} |(y)es, (n)o, (q)uit|".cyan)
40
+ choice.strip.downcase.to_sym
41
+ end
42
+
43
+ def merged_actions
44
+ puts "#{pluralize(merged.length, 'branch')} merged into master:".green
45
+ puts " #{merged.join("\n ")}"
46
+
47
+ case prompt("Delete all #{merged.length} branches?")
48
+ when :y; merged.each{|branch| delete(branch) }
49
+ when :n;
50
+ when :q; exit
51
+ end
52
+ end
53
+
54
+ def unmerged_actions
55
+ unmerged.each do |branch|
56
+ presenter(branch, origin).print
57
+
58
+ case prompt("Delete #{branch}?")
59
+ when :y; delete(branch)
60
+ when :n;
61
+ when :q; exit
62
+ end
63
+ end
64
+ end
65
+
66
+ def delete(name)
67
+ print '!'.red
68
+ puts " Deleting: #{name}"
69
+ `git push origin :#{name}`
70
+ puts "Success!".green
71
+ end
72
+
73
+ def presenter(branch, origin)
74
+ Augit::Presenter.new(branch, origin)
75
+ end
76
+
77
+ private
78
+
79
+ def print_key
80
+ puts "\n#{pluralize(unmerged.length, 'branch')} not merged:"
81
+ print "RED ".red
82
+ puts " - Over a month old"
83
+ print "YELLOW".light_yellow
84
+ puts " - Over a week old"
85
+ print "GREEN ".green
86
+ puts " - Created this week"
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,54 @@
1
+ I18n.enforce_available_locales = false
2
+
3
+ module Augit
4
+ class Presenter
5
+ include ::ActionView::Helpers::DateHelper
6
+ include ::ActionView::Helpers::TextHelper
7
+
8
+ attr_reader :name, :origin
9
+
10
+ def initialize(name, origin)
11
+ @name = name
12
+ @origin = origin
13
+ end
14
+
15
+ def print
16
+ name = "#{branch.name}".send(age_color(branch.age))
17
+ commits = pluralize(branch.commit_count, 'commit')
18
+ age = distance_of_time_in_words_to_now(branch.age)
19
+ filelist = files.first(5).compact.join("\n ").light_black
20
+ ellipsis = "\n...\nand #{files.length - 5} more...".light_black
21
+
22
+ puts <<-eos
23
+
24
+ #{name}
25
+ #{branch.author}
26
+ #{commits} - #{age} ago
27
+ #{filelist}#{ellipsis if files.length > 5}
28
+ #{branch.compare_url}
29
+ eos
30
+ end
31
+
32
+ def oneline(name, origin)
33
+ info = branch_info(name, origin)
34
+ puts " #{info[:name].send(presenter.age_color(info[:age]))}"
35
+ end
36
+
37
+ def branch
38
+ @branch ||= Branch.new(name, origin)
39
+ end
40
+
41
+ def files
42
+ branch.files
43
+ end
44
+
45
+ private
46
+
47
+ def age_color(time)
48
+ return :red if time < Time.now - 4 * 7 * 24 * 60 * 60 # four weeks
49
+ return :light_yellow if time < Time.now - 1 * 7 * 24 * 60 * 60 # one week
50
+
51
+ return :green
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,26 @@
1
+ module Augit
2
+ class Repo
3
+ def initialize
4
+
5
+ end
6
+
7
+ def origin
8
+ origin = `git remote show -n origin | grep "Fetch URL:"`.match(/.*\:(.*)\./)
9
+ origin.nil? ? origin : origin[1]
10
+ end
11
+
12
+ def branch_names
13
+ `git branch -r | #{sanitize_string}`.split("\n").uniq
14
+ end
15
+
16
+ def merged_branches
17
+ `git branch -r --merged master | #{sanitize_string}`.split("\n").uniq
18
+ end
19
+
20
+ private
21
+
22
+ def sanitize_string
23
+ "grep -v master | sed \"s/ *origin\\///\" | sed \"s/ *tddium\\///\""
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,3 @@
1
+ module Augit
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,142 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: augit
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Matthew Werner
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-04-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: colorize
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: highline
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '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'
55
+ - !ruby/object:Gem::Dependency
56
+ name: actionview
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.7'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.7'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '10.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '10.0'
97
+ description: Clean up your git branches
98
+ email:
99
+ - m@mjw.io
100
+ executables:
101
+ - augit
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - Gemfile
106
+ - Gemfile.lock
107
+ - LICENSE.txt
108
+ - README.md
109
+ - Rakefile
110
+ - augit.gemspec
111
+ - bin/augit
112
+ - lib/augit.rb
113
+ - lib/augit/branch.rb
114
+ - lib/augit/inspector.rb
115
+ - lib/augit/presenter.rb
116
+ - lib/augit/repo.rb
117
+ - lib/augit/version.rb
118
+ homepage: ''
119
+ licenses:
120
+ - MIT
121
+ metadata: {}
122
+ post_install_message:
123
+ rdoc_options: []
124
+ require_paths:
125
+ - lib
126
+ required_ruby_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ required_rubygems_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ requirements: []
137
+ rubyforge_project:
138
+ rubygems_version: 2.4.3
139
+ signing_key:
140
+ specification_version: 4
141
+ summary: Audit your git
142
+ test_files: []