versionius 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -3,6 +3,7 @@ source 'https://rubygems.org'
3
3
  gemspec
4
4
 
5
5
  gem 'grit'
6
+ gem 'versionomy'
6
7
 
7
8
  group :development do
8
9
  gem 'debugger'
@@ -1,5 +1,4 @@
1
1
  require 'versionius'
2
- require 'rake'
3
2
 
4
3
  namespace :versionius do
5
4
 
@@ -8,4 +7,24 @@ namespace :versionius do
8
7
  builder = Versionius::Builder.new('./', './public/')
9
8
  builder.run
10
9
  end
10
+
11
+ desc "Create minor tag"
12
+ task :minor do
13
+ version = Versionius::Version.new('./')
14
+ version.minor
15
+ end
16
+
17
+ desc "Create major tag"
18
+ task :major do
19
+ version = Versionius::Version.new('./')
20
+ version.major
21
+ end
22
+
23
+
24
+ desc "Create release tag"
25
+ task :release do
26
+ version = Versionius::Version.new('./')
27
+ version.release
28
+ end
11
29
  end
30
+
@@ -12,9 +12,8 @@ module Versionius
12
12
  repo = Grit::Repo.new(@repository_path)
13
13
 
14
14
  File.open(File.join(@version_file_path, Versionius::FILE_NAME), "w+") do |file|
15
- tag = repo.tags.last
16
- unless tag.nil?
17
- file.puts "#{Versionius::TAG_TITLE} #{tag.name}"
15
+ unless repo.tags.empty?
16
+ file.puts "#{Versionius::TAG_TITLE} #{repo.tags.last.name}"
18
17
 
19
18
  commits = between_tags(repo) if repo.tags.size > 1
20
19
  end
@@ -27,16 +26,9 @@ module Versionius
27
26
  end
28
27
 
29
28
  def between_tags(repo)
30
- commits = []
29
+ last = repo.tags.last
31
30
  previous = repo.tags[repo.tags.size - 2]
32
-
33
- for commit in repo.commits
34
- break if commit.id == previous.commit.id
35
-
36
- commits << commit
37
- end
38
-
39
- commits
31
+ repo.commits_between(previous.commit.id, last.commit.id)
40
32
  end
41
33
  end
42
34
 
@@ -0,0 +1,50 @@
1
+ require 'grit'
2
+ require 'versionomy'
3
+ require 'rake'
4
+
5
+ module Versionius
6
+
7
+ class Version
8
+ def initialize(project_path)
9
+ @repo = Grit::Repo.new(project_path)
10
+ @version = Versionomy.parse(tag.name)
11
+ end
12
+
13
+ def minor
14
+ change(@version.bump(2))
15
+ end
16
+
17
+ def major
18
+ change(@version.bump(1))
19
+ end
20
+
21
+ def release
22
+ change(@version.bump(0))
23
+ end
24
+
25
+ private
26
+
27
+ def tag
28
+ @repo.tags.last || NoTag.new
29
+ end
30
+
31
+ def tag_version(version)
32
+ system "git tag #{version}"
33
+ end
34
+
35
+ def git_push
36
+ system "git push --tags origin master"
37
+ end
38
+
39
+ def change(version)
40
+ tag_version(version.to_s)
41
+ git_push
42
+ end
43
+
44
+ class NoTag
45
+ def name
46
+ "0.0.0"
47
+ end
48
+ end
49
+ end
50
+ end
@@ -1,3 +1,3 @@
1
1
  module Versionius
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/versionius.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require "versionius/versionius"
2
2
  require "versionius/builder"
3
3
  require "versionius/tasks"
4
+ require "versionius/version"
4
5
 
5
6
  require "versionius/railtie" if defined?(Rails)
6
7
 
@@ -0,0 +1,72 @@
1
+ require 'spec_helper'
2
+ require 'versionomy'
3
+
4
+ include Versionius
5
+
6
+ describe Version do
7
+ before do
8
+ @repo = Grit::Repo.new(repository_path, :is_bare => true)
9
+ Grit::Repo.stub!(:new).and_return(@repo)
10
+
11
+ version.should_receive(:git_push)
12
+ end
13
+
14
+ let(:version) { Version.new(repository_path) }
15
+
16
+ context "when we have no tags in the project" do
17
+ let(:repository_path) { './spec/fixtures/commits_repo/dot_git' }
18
+
19
+ context "for minor changes" do
20
+ it "should create tag" do
21
+ version.should_receive(:tag_version).with('0.0.1').and_return
22
+
23
+ version.minor
24
+ end
25
+ end
26
+
27
+ context "for major changes" do
28
+ it "should create tag" do
29
+ version.should_receive(:tag_version).with('0.1.0').and_return
30
+
31
+ version.major
32
+ end
33
+ end
34
+
35
+ context "for release changes" do
36
+ it "should create tag" do
37
+ version.should_receive(:tag_version).with('1.0.0').and_return
38
+
39
+ version.release
40
+ end
41
+ end
42
+ end
43
+
44
+ context "when we have several tags in the project" do
45
+ let(:repository_path) { './spec/fixtures/tags_repo/dot_git' }
46
+
47
+ context "for minor changes" do
48
+ it "should increment minor version on minor changes" do
49
+ version.should_receive(:tag_version).with('0.0.3').and_return
50
+
51
+ version.minor
52
+ end
53
+ end
54
+
55
+ context "for major changes" do
56
+ it "should increment major version and minor as zero" do
57
+ version.should_receive(:tag_version).with('0.1.0').and_return
58
+
59
+ version.major
60
+ end
61
+ end
62
+
63
+ context "for release changes" do
64
+ it "should increment release version and minor, major as zero" do
65
+ version.should_receive(:tag_version).with('1.0.0').and_return
66
+
67
+ version.release
68
+ end
69
+ end
70
+ end
71
+ end
72
+
data/versionius.gemspec CHANGED
@@ -16,4 +16,5 @@ Gem::Specification.new do |gem|
16
16
  gem.version = Versionius::VERSION
17
17
 
18
18
  gem.add_dependency('grit')
19
+ gem.add_dependency('versionomy')
19
20
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: versionius
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-05 00:00:00.000000000 Z
12
+ date: 2012-05-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: grit
@@ -27,6 +27,22 @@ dependencies:
27
27
  - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
29
  version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: versionomy
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
30
46
  description: Build version txt file in the public folder
31
47
  email:
32
48
  - alex.korsak@gmail.com
@@ -47,6 +63,7 @@ files:
47
63
  - lib/versionius/builder.rb
48
64
  - lib/versionius/railtie.rb
49
65
  - lib/versionius/tasks.rb
66
+ - lib/versionius/version.rb
50
67
  - lib/versionius/versionius.rb
51
68
  - spec/builder_spec.rb
52
69
  - spec/fixtures/commits_repo/README
@@ -134,6 +151,7 @@ files:
134
151
  - spec/fixtures/tags_repo/dot_git/refs/tags/0.0.1
135
152
  - spec/fixtures/tags_repo/dot_git/refs/tags/0.0.2
136
153
  - spec/spec_helper.rb
154
+ - spec/version_spec.rb
137
155
  - versionius.gemspec
138
156
  homepage: http://github.com/oivoodoo/versionius
139
157
  licenses: []
@@ -246,3 +264,4 @@ test_files:
246
264
  - spec/fixtures/tags_repo/dot_git/refs/tags/0.0.1
247
265
  - spec/fixtures/tags_repo/dot_git/refs/tags/0.0.2
248
266
  - spec/spec_helper.rb
267
+ - spec/version_spec.rb