shalala 1.0.0 → 2.0.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 +4 -4
- data/README.md +5 -1
- data/lib/shalala/app.rb +59 -0
- data/lib/shalala/engine.rb +0 -10
- data/lib/shalala/version.rb +1 -1
- data/lib/shalala.rb +1 -2
- data/shalala.gemspec +5 -6
- metadata +25 -11
- data/app/controllers/shalala/commits_controller.rb +0 -58
- data/config/routes.rb +0 -5
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2d7d98725bed220f0686428ba4216fab567d6845635c6c872780ac43cc0afc54
|
|
4
|
+
data.tar.gz: 7805862925c34b2111ab63539e7926d93d8af393624aba8e8423a2b16128af93
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: af1aa4e824ff3183bef04da95570a17aacf798f5639756e4acfd3c3e7e8d6b1fb3793e800c6ae359ddf62ca468c76d62c45b5d1df7c3db8972096aa452efbf93
|
|
7
|
+
data.tar.gz: 197f054ebdfee7c2e281fd7871e596b110c76ec954c64f74899f1a54734c72a5a033886b660d0f0f6abec0b52941e365bbfb3014b9c20f4607a94a211da0c9d5
|
data/README.md
CHANGED
|
@@ -30,7 +30,11 @@ bundle install
|
|
|
30
30
|
|
|
31
31
|
## Mounting
|
|
32
32
|
|
|
33
|
-
|
|
33
|
+
Mount the app in your Routes file:
|
|
34
|
+
|
|
35
|
+
```
|
|
36
|
+
mount Shalala::App => "/commit"
|
|
37
|
+
```
|
|
34
38
|
|
|
35
39
|
## Usage examples
|
|
36
40
|
|
data/lib/shalala/app.rb
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Shalala
|
|
4
|
+
class App
|
|
5
|
+
def self.call(env)
|
|
6
|
+
new.call(env)
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def call(env)
|
|
10
|
+
commit = resolved_commit
|
|
11
|
+
branch = resolved_branch
|
|
12
|
+
|
|
13
|
+
if commit
|
|
14
|
+
body = "commit: #{commit}\nbranch: #{branch}"
|
|
15
|
+
[200, { "content-type" => "text/plain" }, [body]]
|
|
16
|
+
else
|
|
17
|
+
[404, { "content-type" => "text/plain" }, ["Not Found"]]
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
private
|
|
22
|
+
|
|
23
|
+
def resolved_commit
|
|
24
|
+
env_commit = ENV["GIT_COMMIT"]
|
|
25
|
+
return env_commit if env_commit && !env_commit.empty?
|
|
26
|
+
return current_git_commit if development_environment?
|
|
27
|
+
|
|
28
|
+
nil
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def resolved_branch
|
|
32
|
+
env_branch = ENV["GIT_BRANCH"]
|
|
33
|
+
return env_branch if env_branch && !env_branch.empty?
|
|
34
|
+
|
|
35
|
+
current_git_branch
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def development_environment?
|
|
39
|
+
(ENV["RACK_ENV"] || "development") == "development"
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def current_git_commit
|
|
43
|
+
sha = `git rev-parse HEAD`.strip
|
|
44
|
+
$?.success? ? sha : nil
|
|
45
|
+
rescue StandardError
|
|
46
|
+
nil
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def current_git_branch
|
|
50
|
+
branch = `git branch --show-current`.strip
|
|
51
|
+
return branch if $?.success? && !branch.empty?
|
|
52
|
+
|
|
53
|
+
fallback = `git rev-parse --abbrev-ref HEAD`.strip
|
|
54
|
+
$?.success? ? fallback : nil
|
|
55
|
+
rescue StandardError
|
|
56
|
+
nil
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
data/lib/shalala/engine.rb
CHANGED
|
@@ -3,15 +3,5 @@
|
|
|
3
3
|
module Shalala
|
|
4
4
|
class Engine < ::Rails::Engine
|
|
5
5
|
isolate_namespace Shalala
|
|
6
|
-
|
|
7
|
-
initializer "shalala.mount_route" do |app|
|
|
8
|
-
app.config.to_prepare do
|
|
9
|
-
next if app.routes.named_routes.key?(:shalala)
|
|
10
|
-
|
|
11
|
-
app.routes.append do
|
|
12
|
-
mount Shalala::Engine, at: "/commit", as: :shalala
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
6
|
end
|
|
17
7
|
end
|
data/lib/shalala/version.rb
CHANGED
data/lib/shalala.rb
CHANGED
data/shalala.gemspec
CHANGED
|
@@ -9,22 +9,21 @@ Gem::Specification.new do |spec|
|
|
|
9
9
|
spec.authors = ["Ryan Bigg"]
|
|
10
10
|
spec.email = ["ryan@example.com"]
|
|
11
11
|
|
|
12
|
-
spec.summary = "
|
|
13
|
-
spec.description = "
|
|
12
|
+
spec.summary = "Rack app exposing current git commit"
|
|
13
|
+
spec.description = "Mount at any path to return the current git commit SHA based on environment rules."
|
|
14
14
|
spec.homepage = "https://github.com/radar/shalala"
|
|
15
15
|
spec.license = "MIT"
|
|
16
16
|
spec.required_ruby_version = ">= 3.1"
|
|
17
17
|
|
|
18
18
|
spec.files = Dir[
|
|
19
|
-
"app/**/*",
|
|
20
|
-
"config/**/*",
|
|
21
19
|
"lib/**/*",
|
|
22
20
|
"*.md",
|
|
23
21
|
"*.gemspec",
|
|
24
22
|
"Rakefile"
|
|
25
23
|
]
|
|
26
24
|
|
|
27
|
-
spec.add_dependency "
|
|
25
|
+
spec.add_dependency "rack"
|
|
28
26
|
|
|
29
|
-
spec.add_development_dependency "rspec
|
|
27
|
+
spec.add_development_dependency "rspec", ">= 3.0"
|
|
28
|
+
spec.add_development_dependency "rack-test"
|
|
30
29
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: shalala
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 2.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ryan Bigg
|
|
@@ -10,34 +10,49 @@ cert_chain: []
|
|
|
10
10
|
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
12
|
- !ruby/object:Gem::Dependency
|
|
13
|
-
name:
|
|
13
|
+
name: rack
|
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|
|
15
15
|
requirements:
|
|
16
16
|
- - ">="
|
|
17
17
|
- !ruby/object:Gem::Version
|
|
18
|
-
version: '
|
|
18
|
+
version: '0'
|
|
19
19
|
type: :runtime
|
|
20
20
|
prerelease: false
|
|
21
21
|
version_requirements: !ruby/object:Gem::Requirement
|
|
22
22
|
requirements:
|
|
23
23
|
- - ">="
|
|
24
24
|
- !ruby/object:Gem::Version
|
|
25
|
-
version: '
|
|
25
|
+
version: '0'
|
|
26
26
|
- !ruby/object:Gem::Dependency
|
|
27
|
-
name: rspec
|
|
27
|
+
name: rspec
|
|
28
28
|
requirement: !ruby/object:Gem::Requirement
|
|
29
29
|
requirements:
|
|
30
30
|
- - ">="
|
|
31
31
|
- !ruby/object:Gem::Version
|
|
32
|
-
version: '
|
|
32
|
+
version: '3.0'
|
|
33
33
|
type: :development
|
|
34
34
|
prerelease: false
|
|
35
35
|
version_requirements: !ruby/object:Gem::Requirement
|
|
36
36
|
requirements:
|
|
37
37
|
- - ">="
|
|
38
38
|
- !ruby/object:Gem::Version
|
|
39
|
-
version: '
|
|
40
|
-
|
|
39
|
+
version: '3.0'
|
|
40
|
+
- !ruby/object:Gem::Dependency
|
|
41
|
+
name: rack-test
|
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
|
43
|
+
requirements:
|
|
44
|
+
- - ">="
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: '0'
|
|
47
|
+
type: :development
|
|
48
|
+
prerelease: false
|
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
50
|
+
requirements:
|
|
51
|
+
- - ">="
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: '0'
|
|
54
|
+
description: Mount at any path to return the current git commit SHA based on environment
|
|
55
|
+
rules.
|
|
41
56
|
email:
|
|
42
57
|
- ryan@example.com
|
|
43
58
|
executables: []
|
|
@@ -46,9 +61,8 @@ extra_rdoc_files: []
|
|
|
46
61
|
files:
|
|
47
62
|
- README.md
|
|
48
63
|
- Rakefile
|
|
49
|
-
- app/controllers/shalala/commits_controller.rb
|
|
50
|
-
- config/routes.rb
|
|
51
64
|
- lib/shalala.rb
|
|
65
|
+
- lib/shalala/app.rb
|
|
52
66
|
- lib/shalala/engine.rb
|
|
53
67
|
- lib/shalala/version.rb
|
|
54
68
|
- shalala.gemspec
|
|
@@ -72,5 +86,5 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
72
86
|
requirements: []
|
|
73
87
|
rubygems_version: 3.6.9
|
|
74
88
|
specification_version: 4
|
|
75
|
-
summary:
|
|
89
|
+
summary: Rack app exposing current git commit
|
|
76
90
|
test_files: []
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Shalala
|
|
4
|
-
class CommitsController < ActionController::Base
|
|
5
|
-
def show
|
|
6
|
-
commit = resolved_commit
|
|
7
|
-
branch = resolved_branch
|
|
8
|
-
|
|
9
|
-
if commit.present?
|
|
10
|
-
render plain: "commit: #{commit}\nbranch: #{branch}"
|
|
11
|
-
else
|
|
12
|
-
head :not_found
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
private
|
|
17
|
-
|
|
18
|
-
def resolved_commit
|
|
19
|
-
env_commit = ENV["GIT_COMMIT"]
|
|
20
|
-
return env_commit if env_commit.present?
|
|
21
|
-
return current_git_commit if development_environment?
|
|
22
|
-
|
|
23
|
-
nil
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
def resolved_branch
|
|
27
|
-
env_branch = ENV["GIT_BRANCH"]
|
|
28
|
-
return env_branch if env_branch.present?
|
|
29
|
-
|
|
30
|
-
current_git_branch
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
def development_environment?
|
|
34
|
-
Rails.env.development?
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
def current_git_commit
|
|
38
|
-
Dir.chdir(Rails.root) do
|
|
39
|
-
sha = `git rev-parse HEAD`.strip
|
|
40
|
-
$?.success? ? sha : nil
|
|
41
|
-
end
|
|
42
|
-
rescue StandardError
|
|
43
|
-
nil
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
def current_git_branch
|
|
47
|
-
Dir.chdir(Rails.root) do
|
|
48
|
-
branch = `git branch --show-current`.strip
|
|
49
|
-
return branch if $?.success? && branch.present?
|
|
50
|
-
|
|
51
|
-
fallback_branch = `git rev-parse --abbrev-ref HEAD`.strip
|
|
52
|
-
$?.success? ? fallback_branch : nil
|
|
53
|
-
end
|
|
54
|
-
rescue StandardError
|
|
55
|
-
nil
|
|
56
|
-
end
|
|
57
|
-
end
|
|
58
|
-
end
|