changes_since 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e424db5e79783a8dac24b5322e62abb6eb170fb4
4
- data.tar.gz: ae1b5d68e1280f49bf8360c0827a296a95eb2de3
3
+ metadata.gz: 7905ff2ff3853d73c2af20d6437613cf816f87e6
4
+ data.tar.gz: 5d568661ae3872052038b0b138e1a9c4359bafc9
5
5
  SHA512:
6
- metadata.gz: 1dae5b200c93682a878605203d02be7d167d448c5672f143bb8fa5d4932cf5575d8f3ae95408721b865035e5dfd122272fdca483aa8000f9ae9cc09f2182cdc6
7
- data.tar.gz: 7b007f54f5cd34b8609d077449c29774fe171b134de607709659f62e9cbf05c46ca541642ccf023caf65997b32c7a4a9a9475d00ba1cf5932b675ece9720f4cd
6
+ metadata.gz: 6fd0894a4e7f79ca610c344c68f4848d9e5c8df3be18a9973f610de3f8284c61872bc32d88b26be4876379a0c487bdbed545c2c84e8261269fef899afd382b18
7
+ data.tar.gz: 6efd92684c8ef27822425a18ad91d2c333057c3dfa46a1a72e064472d84e1b5e0eaa82ee06fa0aeb3e2339f140c8922d78f0df54cee50bf26f0effa3721adc84
data/.travis.yml ADDED
@@ -0,0 +1 @@
1
+ language: ruby
data/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ [![Build Status](https://travis-ci.org/hashwin/changes_since.svg?branch=master)](https://travis-ci.org/hashwin/changes_since)
2
+
1
3
  changes_since
2
4
  =============
3
5
  A Changelog tool that helps you display a neat changelog of all pull requests merged since a certain tag.
data/Rakefile CHANGED
@@ -1,8 +1,8 @@
1
- require "bundler/gem_tasks"
2
-
3
- require "rspec/core/rake_task"
4
-
5
- RSpec::Core::RakeTask.new
6
-
7
- task :default => :spec
8
- task :test => :spec
1
+ require 'rake/testtask'
2
+ Rake::TestTask.new(:test) do |test|
3
+ test.libs << 'lib' << 'test'
4
+ test.pattern = 'test/**/*_test.rb'
5
+ test.verbose = true
6
+ end
7
+ desc "Run tests"
8
+ task :default => :test
@@ -21,5 +21,7 @@ Gem::Specification.new do |spec|
21
21
  spec.add_development_dependency "bundler", "~> 1.5"
22
22
  spec.add_development_dependency "rake", '10.1.1'
23
23
  spec.add_development_dependency 'test-unit'
24
+ spec.add_development_dependency 'mocha'
25
+ spec.add_development_dependency 'shoulda'
24
26
  spec.add_dependency "git"
25
27
  end
@@ -1,89 +1,99 @@
1
- class ChangesSince::ChangelogPrinter
2
- attr_reader :teams, :options, :repo
1
+ module ChangesSince
2
+ class ChangelogPrinter
3
+ attr_reader :teams, :options, :repo
3
4
 
4
- TAGS = {
5
- :public => 'Public',
6
- :bug => 'Bugs',
7
- :internal => 'Internal'
8
- }
5
+ TAGS = {
6
+ :public => 'Public',
7
+ :bug => 'Bugs',
8
+ :internal => 'Internal'
9
+ }
9
10
 
10
- def initialize(commits, teams, options, repo)
11
- @commits = commits
12
- @teams = teams
13
- @options = options
14
- @repo = repo
15
- end
11
+ def initialize(commits, teams, options, repo)
12
+ @commits = commits
13
+ @teams = teams
14
+ @options = options
15
+ @repo = repo
16
+ end
16
17
 
17
- def print!
18
- if teams
19
- print_team_commits!
20
- else
21
- print_commits!(@commits)
18
+ def print!
19
+ if teams
20
+ print_team_commits!
21
+ else
22
+ print_commits!(@commits)
23
+ end
24
+ return
22
25
  end
23
- return
24
- end
25
26
 
26
- def print_team_commits!
27
- teams.each do |team, members|
28
- author_re = /#{members.join("|")}/i
29
- team_commits = @commits.select do |commit|
30
- [commit.author.name, commit.author.email].any? do |str|
31
- str =~ author_re
27
+ def print_team_commits!
28
+ teams.each do |team, members|
29
+ author_re = /#{members.join("|")}/i
30
+ team_commits = @commits.select do |commit|
31
+ [commit.author.name, commit.author.email].any? do |str|
32
+ str =~ author_re
33
+ end
32
34
  end
35
+ next if team_commits.empty?
36
+ @commits -= team_commits
37
+ print_team_name(team)
38
+ print_commits!(team_commits)
33
39
  end
34
- next if team_commits.empty?
35
- @commits -= team_commits
40
+
41
+ return if @commits.empty?
42
+ print_team_name("Other")
43
+ print_commits!(@commits)
44
+ end
45
+
46
+ def print_team_name(name)
36
47
  if options[:markdown]
37
- puts "||*#{team}*||Author||PR||#{"Commit" if options[:sha]}"
48
+ row = "||*#{name}*||Author||PR||"
49
+ row << "Commit||" if options[:sha]
50
+ row << "Risks||" if options[:risks]
51
+ puts row
38
52
  else
39
- puts "\n*#{team}*\n"
53
+ puts "\n*#{name}*\n"
40
54
  end
41
- print_commits!(team_commits)
42
55
  end
43
56
 
44
- return if @commits.empty?
45
- puts "\n*Other*\n\n"
46
- @commits.each { |commit| print_message(commit, nil) }
47
- end
48
-
49
- def print_commits!(output_commits)
50
- output_commits.sort! { |a, b| a.author.name <=> b.author.name }
57
+ def print_commits!(output_commits)
58
+ output_commits.sort! { |a, b| a.author.name <=> b.author.name }
51
59
 
52
- if options[:tags]
53
- TAGS.each do |type, title|
54
- tagged_commits = output_commits.select { |commit| commit.message.include?("##{type}") }
55
- next if tagged_commits.empty?
60
+ if options[:tags]
61
+ TAGS.each do |type, title|
62
+ tagged_commits = output_commits.select { |commit| commit.message.include?("##{type}") }
63
+ next if tagged_commits.empty?
56
64
 
57
- puts "\n#{title}:\n\n"
58
- tagged_commits.each { |commit| print_message(commit, type) }
59
- output_commits -= tagged_commits
65
+ puts "\n#{title}:\n\n"
66
+ tagged_commits.each { |commit| print_message(commit, type) }
67
+ output_commits -= tagged_commits
68
+ end
69
+ return if output_commits.empty?
70
+ puts "\nUnclassified:\n\n"
60
71
  end
61
- return if output_commits.empty?
62
- puts "\nUnclassified:\n\n"
63
- end
64
72
 
65
- output_commits.each { |commit| print_message(commit, nil) }
66
- end
67
-
68
- def print_message(commit, type)
69
- message_lines = commit.message.split("\n\n")
70
- if message_lines.first =~ /Merge pull request/
71
- title = message_lines.last
72
- pr = message_lines.first.split(" from ").first.split("#").last
73
- else
74
- title = message_lines.first
73
+ output_commits.each { |commit| print_message(commit) }
75
74
  end
76
- title.gsub!("##{type}", "") if type
77
- branch_author = commit.author.name
78
- sha = commit.sha[0..9] if options[:sha]
79
- if options[:markdown]
80
- text = "|#{title}|"
81
- text << "#{branch_author}|"
82
- text << "[##{pr}|#{@repo}/pull/#{pr}]|" if @repo
83
- text << "[#{sha}|#{@repo}/commit/#{sha}]|" if sha
84
- else
85
- text = "* #{title} (#{branch_author}) #{options[:sha] ? commit.sha[0..9] : ''}"
75
+
76
+ def print_message(commit, tag=nil)
77
+ message_lines = commit.message.split("\n\n")
78
+ if message_lines.first =~ /Merge pull request/
79
+ title = message_lines.last
80
+ pr = message_lines.first.split(" from ").first.split("#").last
81
+ else
82
+ title = message_lines.first
83
+ sha = options[:sha] ? commit.sha[0..9] : ''
84
+ end
85
+ title.gsub!("##{tag}", "") if tag
86
+ branch_author = commit.author.name
87
+ if options[:markdown]
88
+ text = "|#{title}|"
89
+ text << "#{branch_author}|"
90
+ text << "[##{pr}|#{@repo}/pull/#{pr}]|" if @repo && pr
91
+ text << "[#{sha}|#{@repo}/commit/#{sha}]|" if sha
92
+ text << "|" if options[:risks]
93
+ else
94
+ text = "* #{title} (#{branch_author})"
95
+ end
96
+ puts text
86
97
  end
87
- puts text
88
98
  end
89
99
  end
@@ -1,56 +1,58 @@
1
- class ChangesSince::CommitParser
2
- attr_reader :log, :options
3
-
4
- def initialize(tag, options)
5
- git = Git.open(Dir.pwd)
6
- @log = git.log(100000).between(tag)
7
- @options = options
8
- end
1
+ module ChangesSince
2
+ class CommitParser
3
+ attr_reader :log, :options
4
+
5
+ def initialize(tag, options)
6
+ git = Git.open(Dir.pwd)
7
+ @log = git.log(100000).between(tag)
8
+ @options = options
9
+ end
9
10
 
10
- def parse_all_commits
11
- interesting = Set.new
12
- all_commits = log.to_a
11
+ def parse_all_commits
12
+ interesting = Set.new
13
+ all_commits = log.to_a
13
14
 
14
- link_re = /^\s*\[(.*?)\]/m
15
- linked_commits, remaining_commits = all_commits.partition do |commit|
16
- commit.message =~ link_re
17
- end
15
+ link_re = /^\s*\[(.*?)\]/m
16
+ linked_commits, remaining_commits = all_commits.partition do |commit|
17
+ commit.message =~ link_re
18
+ end
18
19
 
19
- linked_commits.uniq! do |commit|
20
- commit.message[link_re,1]
21
- end
20
+ linked_commits.uniq! do |commit|
21
+ commit.message[link_re,1]
22
+ end
22
23
 
23
- interesting = interesting + linked_commits
24
+ interesting = interesting + linked_commits
24
25
 
25
- interesting_re = /
26
- (?:\#(bug|public|internal)) | # anything explicitly tagged
27
- (?:closes\s\#\d+) | # a squash-merge commit closing the linked PR
28
- (?:Merge\spull\srequest) # a straight PR merge
29
- /xmi
26
+ interesting_re = /
27
+ (?:\#(bug|public|internal)) | # anything explicitly tagged
28
+ (?:closes\s\#\d+) | # a squash-merge commit closing the linked PR
29
+ (?:Merge\spull\srequest) # a straight PR merge
30
+ /xmi
30
31
 
31
- remaining_commits.each do |commit|
32
- if commit.message =~ interesting_re
33
- interesting << commit
32
+ remaining_commits.each do |commit|
33
+ if commit.message =~ interesting_re
34
+ interesting << commit
35
+ end
34
36
  end
37
+ commits = interesting.to_a
35
38
  end
36
- commits = interesting.to_a
37
- end
38
39
 
39
- def parse
40
- commits = if options[:all]
41
- parse_all_commits
42
- else
43
- log.select { |commit| commit.message =~ /Merge pull request/ }
44
- end
40
+ def parse
41
+ commits = if options[:all]
42
+ parse_all_commits
43
+ else
44
+ log.select { |commit| commit.message =~ /Merge pull request/ }
45
+ end
45
46
 
46
- if options[:author_filter]
47
- author_re = /#{options[:author_filter].join("|")}/i
48
- commits = commits.select do |commit|
49
- [commit.author.name, commit.author.email].any? do |str|
50
- str =~ author_re
47
+ if options[:author_filter]
48
+ author_re = /#{options[:author_filter].join("|")}/i
49
+ commits = commits.select do |commit|
50
+ [commit.author.name, commit.author.email].any? do |str|
51
+ str =~ author_re
52
+ end
51
53
  end
52
54
  end
55
+ commits
53
56
  end
54
- commits
55
57
  end
56
58
  end
@@ -1,3 +1,3 @@
1
1
  module ChangesSince
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
data/lib/changes_since.rb CHANGED
@@ -1,13 +1,8 @@
1
- #!/usr/bin/env ruby
2
-
3
- # Usage: To get all merged pull requests since v1.37.0
4
- # script/changes_since v1.37.0
5
-
6
1
  require 'git'
7
2
  require 'optparse'
8
3
  require 'set'
9
4
 
10
- class ChangesSince
5
+ module ChangesSince
11
6
  def self.fetch(tag, teams=nil, repo=nil)
12
7
  options = parse_options
13
8
  parser = CommitParser.new(tag, options)
@@ -0,0 +1,150 @@
1
+ require File.expand_path("../../helper", __FILE__)
2
+
3
+ class ChangelogPrinterTest < Test::Unit::TestCase
4
+
5
+ def stub_commits
6
+ [
7
+ stub(:author => stub(:name => "Rajesh", :email => "rajesh@gmail.com"), :message => "abcd"),
8
+ stub(:author => stub(:name => "Rajesh", :email => "rajesh@gmail.com"), :message => "def #bug"),
9
+ stub(:author => stub(:name => "Ankita", :email => "ankita@gmail.com"), :message => "sad #internal"),
10
+ stub(:author => stub(:name => "Rajesh", :email => "rajesh@gmail.com"), :message => "dasd"),
11
+ stub(:author => stub(:name => "Susan", :email => "susan@gmail.com"), :message => "aaaa" ),
12
+ stub(:author => stub(:name => "Rajesh", :email => "rajesh@gmail.com"), :message => "dsss"),
13
+ stub(:author => stub(:name => "Ankita", :email => "ankita@gmail.com"), :message => "ver"),
14
+ stub(:author => stub(:name => "Rajesh", :email => "rajesh@gmail.com"), :message => "sdfs #public"),
15
+ stub(:author => stub(:name => "Derek", :email => "derek@gmail.com"), :message => "sds"),
16
+ stub(:author => stub(:name => "Bob", :email => "bob@gmail.com"), :message => "bbbb")
17
+ ]
18
+ end
19
+
20
+ def stub_teams
21
+ {
22
+ "Team 1" => ["Bob", "Ankita"],
23
+ "Team 2" => ["Rajesh", "susan@gmail.com"]
24
+ }
25
+ end
26
+
27
+ context "ChangelogPrinter" do
28
+
29
+ context 'initialization' do
30
+ should "setup instance variables" do
31
+ commits = stub
32
+ teams = stub
33
+ options = stub
34
+ repo = stub
35
+ printer = ChangesSince::ChangelogPrinter.new(commits, teams, options, repo)
36
+ assert_equal printer.instance_variable_get('@commits'), commits
37
+ assert_equal printer.instance_variable_get('@teams'), teams
38
+ assert_equal printer.instance_variable_get('@options'), options
39
+ assert_equal printer.instance_variable_get('@repo'), repo
40
+ end
41
+ end
42
+
43
+ context 'print!' do
44
+ should "print team commits if present" do
45
+ commits = stub
46
+ teams = stub
47
+ printer = ChangesSince::ChangelogPrinter.new(commits, teams, stub, stub)
48
+ printer.expects(:print_team_commits!)
49
+ printer.print!
50
+ end
51
+
52
+ should "print commits if no teams present" do
53
+ commits = stub
54
+ printer = ChangesSince::ChangelogPrinter.new(commits, nil, stub, stub)
55
+ printer.expects(:print_commits!)
56
+ printer.print!
57
+ end
58
+ end
59
+
60
+ context "print_team_commits!" do
61
+ setup do
62
+ @commits = stub_commits
63
+ @teams = stub_teams
64
+ @team_commits = {
65
+ "Team 1" => @commits.select { |commit|
66
+ [commit.author.name, commit.author.email].any? { |str| str =~ /Bob|Ankita/i }
67
+ },
68
+ "Team 2" => @commits.select { |commit|
69
+ [commit.author.name, commit.author.email].any? { |str| str =~ /Rajesh|susan@gmail.com/i }
70
+ },
71
+ "Other" => @commits.select { |commit|
72
+ [commit.author.name, commit.author.email].any? { |str| str =~ /Derek/ }
73
+ }
74
+ }
75
+ end
76
+
77
+ should "divide by teams and call print commits" do
78
+ printer = ChangesSince::ChangelogPrinter.new(@commits, @teams, stub, stub)
79
+ @team_commits.each do |name, commit_set|
80
+ printer.expects(:print_team_name).with(name)
81
+ printer.expects(:print_commits!).with(commit_set)
82
+ end
83
+ printer.print_team_commits!
84
+ end
85
+
86
+ should "not print other if no commits are present" do
87
+ @commits.reject! { |commit| commit.author.name == "Derek" }
88
+ @team_commits.delete("Other")
89
+ printer = ChangesSince::ChangelogPrinter.new(@commits, @teams, stub, stub)
90
+ @team_commits.each do |name, commit_set|
91
+ printer.expects(:print_team_name).with(name)
92
+ printer.expects(:print_commits!).with(commit_set)
93
+ end
94
+ printer.expects(:print_team_name).with("Other").never
95
+ printer.print_team_commits!
96
+ end
97
+ end
98
+
99
+ context "print_commits!" do
100
+ should "call print message for each commit" do
101
+ commits = stub_commits
102
+ options = {}
103
+ printer = ChangesSince::ChangelogPrinter.new(commits, stub, options, stub)
104
+ commits.each { |commit| printer.expects(:print_message).with(commit) }
105
+ printer.print_commits!(commits)
106
+ end
107
+
108
+ should "call print message for each commit when tags are enabled" do
109
+ commits = stub_commits
110
+ options = { :tags => true }
111
+ printer = ChangesSince::ChangelogPrinter.new(commits, stub, options, stub)
112
+ tagged_commits = commits.select { |commit| commit.message =~ /public|bug|internal/ }
113
+ tagged_commits.each { |commit|
114
+ tag = commit.message.slice(commit.message.index("#") + 1, commit.message.length).to_sym
115
+ printer.expects(:print_message).with(commit, tag)
116
+ }
117
+ untagged_commits = commits - tagged_commits
118
+ untagged_commits.each { |commit| printer.expects(:print_message).with(commit) }
119
+ printer.expects(:puts).with("\nPublic:\n\n")
120
+ printer.expects(:puts).with("\nBugs:\n\n")
121
+ printer.expects(:puts).with("\nInternal:\n\n")
122
+ printer.expects(:puts).with("\nUnclassified:\n\n")
123
+ printer.print_commits!(commits)
124
+ end
125
+ end
126
+
127
+ context "print_team_name" do
128
+ should "print the team name" do
129
+ printer = ChangesSince::ChangelogPrinter.new(stub, stub, {}, stub)
130
+ printer.expects(:puts).with("\n*abc*\n")
131
+ printer.print_team_name("abc")
132
+ end
133
+
134
+ should "print the team name with markdown" do
135
+ printer = ChangesSince::ChangelogPrinter.new(stub, stub, { :markdown => true }, stub)
136
+ printer.expects(:puts).with("||*abc*||Author||PR||")
137
+ printer.print_team_name("abc")
138
+ end
139
+
140
+ should "print the team name with markdown and risks" do
141
+ printer = ChangesSince::ChangelogPrinter.new(stub, stub, { :markdown => true, :risks => true }, stub)
142
+ printer.expects(:puts).with("||*abc*||Author||PR||Risks||")
143
+ printer.print_team_name("abc")
144
+ end
145
+ end
146
+
147
+ context "print_message" do
148
+ end
149
+ end
150
+ end
@@ -1,5 +1,4 @@
1
- require 'test/unit'
2
- require 'changes_since'
1
+ require File.expand_path("../helper", __FILE__)
3
2
 
4
3
  class ChangesSinceTest < Test::Unit::TestCase
5
4
 
data/test/helper.rb ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler'
2
+ require 'test/unit'
3
+ require 'mocha'
4
+ require 'mocha/test_unit'
5
+ require 'shoulda'
6
+ require 'changes_since'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: changes_since
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ashwin Hegde
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-15 00:00:00.000000000 Z
11
+ date: 2014-04-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,34 @@ dependencies:
52
52
  - - '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: mocha
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
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: shoulda
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
55
83
  - !ruby/object:Gem::Dependency
56
84
  name: git
57
85
  requirement: !ruby/object:Gem::Requirement
@@ -75,6 +103,7 @@ extensions: []
75
103
  extra_rdoc_files: []
76
104
  files:
77
105
  - .gitignore
106
+ - .travis.yml
78
107
  - Gemfile
79
108
  - LICENSE.txt
80
109
  - README.md
@@ -84,7 +113,9 @@ files:
84
113
  - lib/changes_since/changelog_printer.rb
85
114
  - lib/changes_since/commit_parser.rb
86
115
  - lib/changes_since/version.rb
116
+ - test/changes_since/changelog_printer_test.rb
87
117
  - test/changes_since_test.rb
118
+ - test/helper.rb
88
119
  homepage: http://rubygems.org/gems/changes_since
89
120
  licenses:
90
121
  - MIT
@@ -110,4 +141,6 @@ signing_key:
110
141
  specification_version: 4
111
142
  summary: Git Changes since a tag
112
143
  test_files:
144
+ - test/changes_since/changelog_printer_test.rb
113
145
  - test/changes_since_test.rb
146
+ - test/helper.rb