rack-commit-stats 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +26 -2
- data/lib/rack-commit-stats/app.rb +20 -12
- data/lib/rack-commit-stats/commit.rb +3 -1
- data/lib/rack-commit-stats/commit_from_env.rb +31 -0
- data/lib/rack-commit-stats/railtie.rb +4 -0
- data/lib/rack-commit-stats/version.rb +1 -1
- data/lib/rack-commit-stats.rb +13 -3
- data/spec/fixtures/revisions.log +1 -0
- data/spec/lib/rack-commit-stats/app_spec.rb +41 -15
- data/spec/lib/rack-commit-stats/commit_from_env_spec.rb +42 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 33cd6390c84f95343a8d60e31c3f7502b8d32717
|
4
|
+
data.tar.gz: e23b76420f3d499816f80c067a429eac109e40d6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e86742e895139b597fce471ea999e9de4021342547d32fbbdb9b864b9165601fafc173e07ac2eb98097810da717929afe7fb7f95976e07a505d7a2bfa6f7fdd7
|
7
|
+
data.tar.gz: 98088766feac142a7ff0dda000a7639853f7300c26747ea000227ff8074846355c889b47b65ad91408c6f72f0211cddde63abd6ac814e4de56dd669a020d792a
|
data/README.md
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
rack-commit-stats
|
2
2
|
===========
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/rack-commit-stats.svg)](http://badge.fury.io/rb/rack-commit-stats)
|
3
4
|
[![Build Status](https://travis-ci.org/todd/rack-commit-stats.svg?branch=master)](https://travis-ci.org/todd/rack-commit-stats)
|
4
5
|
[![Coverage Status](https://coveralls.io/repos/todd/rack-commit-stats/badge.png?branch=master)](https://coveralls.io/r/todd/rack-commit-stats?branch=master)
|
5
6
|
[![Code Climate](https://codeclimate.com/github/todd/rack-commit-stats/badges/gpa.svg)](https://codeclimate.com/github/todd/rack-commit-stats)
|
@@ -23,7 +24,7 @@ on your system. CMake should be available through your package manager of choice
|
|
23
24
|
|
24
25
|
## For Rails
|
25
26
|
Mount the application on a new endpoint within your `routes.rb` file. You will
|
26
|
-
probably want to limit access to this endpoint using some sort of
|
27
|
+
probably want to limit access to this endpoint using some sort of authorization
|
27
28
|
constraint you've established, though this is totally optional.
|
28
29
|
|
29
30
|
```ruby
|
@@ -37,7 +38,7 @@ in the affected environment configuration files.
|
|
37
38
|
|
38
39
|
```ruby
|
39
40
|
# production.rb
|
40
|
-
config.rack_commit_stats.repo_path = '
|
41
|
+
config.rack_commit_stats.repo_path = '../.git'
|
41
42
|
```
|
42
43
|
|
43
44
|
## For Sinatra
|
@@ -60,6 +61,29 @@ RackCommitStats.configure do |config|
|
|
60
61
|
end
|
61
62
|
```
|
62
63
|
|
64
|
+
## Using with Capistrano
|
65
|
+
By default, the gem will attempt to read a Git repo on a standard path. However,
|
66
|
+
deploying with a tool like Capistrano does some things that make reading Git
|
67
|
+
state a bit trickier. The `.git` directory is moved outside of the project root
|
68
|
+
and the deployed branch is not checked out on the server. To work around this,
|
69
|
+
rack-commit-stats can read the branch and revision state from the `revisions.log`
|
70
|
+
file created by Capistrano on deploys and pull repository state based on that.
|
71
|
+
|
72
|
+
To enable this, you'll need to set a few additional configuration options:
|
73
|
+
```ruby
|
74
|
+
# Rails - production.rb (or other environment configuration file)
|
75
|
+
config.rack_commit_stats.repo_path = "../../repo"
|
76
|
+
config.rack_commit_stats.mode = :file
|
77
|
+
config.rack_commit_stats.file_path_prefix = "../../"
|
78
|
+
|
79
|
+
# Sinatra
|
80
|
+
RackCommitStats.configure do |config|
|
81
|
+
config.repo_path = "../../repo"
|
82
|
+
config.mode = :file
|
83
|
+
config.file_path_prefix = "../../"
|
84
|
+
end
|
85
|
+
```
|
86
|
+
|
63
87
|
## Example Output
|
64
88
|
```json
|
65
89
|
{
|
@@ -3,25 +3,33 @@ require 'json'
|
|
3
3
|
module RackCommitStats
|
4
4
|
class App
|
5
5
|
def self.call(env)
|
6
|
-
status
|
6
|
+
status = 200
|
7
7
|
headers = {"Content-Type" => "application/json"}
|
8
8
|
|
9
9
|
[status, headers, [response]]
|
10
10
|
end
|
11
11
|
|
12
|
-
|
12
|
+
class << self
|
13
|
+
def response
|
14
|
+
{
|
15
|
+
branch: commit.branch,
|
16
|
+
commit: {
|
17
|
+
revision: commit.revision,
|
18
|
+
message: commit.message,
|
19
|
+
author: commit.author
|
20
|
+
}
|
21
|
+
}.to_json
|
22
|
+
end
|
13
23
|
|
14
|
-
|
15
|
-
|
24
|
+
def commit
|
25
|
+
if RackCommitStats.config.file_mode?
|
26
|
+
@_commit ||= CommitFromEnv.new
|
27
|
+
else
|
28
|
+
@_commit ||= Commit.new
|
29
|
+
end
|
16
30
|
|
17
|
-
|
18
|
-
|
19
|
-
commit: {
|
20
|
-
revision: commit.revision,
|
21
|
-
message: commit.message,
|
22
|
-
author: commit.author
|
23
|
-
}
|
24
|
-
}.to_json
|
31
|
+
@_commit
|
32
|
+
end
|
25
33
|
end
|
26
34
|
end
|
27
35
|
end
|
@@ -18,12 +18,14 @@ module RackCommitStats
|
|
18
18
|
commit.author.reject { |k, _| k == :time }
|
19
19
|
end
|
20
20
|
|
21
|
-
|
21
|
+
protected
|
22
22
|
|
23
23
|
def repo
|
24
24
|
@_repo ||= Rugged::Repository.new(RackCommitStats.config.repo_path)
|
25
25
|
end
|
26
26
|
|
27
|
+
private
|
28
|
+
|
27
29
|
def head
|
28
30
|
repo.head
|
29
31
|
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module RackCommitStats
|
2
|
+
class CommitFromEnv < Commit
|
3
|
+
REVISION_LOG_FILE = 'revisions.log'
|
4
|
+
|
5
|
+
def branch
|
6
|
+
current_revision[1]
|
7
|
+
end
|
8
|
+
|
9
|
+
def revision
|
10
|
+
commit.oid
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def commit
|
16
|
+
@_commit ||= repo.lookup(sha_from_file)
|
17
|
+
end
|
18
|
+
|
19
|
+
def sha_from_file
|
20
|
+
current_revision[3].gsub(/[)]/, '')
|
21
|
+
end
|
22
|
+
|
23
|
+
def current_revision
|
24
|
+
@_current_revision ||= File.open(
|
25
|
+
File.join(
|
26
|
+
RackCommitStats.config.file_path_prefix, REVISION_LOG_FILE
|
27
|
+
), 'r'
|
28
|
+
).readlines.last.split
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -6,6 +6,10 @@ module RackCommitStats
|
|
6
6
|
RackCommitStats.configure do |config|
|
7
7
|
config.repo_path = app.config.rack_commit_stats.repo_path ||
|
8
8
|
DEFAULT_REPO_PATH
|
9
|
+
|
10
|
+
config.mode = app.config.rack_commit_stats.mode || DEFAULT_MODE
|
11
|
+
config.file_path_prefix = app.config.rack_commit_stats.file_path_prefix ||
|
12
|
+
DEFAULT_FILE_PATH_PREFIX
|
9
13
|
end
|
10
14
|
end
|
11
15
|
end
|
data/lib/rack-commit-stats.rb
CHANGED
@@ -1,14 +1,24 @@
|
|
1
1
|
module RackCommitStats
|
2
2
|
require 'rack-commit-stats/app'
|
3
3
|
require 'rack-commit-stats/commit'
|
4
|
+
require 'rack-commit-stats/commit_from_env'
|
4
5
|
require 'rack-commit-stats/railtie' if defined? Rails
|
5
6
|
|
6
|
-
DEFAULT_REPO_PATH
|
7
|
+
DEFAULT_REPO_PATH = '.git'
|
8
|
+
DEFAULT_MODE = :default
|
9
|
+
FILE_MODE = :file
|
10
|
+
DEFAULT_FILE_PATH_PREFIX = '.'
|
7
11
|
|
8
|
-
class Configuration < Struct.new(:repo_path)
|
12
|
+
class Configuration < Struct.new(:repo_path, :mode, :file_path_prefix)
|
13
|
+
def file_mode?
|
14
|
+
mode == FILE_MODE
|
15
|
+
end
|
16
|
+
end
|
9
17
|
|
10
18
|
def self.config
|
11
|
-
@@_config ||= Configuration.new(
|
19
|
+
@@_config ||= Configuration.new(
|
20
|
+
DEFAULT_REPO_PATH, DEFAULT_MODE, DEFAULT_FILE_PATH_PREFIX
|
21
|
+
)
|
12
22
|
end
|
13
23
|
|
14
24
|
def self.configure
|
@@ -0,0 +1 @@
|
|
1
|
+
Branch test_branch (at ce7a40f) deployed as release 20141210195915 by runner\n
|
@@ -23,22 +23,48 @@ RSpec.describe RackCommitStats::App do
|
|
23
23
|
expect(headers).to eq({"Content-Type" => "application/json"})
|
24
24
|
end
|
25
25
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
26
|
+
context 'default mode' do
|
27
|
+
it 'renders a JSON object with commit details as the body' do
|
28
|
+
allow(described_class).to receive(:commit).and_return commit_double
|
29
|
+
_, _, response = subject
|
30
|
+
expect(response.first).to eq(
|
31
|
+
{
|
32
|
+
branch: 'specs',
|
33
|
+
commit: {
|
34
|
+
revision: 'gibberish',
|
35
|
+
message: 'hello',
|
36
|
+
author: {
|
37
|
+
name: 'Foo Bar',
|
38
|
+
email: 'foo@bar.com'
|
39
|
+
}
|
38
40
|
}
|
39
|
-
}
|
40
|
-
|
41
|
-
|
41
|
+
}.to_json
|
42
|
+
)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context 'file mode' do
|
47
|
+
before do
|
48
|
+
RackCommitStats.configure { |config| config.mode = :file }
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'renders a JSON object with commit details as the body' do
|
52
|
+
allow(described_class).to receive(:commit).and_return commit_double
|
53
|
+
_, _, response = subject
|
54
|
+
expect(response.first).to eq(
|
55
|
+
{
|
56
|
+
branch: 'specs',
|
57
|
+
commit: {
|
58
|
+
revision: 'gibberish',
|
59
|
+
message: 'hello',
|
60
|
+
author: {
|
61
|
+
name: 'Foo Bar',
|
62
|
+
email: 'foo@bar.com'
|
63
|
+
}
|
64
|
+
}
|
65
|
+
}.to_json
|
66
|
+
)
|
67
|
+
end
|
42
68
|
end
|
43
69
|
end
|
44
70
|
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe RackCommitStats::CommitFromEnv do
|
4
|
+
before do
|
5
|
+
RackCommitStats.configure do |config|
|
6
|
+
config.repo_path = 'spec/fixtures/repo'
|
7
|
+
config.mode = :file
|
8
|
+
config.file_path_prefix = 'spec/fixtures'
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe '#branch' do
|
13
|
+
it 'returns the branch name at HEAD' do
|
14
|
+
expect(described_class.new.branch).to eq 'test_branch'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '#revision' do
|
19
|
+
it 'returns the revision SHA at HEAD' do
|
20
|
+
expect(described_class.new.revision).to eq(
|
21
|
+
"ce7a40f280665ce2e7bbc10b81a91632affe15ab"
|
22
|
+
)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe '#message' do
|
27
|
+
it 'returns the commit message at HEAD' do
|
28
|
+
expect(described_class.new.message).to eq "bar"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe '#author' do
|
33
|
+
it 'returns a hash of author information for the commit at HEAD' do
|
34
|
+
expect(described_class.new.author).to eq(
|
35
|
+
{
|
36
|
+
name: 'Foo Bar',
|
37
|
+
email: 'foo@bar.com'
|
38
|
+
}
|
39
|
+
)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-commit-stats
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Todd Bealmear
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-12-
|
11
|
+
date: 2014-12-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rugged
|
@@ -65,13 +65,16 @@ files:
|
|
65
65
|
- lib/rack-commit-stats.rb
|
66
66
|
- lib/rack-commit-stats/app.rb
|
67
67
|
- lib/rack-commit-stats/commit.rb
|
68
|
+
- lib/rack-commit-stats/commit_from_env.rb
|
68
69
|
- lib/rack-commit-stats/railtie.rb
|
69
70
|
- lib/rack-commit-stats/version.rb
|
70
71
|
- rack-commit-stats.gemspec
|
71
72
|
- spec/fixtures/repo/HEAD
|
72
73
|
- spec/fixtures/repo/objects/ce/7a40f280665ce2e7bbc10b81a91632affe15ab
|
73
74
|
- spec/fixtures/repo/refs/heads/master
|
75
|
+
- spec/fixtures/revisions.log
|
74
76
|
- spec/lib/rack-commit-stats/app_spec.rb
|
77
|
+
- spec/lib/rack-commit-stats/commit_from_env_spec.rb
|
75
78
|
- spec/lib/rack-commit-stats/commit_spec.rb
|
76
79
|
- spec/lib/rack-commit-stats_spec.rb
|
77
80
|
- spec/spec_helper.rb
|