git-version 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +1 -0
- data/README.md +1 -1
- data/Rakefile +6 -0
- data/config/routes.rb +1 -3
- data/git-version.gemspec +1 -1
- data/lib/generators/git_version/install/install_generator.rb +24 -0
- data/lib/generators/git_version/install/templates/config/version.txt +1 -0
- data/lib/generators/git_version/install/templates/gitattributes +2 -0
- data/lib/git-version.rb +4 -2
- data/lib/git-version/engine.rb +1 -0
- data/lib/git-version/finder.rb +26 -0
- data/lib/git-version/version.rb +2 -1
- data/spec/git-version/finder_spec.rb +33 -0
- data/spec/spec_helper.rb +12 -0
- metadata +27 -23
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7abd95f02647559aa6cec401e08d2c2edbe2da8f
|
4
|
+
data.tar.gz: b0663e91d71fac7848102c35f5dce9a45f9dbac3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1181dbe9d831a2b2a38d558c36078a7c7ad9e56370fdb12834611ee2efad293608af8372a4d67292761422b5b87679cbf9a0fb1aeb34db22d20ffbb8c767f6bd
|
7
|
+
data.tar.gz: 5f8c2d3914404c44335beb0938de6c5c743dcd9a77c918aafd0c2af638153ee5db4cd8d2f2b4962eba7b56c96b7b6d39bebf3092d2adc4b3ca36b1deeff71692
|
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/README.md
CHANGED
data/Rakefile
CHANGED
data/config/routes.rb
CHANGED
@@ -1,7 +1,5 @@
|
|
1
|
-
require 'grit'
|
2
|
-
|
3
1
|
GitVersion::Engine.routes.draw do
|
4
|
-
root :to => proc {|env| [200, {}, [
|
2
|
+
root :to => proc {|env| [200, {'Content-Type' => 'text/plain'}, [GitVersion::Finder.new.find]]}
|
5
3
|
end
|
6
4
|
|
7
5
|
Rails.application.routes.draw do
|
data/git-version.gemspec
CHANGED
@@ -0,0 +1,24 @@
|
|
1
|
+
module GitVersion
|
2
|
+
module Generators
|
3
|
+
class InstallGenerator < ::Rails::Generators::Base
|
4
|
+
|
5
|
+
desc <<DESC
|
6
|
+
Description:
|
7
|
+
Copy git-version files to your application.
|
8
|
+
DESC
|
9
|
+
|
10
|
+
def self.source_root
|
11
|
+
@source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
|
12
|
+
end
|
13
|
+
|
14
|
+
def copy_gitattributes
|
15
|
+
template 'gitattributes', '.gitattributes'
|
16
|
+
end
|
17
|
+
|
18
|
+
def copy_version
|
19
|
+
template 'config/version.txt'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
$Id$
|
data/lib/git-version.rb
CHANGED
data/lib/git-version/engine.rb
CHANGED
@@ -0,0 +1,26 @@
|
|
1
|
+
module GitVersion
|
2
|
+
class Finder
|
3
|
+
def find
|
4
|
+
from_environment || from_config_file || from_git_repo
|
5
|
+
end
|
6
|
+
|
7
|
+
private
|
8
|
+
|
9
|
+
def from_environment
|
10
|
+
ENV['COMMIT_HASH']
|
11
|
+
end
|
12
|
+
|
13
|
+
def from_config_file
|
14
|
+
version_file = File.join(Rails.root, 'config', 'version.txt')
|
15
|
+
|
16
|
+
if File.exists? version_file
|
17
|
+
File.read(version_file).match(/\$Id: ([a-zA-Z0-9]*) \$/)[1] rescue nil
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def from_git_repo
|
22
|
+
`git rev-parse HEAD`
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
data/lib/git-version/version.rb
CHANGED
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'git-version/finder'
|
3
|
+
require 'tmpdir'
|
4
|
+
require 'fileutils'
|
5
|
+
|
6
|
+
describe GitVersion::Finder do
|
7
|
+
after(:each) do
|
8
|
+
ENV['COMMIT_HASH'] = nil
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'uses the COMMIT_HASH environment variable' do
|
12
|
+
ENV['COMMIT_HASH'] = '12345'
|
13
|
+
|
14
|
+
expect(subject.find).to eq('12345')
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'uses the config/version.txt file if it exists' do
|
18
|
+
Dir.mktmpdir do |root|
|
19
|
+
Rails.root = root
|
20
|
+
FileUtils.mkdir(File.join(root, 'config'))
|
21
|
+
File.open(File.join(root, 'config', 'version.txt'), 'w') do |file|
|
22
|
+
file.write('$Id: 055c8729cdcc372500a08db659c045e16c4409fb $')
|
23
|
+
end
|
24
|
+
|
25
|
+
expect(subject.find).to eq('055c8729cdcc372500a08db659c045e16c4409fb')
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'uses the git repo if one is found' do
|
30
|
+
expect(subject.find).to eq(`git rev-parse HEAD`)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,27 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: git-version
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.3
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Darrin Holst
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2014-03-15 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
|
-
name:
|
16
|
-
requirement:
|
17
|
-
none: false
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ">="
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
|
-
type: :
|
20
|
+
type: :development
|
23
21
|
prerelease: false
|
24
|
-
version_requirements:
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
25
27
|
description: Add current git commit hash as a rails endpoint bound to /version
|
26
28
|
email:
|
27
29
|
- darrinholst@gmail.com
|
@@ -29,44 +31,46 @@ executables: []
|
|
29
31
|
extensions: []
|
30
32
|
extra_rdoc_files: []
|
31
33
|
files:
|
32
|
-
- .gitignore
|
34
|
+
- ".gitignore"
|
35
|
+
- ".rspec"
|
33
36
|
- Gemfile
|
34
37
|
- LICENSE
|
35
38
|
- README.md
|
36
39
|
- Rakefile
|
37
40
|
- config/routes.rb
|
38
41
|
- git-version.gemspec
|
42
|
+
- lib/generators/git_version/install/install_generator.rb
|
43
|
+
- lib/generators/git_version/install/templates/config/version.txt
|
44
|
+
- lib/generators/git_version/install/templates/gitattributes
|
39
45
|
- lib/git-version.rb
|
40
46
|
- lib/git-version/engine.rb
|
47
|
+
- lib/git-version/finder.rb
|
41
48
|
- lib/git-version/version.rb
|
49
|
+
- spec/git-version/finder_spec.rb
|
50
|
+
- spec/spec_helper.rb
|
42
51
|
homepage: ''
|
43
52
|
licenses: []
|
53
|
+
metadata: {}
|
44
54
|
post_install_message:
|
45
55
|
rdoc_options: []
|
46
56
|
require_paths:
|
47
57
|
- lib
|
48
58
|
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
59
|
requirements:
|
51
|
-
- -
|
60
|
+
- - ">="
|
52
61
|
- !ruby/object:Gem::Version
|
53
62
|
version: '0'
|
54
|
-
segments:
|
55
|
-
- 0
|
56
|
-
hash: 55499764461789626
|
57
63
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
-
none: false
|
59
64
|
requirements:
|
60
|
-
- -
|
65
|
+
- - ">="
|
61
66
|
- !ruby/object:Gem::Version
|
62
67
|
version: '0'
|
63
|
-
segments:
|
64
|
-
- 0
|
65
|
-
hash: 55499764461789626
|
66
68
|
requirements: []
|
67
69
|
rubyforge_project: git-version
|
68
|
-
rubygems_version:
|
70
|
+
rubygems_version: 2.2.2
|
69
71
|
signing_key:
|
70
|
-
specification_version:
|
72
|
+
specification_version: 4
|
71
73
|
summary: Add current git commit as a rails endpoint
|
72
|
-
test_files:
|
74
|
+
test_files:
|
75
|
+
- spec/git-version/finder_spec.rb
|
76
|
+
- spec/spec_helper.rb
|