rack-commit-stats 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: aa1969bb30585c2b370d5f9ab29a923e50ee917f
4
+ data.tar.gz: 39f81d487ee9d3305d0d7263d186a1fb0884541d
5
+ SHA512:
6
+ metadata.gz: 884c460c19c327de728437ad2be96d50f150109834b2db136bfe0c1227a116c92ef76167a8ec35db0bf57cbffd7d3ef1166e6a3577d9091441e0a01efd6caded
7
+ data.tar.gz: 22c23203b2085846b9de718b0e2b3ff1226a09240b328bfc5cb2e362d21776405dfb8cfdbfd5a1212957873c3ac2e674fa680e26e8d726646d95d020e5c7383c
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Todd Bealmear
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
data/README.md ADDED
@@ -0,0 +1,80 @@
1
+ rack-commit-stats
2
+ ===========
3
+ [![Build Status](https://travis-ci.org/todd/rack-commit-stats.svg?branch=master)](https://travis-ci.org/todd/rack-commit-stats)
4
+ [![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
+ [![Code Climate](https://codeclimate.com/github/todd/rack-commit-stats/badges/gpa.svg)](https://codeclimate.com/github/todd/rack-commit-stats)
6
+ [![Dependency Status](https://gemnasium.com/todd/rack-commit-stats.svg)](https://gemnasium.com/todd/rack-commit-stats)
7
+
8
+ rack-commit-stats is a Rack application that will display information about the
9
+ commit at a Git repository's HEAD. It's primary use case is for mounting within
10
+ another Rack-based application to display a quickly accessible digest of commit
11
+ information for that app; this is useful to quickly see what branch and commit
12
+ are deployed to your server environments if you don't have other tooling already
13
+ set up for that purpose.
14
+
15
+ ## Getting Started
16
+ Add the gem to your Gemfile and run `bundle install`:
17
+ ```
18
+ gem 'rack-commit-stats'
19
+ ```
20
+ An important note: this gem is built on top of
21
+ [Rugged](https://github.com/libgit2/rugged), which requires CMake to be present
22
+ on your system. CMake should be available through your package manager of choice.
23
+
24
+ ## For Rails
25
+ 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 authentication
27
+ constraint you've established, though this is totally optional.
28
+
29
+ ```ruby
30
+ mount RackCommitStats::App => '/deploy',
31
+ constraints: YouShallNotPassConstraint.new
32
+ ```
33
+
34
+ A Railtie is provided, so no additional configuration is required unless your
35
+ `.git` directory is on a non-standard path. If it is, you can set the path
36
+ in the affected environment configuration files.
37
+
38
+ ```ruby
39
+ # production.rb
40
+ config.rack_commit_stats.repo_path = '../repo'
41
+ ```
42
+
43
+ ## For Sinatra
44
+ Simply add a new route with an endpoint of your choice and call the application
45
+ from inside of it.
46
+
47
+ ```ruby
48
+ get '/deploy' do
49
+ RackCommitStats::App.call env
50
+ end
51
+ ```
52
+
53
+ Additionally, you can configure the Git repository path if you're not using
54
+ the standard `.git` directory or your app isn't being run from the repository
55
+ root.
56
+
57
+ ```ruby
58
+ RackCommitStats.configure do |config|
59
+ config.repo_path = '../.git'
60
+ end
61
+ ```
62
+
63
+ ## Example Output
64
+ ```json
65
+ {
66
+ "branch": "master",
67
+ "commit": {
68
+ "revision": "5ec0b96f8304cc9487172375a6f953cc73d3ffd5",
69
+ "message": "I have a lovely bunch of coconuts.",
70
+ "author": {
71
+ "name": "Foo Bar",
72
+ "email": "foo@bar.com"
73
+ }
74
+ }
75
+ }
76
+ ```
77
+
78
+ ## License
79
+
80
+ Copyright 2014 Todd Bealmear. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ require 'rspec/core/rake_task'
2
+
3
+ RSpec::Core::RakeTask.new(:spec)
4
+
5
+ task :default => :spec
@@ -0,0 +1,27 @@
1
+ require 'json'
2
+
3
+ module RackCommitStats
4
+ class App
5
+ def self.call(env)
6
+ status = 200
7
+ headers = {"Content-Type" => "application/json"}
8
+
9
+ [status, headers, [response]]
10
+ end
11
+
12
+ private
13
+
14
+ def self.response
15
+ commit = Commit.new
16
+
17
+ {
18
+ branch: commit.branch,
19
+ commit: {
20
+ revision: commit.revision,
21
+ message: commit.message,
22
+ author: commit.author
23
+ }
24
+ }.to_json
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,35 @@
1
+ require 'rugged'
2
+
3
+ module RackCommitStats
4
+ class Commit
5
+ def branch
6
+ head.name.split('/').last
7
+ end
8
+
9
+ def revision
10
+ head.target_id
11
+ end
12
+
13
+ def message
14
+ commit.message.gsub /[\r\n]/, ''
15
+ end
16
+
17
+ def author
18
+ commit.author.reject { |k, _| k == :time }
19
+ end
20
+
21
+ private
22
+
23
+ def repo
24
+ @_repo ||= Rugged::Repository.new(RackCommitStats.config.repo_path)
25
+ end
26
+
27
+ def head
28
+ repo.head
29
+ end
30
+
31
+ def commit
32
+ head.target
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,12 @@
1
+ module RackCommitStats
2
+ class Railtie < Rails::Railtie
3
+ config.rack_commit_stats = ActiveSupport::OrderedOptions.new
4
+
5
+ initializer "rack-commit-stats.configure" do |app|
6
+ RackCommitStats.configure do |config|
7
+ config.repo_path = app.config.rack_commit_stats.repo_path ||
8
+ DEFAULT_REPO_PATH
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,3 @@
1
+ module RackCommitStats
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,17 @@
1
+ module RackCommitStats
2
+ require 'rack-commit-stats/app'
3
+ require 'rack-commit-stats/commit'
4
+ require 'rack-commit-stats/railtie' if defined? Rails
5
+
6
+ DEFAULT_REPO_PATH = '.git'
7
+
8
+ class Configuration < Struct.new(:repo_path); end
9
+
10
+ def self.config
11
+ @@_config ||= Configuration.new(DEFAULT_REPO_PATH)
12
+ end
13
+
14
+ def self.configure
15
+ yield self.config
16
+ end
17
+ end
@@ -0,0 +1,25 @@
1
+ # encoding: utf-8
2
+
3
+ $:.unshift File.expand_path('../lib', __FILE__)
4
+ require 'rack-commit-stats/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.required_ruby_version = '>= 1.9.3'
8
+
9
+ spec.add_dependency 'rugged', '~> 0.21.0'
10
+ spec.add_dependency 'rack', '~> 1.0'
11
+ spec.add_development_dependency 'bundler', '~> 1.0'
12
+
13
+ spec.authors = ['Todd Bealmear']
14
+ spec.description = %q{Rack application that displays current Git commit information.}
15
+ spec.email = ['todd@t0dd.io']
16
+ spec.files = %w(LICENSE README.md Rakefile rack-commit-stats.gemspec)
17
+ spec.files += Dir.glob('lib/**/*.rb')
18
+ spec.files += Dir.glob('spec/**/*')
19
+ spec.homepage = 'https://github.com/todd/rack-commit-stats'
20
+ spec.licenses = ['MIT']
21
+ spec.name = 'rack-commit-stats'
22
+ spec.require_paths = ['lib']
23
+ spec.summary = spec.description
24
+ spec.version = RackCommitStats::VERSION
25
+ end
@@ -0,0 +1 @@
1
+ ref: refs/heads/master
@@ -0,0 +1,2 @@
1
+ x��A
2
+ 1 �a�=E.0�t�iADf�=b���(���n��S��3�z�� �^�J�Tv�)[΍��ƒbC4��D�A�����pȀ[s�d���}q�e%�s�a��f��AXV�L�,�
@@ -0,0 +1 @@
1
+ ce7a40f280665ce2e7bbc10b81a91632affe15ab
@@ -0,0 +1,48 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe RackCommitStats::App do
4
+ describe '.call' do
5
+ let(:commit_double) { instance_double("Commit", commit_properties) }
6
+ let(:commit_properties) {
7
+ {
8
+ branch: 'specs',
9
+ revision: 'gibberish',
10
+ message: 'hello',
11
+ author: {name: 'Foo Bar', email: 'foo@bar.com'}
12
+ }
13
+ }
14
+ subject { described_class.call env_for("http://foobar.com") }
15
+
16
+ it 'returns a 200 status' do
17
+ status, _, _ = subject
18
+ expect(status).to eq 200
19
+ end
20
+
21
+ it 'returns headers with a JSON content-type' do
22
+ _, headers, _ = subject
23
+ expect(headers).to eq({"Content-Type" => "application/json"})
24
+ end
25
+
26
+ it 'renders a JSON object with commit details as the body' do
27
+ allow(RackCommitStats::Commit).to receive(:new).and_return commit_double
28
+ _, _, response = subject
29
+ expect(response.first).to eq(
30
+ {
31
+ branch: 'specs',
32
+ commit: {
33
+ revision: 'gibberish',
34
+ message: 'hello',
35
+ author: {
36
+ name: 'Foo Bar',
37
+ email: 'foo@bar.com'
38
+ }
39
+ }
40
+ }.to_json
41
+ )
42
+ end
43
+ end
44
+
45
+ def env_for(url, opts = {})
46
+ Rack::MockRequest.env_for(url, opts)
47
+ end
48
+ end
@@ -0,0 +1,40 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe RackCommitStats::Commit do
4
+ before do
5
+ RackCommitStats.configure do |config|
6
+ config.repo_path = 'spec/fixtures/repo'
7
+ end
8
+ end
9
+
10
+ describe '#branch' do
11
+ it 'returns the branch name at HEAD' do
12
+ expect(described_class.new.branch).to eq 'master'
13
+ end
14
+ end
15
+
16
+ describe '#revision' do
17
+ it 'returns the revision SHA at HEAD' do
18
+ expect(described_class.new.revision).to eq(
19
+ "ce7a40f280665ce2e7bbc10b81a91632affe15ab"
20
+ )
21
+ end
22
+ end
23
+
24
+ describe '#message' do
25
+ it 'returns the commit message at HEAD' do
26
+ expect(described_class.new.message).to eq "bar"
27
+ end
28
+ end
29
+
30
+ describe '#author' do
31
+ it 'returns a hash of author information for the commit at HEAD' do
32
+ expect(described_class.new.author).to eq(
33
+ {
34
+ name: 'Foo Bar',
35
+ email: 'foo@bar.com'
36
+ }
37
+ )
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe RackCommitStats do
4
+ describe '.configure' do
5
+ context 'with custom repo path' do
6
+ it 'sets the custom repo path within the configuration' do
7
+ described_class.configure { |config| config.repo_path = 'foo' }
8
+ expect(described_class.config.repo_path).to eq 'foo'
9
+ end
10
+ end
11
+
12
+ context 'without custom repo path' do
13
+ it 'sets the default repo path within the configuration' do
14
+ described_class.configure { |config| }
15
+ expect(described_class.config.repo_path).to eq '.git'
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,55 @@
1
+ if ENV['CI']
2
+ require 'coveralls'
3
+ Coveralls.wear!
4
+ else
5
+ require 'awesome_print'
6
+ require 'pry-byebug'
7
+
8
+ require 'simplecov'
9
+ SimpleCov.start
10
+ end
11
+
12
+ require 'rack'
13
+ require 'rack-commit-stats'
14
+
15
+ RSpec.configure do |config|
16
+ config.expect_with :rspec do |expectations|
17
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
18
+ end
19
+
20
+ config.mock_with :rspec do |mocks|
21
+ mocks.verify_partial_doubles = true
22
+ end
23
+
24
+ config.filter_run :focus
25
+ config.run_all_when_everything_filtered = true
26
+
27
+ config.disable_monkey_patching!
28
+
29
+ config.warnings = true
30
+
31
+ if config.files_to_run.one?
32
+ config.default_formatter = 'doc'
33
+ end
34
+
35
+ # Print the 10 slowest examples and example groups at the
36
+ # end of the spec run, to help surface which specs are running
37
+ # particularly slow.
38
+ #config.profile_examples = 10
39
+
40
+ # Run specs in random order to surface order dependencies. If you find an
41
+ # order dependency and want to debug it, you can fix the order by providing
42
+ # the seed, which is printed after each run.
43
+ # --seed 1234
44
+ config.order = :random
45
+
46
+ # Seed global randomization in this process using the `--seed` CLI option.
47
+ # Setting this allows you to use `--seed` to deterministically reproduce
48
+ # test failures related to randomization by passing the same `--seed` value
49
+ # as the one that triggered the failure.
50
+ #Kernel.srand config.seed
51
+
52
+ config.after do
53
+ RackCommitStats.class_variable_set(:@@_config, nil)
54
+ end
55
+ end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rack-commit-stats
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Todd Bealmear
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-12-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rugged
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.21.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.21.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: rack
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.0'
55
+ description: Rack application that displays current Git commit information.
56
+ email:
57
+ - todd@t0dd.io
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - LICENSE
63
+ - README.md
64
+ - Rakefile
65
+ - lib/rack-commit-stats.rb
66
+ - lib/rack-commit-stats/app.rb
67
+ - lib/rack-commit-stats/commit.rb
68
+ - lib/rack-commit-stats/railtie.rb
69
+ - lib/rack-commit-stats/version.rb
70
+ - rack-commit-stats.gemspec
71
+ - spec/fixtures/repo/HEAD
72
+ - spec/fixtures/repo/objects/ce/7a40f280665ce2e7bbc10b81a91632affe15ab
73
+ - spec/fixtures/repo/refs/heads/master
74
+ - spec/lib/rack-commit-stats/app_spec.rb
75
+ - spec/lib/rack-commit-stats/commit_spec.rb
76
+ - spec/lib/rack-commit-stats_spec.rb
77
+ - spec/spec_helper.rb
78
+ homepage: https://github.com/todd/rack-commit-stats
79
+ licenses:
80
+ - MIT
81
+ metadata: {}
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: 1.9.3
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubyforge_project:
98
+ rubygems_version: 2.2.2
99
+ signing_key:
100
+ specification_version: 4
101
+ summary: Rack application that displays current Git commit information.
102
+ test_files: []