ReinH-git-changelog 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/LICENSE +20 -0
  2. data/README +9 -0
  3. data/Rakefile +39 -0
  4. data/bin/git-changelog +137 -0
  5. metadata +57 -0
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 PRIMEDIA
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,9 @@
1
+ Git Changelog - Show a list of changes by version.
2
+
3
+ -l, --limit [LIMIT] Maximum commits for each version, default is 20
4
+ --no-limit Show all commits for each version
5
+ -a, --all Show all versions
6
+ --from [VERSION] Start changelog at this version. Defaults to most recent version.
7
+ --to [VERSION] End changelog at this version. Defaults to second most recent version.
8
+ -h, --help Displays this help message
9
+ --version Show version
data/Rakefile ADDED
@@ -0,0 +1,39 @@
1
+ require 'rubygems'
2
+ require 'rake/gempackagetask'
3
+ require 'rubygems/specification'
4
+ require 'date'
5
+
6
+ GEM = "git-changelog"
7
+ GEM_VERSION = "0.9.0"
8
+ AUTHORS = "Jason Noble", "Rein Henrichs"
9
+ SUMMARY = "A gem that provides the git-checkout git command"
10
+
11
+ spec = Gem::Specification.new do |s|
12
+ s.name = GEM
13
+ s.version = GEM_VERSION
14
+ s.platform = Gem::Platform::RUBY
15
+ s.has_rdoc = false
16
+ s.summary = SUMMARY
17
+ s.description = s.summary
18
+ s.authors = AUTHORS
19
+ s.executables = ['git-changelog']
20
+
21
+ s.autorequire = GEM
22
+ s.files = %w(LICENSE README Rakefile bin/git-changelog)
23
+ end
24
+
25
+ Rake::GemPackageTask.new(spec) do |pkg|
26
+ pkg.gem_spec = spec
27
+ end
28
+
29
+ desc "install the gem locally"
30
+ task :install => [:package] do
31
+ sh %{sudo gem install pkg/#{GEM}-#{GEM_VERSION}}
32
+ end
33
+
34
+ desc "create a gemspec file"
35
+ task :make_spec do
36
+ File.open("#{GEM}.gemspec", "w") do |file|
37
+ file.puts spec.to_ruby
38
+ end
39
+ end
data/bin/git-changelog ADDED
@@ -0,0 +1,137 @@
1
+ #!/usr/bin/env ruby -wKU
2
+ require 'optparse'
3
+
4
+ def warn(message)
5
+ STDERR.puts "*" * 50
6
+ STDERR.puts "Warning: #{message}"
7
+ STDERR.puts "*" * 50
8
+ end
9
+
10
+ def error(message)
11
+ STDERR.puts "*" * 50
12
+ STDERR.puts "Error: #{message}"
13
+ STDERR.puts "*" * 50
14
+ exit 1
15
+ end
16
+
17
+ def ask(question, default=nil, valid_response=nil, invalid_message=nil)
18
+ loop do
19
+ print "#{question}"
20
+ print " [#{default}]" if default
21
+ print ": "
22
+ answer = STDIN.gets.chomp
23
+ answer = default if default && answer.empty?
24
+ valid = false
25
+ valid = true if valid_response.nil?
26
+ valid = true if valid_response.respond_to?(:include?) && valid_response.include?(answer)
27
+ valid = true if valid_response.respond_to?(:match) && valid_response.match(answer)
28
+ if valid
29
+ return answer
30
+ else
31
+ if valid_response.is_a?(Array)
32
+ puts invalid_message || begin
33
+ print "Invalid answer, please try again."
34
+ print " Valid answers include:\n"
35
+ puts valid_response
36
+ end
37
+ elsif valid_response.is_a?(Regexp)
38
+ puts invalid_message || "Invalid format for answer, please try again."
39
+ else
40
+ puts invalid_message || "Invalid answer, please try again."
41
+ end
42
+ end
43
+ end
44
+ end
45
+
46
+ def assert_is_git_repo
47
+ error "Not a git repository" unless is_git_repo?
48
+ end
49
+
50
+ def is_git_repo?
51
+ File.directory?('.git')
52
+ end
53
+
54
+ # e.g. v1.4.3
55
+ def valid_version_regexp
56
+ /^v\d+\.\d+\.\d+/
57
+ end
58
+
59
+ # Find all version tags
60
+ def get_tags
61
+ version_regexp = valid_version_regexp
62
+ %x{git tag}.split.grep(version_regexp).sort_by{|v| v.split('.').map{|nbr| nbr[/\d+/].to_i}}.map{|tag| tag.strip}
63
+ end
64
+
65
+ def annotate!(options)
66
+ limit = options[:limit].nil? ? 20 : options[:limit]
67
+
68
+ assert_is_git_repo
69
+ tags = get_tags.reverse
70
+ error "No version tags available." if tags.empty?
71
+
72
+ if options[:all]
73
+ start_index = 0
74
+ end_index = tags.length - 1
75
+ else
76
+ start_tag = options[:from] || ask("Start at which tag?", tags[0], tags)
77
+ start_index = tags.index(start_tag)
78
+ end_tag = options[:to] || ask("End at which tag?", tags[start_index + 1] || tags[start_index], tags)
79
+ end_index = tags.index(end_tag) + 1 # include end tag
80
+ end
81
+
82
+ start_index.upto(end_index-1) do |i|
83
+ start = tags[i]
84
+ finish = tags[i+1]
85
+ range = ''
86
+ range << "refs/tags/#{finish}.." if finish # log until end tag if there is an end tag
87
+ range << "refs/tags/#{start}"
88
+ log = `git log --no-merges --pretty=format:"%h %s" #{range}`.strip.split("\n")
89
+ next if log.empty?
90
+ puts "#{start}"
91
+ puts "=" * start.length
92
+ puts limit ? log[0,limit] : log
93
+ puts " ... and #{log.size - limit} more." if limit && log.size > limit
94
+ puts
95
+ end
96
+ end
97
+
98
+ options = {}
99
+ OptionParser.new do |opts|
100
+ opts.banner = "Git Changelog - Show a list of changes by version."
101
+
102
+ opts.separator ''
103
+
104
+ opts.on_tail('-h', '--help', 'Displays this help message') do
105
+ puts opts
106
+ exit
107
+ end
108
+
109
+ opts.on_tail("--version", "Show version") do
110
+ puts 'git changelog version ' + QaReleaseTasks.version
111
+ exit
112
+ end
113
+
114
+ opts.on('-l', '--limit [LIMIT]', Integer, 'Maximum commits for each version, default is 20') do |limit|
115
+ options[:limit] = limit || 20
116
+ end
117
+
118
+ opts.on('--no-limit', 'Show all commits for each version') do
119
+ options[:limit] = false
120
+ end
121
+
122
+ opts.on('-a', '--all', 'Show all versions') do
123
+ options[:all] = true
124
+ end
125
+
126
+ opts.on('--from [VERSION]',
127
+ 'Start changelog at this version. Defaults to most recent version.') do |from|
128
+ options[:from] = from
129
+ end
130
+
131
+ opts.on('--to [VERSION]',
132
+ 'End changelog at this version. Defaults to second most recent version.') do |to|
133
+ options[:to] = to
134
+ end
135
+ end.parse!
136
+
137
+ annotate!(options)
metadata ADDED
@@ -0,0 +1,57 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ReinH-git-changelog
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.0
5
+ platform: ruby
6
+ authors:
7
+ - Jason Noble
8
+ - Rein Henrichs
9
+ autorequire: git-changelog
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2009-04-06 00:00:00 -07:00
14
+ default_executable: git-changelog
15
+ dependencies: []
16
+
17
+ description: A gem that provides the git-checkout git command
18
+ email:
19
+ executables:
20
+ - git-changelog
21
+ extensions: []
22
+
23
+ extra_rdoc_files: []
24
+
25
+ files:
26
+ - LICENSE
27
+ - README
28
+ - Rakefile
29
+ - bin/git-changelog
30
+ has_rdoc: false
31
+ homepage:
32
+ post_install_message:
33
+ rdoc_options: []
34
+
35
+ require_paths:
36
+ - lib
37
+ required_ruby_version: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: "0"
42
+ version:
43
+ required_rubygems_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: "0"
48
+ version:
49
+ requirements: []
50
+
51
+ rubyforge_project:
52
+ rubygems_version: 1.2.0
53
+ signing_key:
54
+ specification_version: 2
55
+ summary: A gem that provides the git-checkout git command
56
+ test_files: []
57
+