qa_release_tasks 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
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,75 @@
1
+ require 'rubygems'
2
+ require 'rake/gempackagetask'
3
+ require 'rubygems/specification'
4
+ require 'date'
5
+ require 'spec/rake/spectask'
6
+
7
+ require 'lib/qa_release_tasks'
8
+
9
+ GEM = "qa_release_tasks"
10
+ GEM_VERSION = QaReleaseTasks.version
11
+ AUTHORS = "Jason Noble", "Rein Henrichs"
12
+ SUMMARY = "A gem that provides workflow driven rake tasks for git QA branch management"
13
+
14
+ spec = Gem::Specification.new do |s|
15
+ s.name = GEM
16
+ s.version = GEM_VERSION
17
+ s.platform = Gem::Platform::RUBY
18
+ s.has_rdoc = true
19
+ s.extra_rdoc_files = ["README", "LICENSE"]
20
+ s.summary = SUMMARY
21
+ s.description = s.summary
22
+ s.authors = AUTHORS
23
+ s.executables = ['git-changelog']
24
+
25
+ s.require_path = 'lib'
26
+ s.autorequire = GEM
27
+ s.files = %w(LICENSE README Rakefile) + Dir.glob("{bin,lib,spec}/**/*")
28
+ s.homepage = ""
29
+ end
30
+
31
+ task :default => :spec
32
+
33
+ task :make => :make_spec do
34
+ system("./bin/git-changelog --help > README && ./bin/git-changelog -a --no-limit > HISTORY")
35
+ end
36
+
37
+ desc "Run specs"
38
+ Spec::Rake::SpecTask.new do |t|
39
+ t.spec_files = FileList['spec/**/*_spec.rb']
40
+ t.spec_opts = %w(-fs --color)
41
+ end
42
+
43
+ Rake::GemPackageTask.new(spec) do |pkg|
44
+ pkg.gem_spec = spec
45
+ end
46
+
47
+ desc "install the gem locally"
48
+ task :install => [:package] do
49
+ sh %{sudo gem install pkg/#{GEM}-#{GEM_VERSION}}
50
+ end
51
+
52
+ desc "create a gemspec file"
53
+ task :make_spec do
54
+ File.open("#{GEM}.gemspec", "w") do |file|
55
+ file.puts spec.to_ruby
56
+ end
57
+ end
58
+
59
+ namespace :gem do
60
+ desc "validate the gem like github does"
61
+ task :validate do
62
+ require 'rubygems/specification'
63
+ data = File.read("#{GEM}.gemspec")
64
+ spec = nil
65
+
66
+ if data !~ %r{!ruby/object:Gem::Specification}
67
+ Thread.new { spec = eval("$SAFE = 3\n#{data}") }.join
68
+ else
69
+ spec = YAML.load(data)
70
+ end
71
+
72
+ puts spec
73
+ puts spec.validate ? "OK" : "FAIL"
74
+ end
75
+ end
data/bin/git-changelog ADDED
@@ -0,0 +1,44 @@
1
+ #!/usr/bin/env ruby -wKU
2
+ require File.join(File.dirname(__FILE__), '../lib/qa_release_tasks')
3
+ require 'optparse'
4
+
5
+ options = {}
6
+ OptionParser.new do |opts|
7
+ opts.banner = "Git Changelog - Show a list of changes by version."
8
+
9
+ opts.separator ''
10
+
11
+ opts.on_tail('-h', '--help', 'Displays this help message') do
12
+ puts opts
13
+ exit
14
+ end
15
+
16
+ opts.on_tail("--version", "Show version") do
17
+ puts 'git changelog version ' + QaReleaseTasks.version
18
+ exit
19
+ end
20
+
21
+ opts.on('-l', '--limit [LIMIT]', Integer, 'Maximum commits for each version, default is 20') do |limit|
22
+ options[:limit] = limit || 20
23
+ end
24
+
25
+ opts.on('--no-limit', 'Show all commits for each version') do
26
+ options[:limit] = false
27
+ end
28
+
29
+ opts.on('-a', '--all', 'Show all versions') do
30
+ options[:all] = true
31
+ end
32
+
33
+ opts.on('--from [VERSION]',
34
+ 'Start changelog at this version. Defaults to most recent version.') do |from|
35
+ options[:from] = from
36
+ end
37
+
38
+ opts.on('--to [VERSION]',
39
+ 'End changelog at this version. Defaults to second most recent version.') do |to|
40
+ options[:to] = to
41
+ end
42
+ end.parse!
43
+
44
+ Git::ReleaseNotes.new(options).annotate!
data/lib/cli.rb ADDED
@@ -0,0 +1,49 @@
1
+ module CLI
2
+ def warn(message)
3
+ wrap(STDERR){ STDERR.puts "Warning: #{message}" }
4
+ end
5
+
6
+ def error(message)
7
+ wrap(STDERR){ STDERR.puts "Error: #{message}" }
8
+ exit 1
9
+ end
10
+
11
+ def stars(num=50)
12
+ return "*" * num
13
+ end
14
+
15
+ def wrap(stream=STDOUT)
16
+ stream.puts stars
17
+ yield
18
+ stream.puts stars
19
+ end
20
+
21
+ def ask(question, default=nil, valid_response=nil, invalid_message=nil)
22
+ loop do
23
+ print "#{question}"
24
+ print " [#{default}]" if default
25
+ print ": "
26
+ answer = STDIN.gets.chomp
27
+ answer = default if default && answer.empty?
28
+ valid = false
29
+ valid = true if valid_response.nil?
30
+ valid = true if valid_response.respond_to?(:include?) && valid_response.include?(answer)
31
+ valid = true if valid_response.respond_to?(:match) && valid_response.match(answer)
32
+ if valid
33
+ return answer
34
+ else
35
+ if valid_response.is_a?(Array)
36
+ puts invalid_message || begin
37
+ print "Invalid answer, please try again."
38
+ print " Valid answers include:\n"
39
+ puts valid_response
40
+ end
41
+ elsif valid_response.is_a?(Regexp)
42
+ puts invalid_message || "Invalid format for answer, please try again."
43
+ else
44
+ puts invalid_message || "Invalid answer, please try again."
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,55 @@
1
+ module Git
2
+ module Commands
3
+
4
+ def assert_is_git_repo
5
+ error "Not a git repository" unless is_git_repo?
6
+ end
7
+
8
+ def is_git_repo?
9
+ File.directory?('.git')
10
+ end
11
+
12
+ # figure out what branch the pwd's repo is on
13
+ def get_branch
14
+ match = Regexp.new("^# On branch (.*)").match(`git status`)
15
+ match && match[1]
16
+ end
17
+
18
+ # e.g. v1.4.3
19
+ def valid_version_regexp
20
+ /^v\d+\.\d+\.\d+/
21
+ end
22
+
23
+ # Find all version tags
24
+ def get_tags
25
+ version_regexp = valid_version_regexp
26
+ %x{git tag}.split.grep(version_regexp).sort_by{|v| v.split('.').map{|nbr| nbr[/\d+/].to_i}}.map{|tag| tag.strip}
27
+ end
28
+
29
+ def next_version(options={})
30
+ latest_tag = get_tags.last
31
+ return 'v0.0.1' unless latest_tag
32
+
33
+ unless latest_tag.match valid_version_regexp
34
+ warn "invalid version number"
35
+ return latest_tag
36
+ end
37
+
38
+ major, minor, point = latest_tag.split('.')
39
+ major = major[1..-1]
40
+ if options[:major]
41
+ major.succ!
42
+ minor, point = '0', '0'
43
+ elsif options[:minor]
44
+ minor.succ!
45
+ point = '0'
46
+ elsif options[:point]
47
+ point.succ!
48
+ else
49
+ warn "unable to increment version number."
50
+ end
51
+
52
+ 'v' + [major, minor, point].join('.')
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,42 @@
1
+ module Git
2
+ class ReleaseNotes
3
+ require 'enumerator'
4
+ include CLI
5
+ include Commands
6
+
7
+ attr_reader :options
8
+ def initialize(options = {})
9
+ @options = options
10
+ end
11
+
12
+ def annotate!
13
+ assert_is_git_repo
14
+ tags = get_tags.reverse
15
+ error "No version tags available." if tags.empty?
16
+
17
+ if options[:all]
18
+ start_index = 0
19
+ end_index = tags.length - 1
20
+ else
21
+ start_tag = options[:from] || ask("Start at which tag?", tags[0], tags)
22
+ start_index = tags.index(start_tag)
23
+ end_tag = options[:to] || ask("End at which tag?", tags[start_index + 1] || tags[start_index], tags)
24
+ end_index = tags.index(end_tag) + 1 # include end tag
25
+ end
26
+
27
+ start_index.upto(end_index-1) do |i|
28
+ start = tags[i]
29
+ finish = tags[i+1]
30
+ range = ''
31
+ range << "refs/tags/#{finish}.." if finish # log until end tag if there is an end tag
32
+ range << "refs/tags/#{start}"
33
+ log = `git log --no-merges --pretty=format:"%h %s" #{range}`.strip.split("\n")
34
+ next if log.empty?
35
+ puts "#{start}"
36
+ puts "=" * start.length
37
+ puts log
38
+ puts
39
+ end
40
+ end
41
+ end
42
+ end
data/lib/git/tagger.rb ADDED
@@ -0,0 +1,39 @@
1
+ module Git
2
+ class Tagger
3
+ include CLI
4
+ include Commands
5
+
6
+ attr_reader :options
7
+ def initialize(options)
8
+ @options = options
9
+ end
10
+
11
+ def tag!
12
+ assert_is_git_repo
13
+ begin
14
+ fetch_tags
15
+ tag_next_version(options)
16
+ push_tags
17
+ end
18
+ end
19
+
20
+ private
21
+
22
+ def fetch_tags
23
+ system("git fetch --tags")
24
+ end
25
+
26
+ def tag_next_version(options={})
27
+ tag = next_version(options)
28
+ if options[:update]
29
+ invalid_message = "Invalid version. Version must be in the format: \"v1.2.3\""
30
+ tag = ask "Name of new version tag ", tag, valid_version_regexp, invalid_message
31
+ end
32
+ system "git tag -am'Tagged by qa_release_tasks gem' #{tag}"
33
+ end
34
+
35
+ def push_tags
36
+ system "git push --tags"
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,14 @@
1
+ $:.unshift File.join(File.dirname(__FILE__))
2
+ require 'cli'
3
+ require 'git/commands'
4
+ require 'git/release_notes'
5
+ require 'git/tagger'
6
+ require 'tasks/qa_release'
7
+
8
+ module QaReleaseTasks
9
+ VERSION = '1.1.0'
10
+
11
+ def self.version
12
+ VERSION
13
+ end
14
+ end
@@ -0,0 +1,18 @@
1
+ namespace :qa do
2
+ namespace :release do
3
+ desc "Create a new minor version release from master."
4
+ task :new do
5
+ Git::Tagger.new(:minor => true, :update => true).tag!
6
+ end
7
+
8
+ desc "Create a new point version release from qa branch."
9
+ task :update do
10
+ Git::Tagger.new(:point => true).tag!
11
+ end
12
+
13
+ desc "Add release notes for a given tag based on commit summaries"
14
+ task :notes do
15
+ Git::ReleaseNotes.new.annotate!
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,5 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ # Load rake file
5
+ import "#{File.dirname(__FILE__)}/qa_release.rake"
@@ -0,0 +1,7 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe "qa_release_tasks" do
4
+ it "should do nothing" do
5
+ true.should == true
6
+ end
7
+ end
@@ -0,0 +1,2 @@
1
+ $TESTING=true
2
+ $:.push File.join(File.dirname(__FILE__), '..', 'lib')
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: qa_release_tasks
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 1
7
+ - 1
8
+ - 0
9
+ version: 1.1.0
10
+ platform: ruby
11
+ authors:
12
+ - Jason Noble
13
+ - Rein Henrichs
14
+ autorequire: qa_release_tasks
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-06-21 00:00:00 -04:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: A gem that provides workflow driven rake tasks for git QA branch management
23
+ email:
24
+ executables:
25
+ - git-changelog
26
+ extensions: []
27
+
28
+ extra_rdoc_files:
29
+ - README
30
+ - LICENSE
31
+ files:
32
+ - LICENSE
33
+ - README
34
+ - Rakefile
35
+ - bin/git-changelog
36
+ - lib/cli.rb
37
+ - lib/git/commands.rb
38
+ - lib/git/release_notes.rb
39
+ - lib/git/tagger.rb
40
+ - lib/qa_release_tasks.rb
41
+ - lib/tasks/qa_release.rake
42
+ - lib/tasks/qa_release.rb
43
+ - spec/qa_release_tasks_spec.rb
44
+ - spec/spec_helper.rb
45
+ has_rdoc: true
46
+ homepage: ""
47
+ licenses: []
48
+
49
+ post_install_message:
50
+ rdoc_options: []
51
+
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ segments:
59
+ - 0
60
+ version: "0"
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ segments:
66
+ - 0
67
+ version: "0"
68
+ requirements: []
69
+
70
+ rubyforge_project:
71
+ rubygems_version: 1.3.6
72
+ signing_key:
73
+ specification_version: 3
74
+ summary: A gem that provides workflow driven rake tasks for git QA branch management
75
+ test_files: []
76
+