git_snatch 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.coveralls.yml +2 -0
- data/.gitignore +19 -0
- data/.simplecov +17 -0
- data/.travis.yml +9 -0
- data/Gemfile +5 -0
- data/LICENSE.txt +22 -0
- data/README.md +82 -0
- data/Rakefile +1 -0
- data/git_snatch.gemspec +29 -0
- data/lib/git_snatch.rb +24 -0
- data/lib/git_snatch/configuration.rb +25 -0
- data/lib/git_snatch/curler.rb +33 -0
- data/lib/git_snatch/grab.rb +23 -0
- data/lib/git_snatch/request.rb +27 -0
- data/lib/git_snatch/url.rb +36 -0
- data/lib/git_snatch/version.rb +3 -0
- data/spec/fixtures/GitSnatch/_grab/returns_content_for_request.yml +87 -0
- data/spec/git_snatch_spec.rb +38 -0
- data/spec/lib/configuration_spec.rb +103 -0
- data/spec/lib/curler_spec.rb +33 -0
- data/spec/lib/grab_spec.rb +36 -0
- data/spec/lib/request_spec.rb +28 -0
- data/spec/lib/url_spec.rb +40 -0
- data/spec/spec_helper.rb +35 -0
- metadata +174 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
MzcyNjU4ZWNkODU4NDBlMjYzODc0YWQ0YTYyZTUyOTE1MDlmMzI0Ng==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
NjY0MWZiY2FkYjBiZWExNTk4YmRkNTI0Mjk4OWQyYmVjMjc1N2Y1Yw==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
OTI3OTgzOTA2Zjk2Mjg5ZWYxNDRhOTU4ZTRiOGJjMjdhNzVlNTdiNTE1YzQ2
|
10
|
+
YzMyZTgyY2I2YjM3ZDQ4ZDM0NTU4MTc2N2ViOGM5ZTNjOGUzODE1ZjcyMWZj
|
11
|
+
YmJjZWNhNDk4ZGQ3ODA2ZDVhNDVjODNiZGI3MTlmZjI1YzVlMGY=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
YmE3NTBhMDYxNDJmMzVkYzU4NTFlYmFkNjBjZmE1YTE5M2FiMzU4OTJmMzNj
|
14
|
+
MzYxOWZkMTNiY2QxNmEyMmRiOTFmNDExMjk3Yjk5MDkwOGMyZjgzZDgyNDEx
|
15
|
+
MGE4YjU0OWFhZmVhM2JkYmE2YjkzNjRkMmU4NThkNTMxZjAwZTk=
|
data/.coveralls.yml
ADDED
data/.gitignore
ADDED
data/.simplecov
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'coveralls'
|
2
|
+
|
3
|
+
SimpleCov.configure do
|
4
|
+
minimum_coverage 95
|
5
|
+
maximum_coverage_drop 5
|
6
|
+
|
7
|
+
start('rails') do
|
8
|
+
formatter SimpleCov::Formatter::MultiFormatter[
|
9
|
+
SimpleCov::Formatter::HTMLFormatter,
|
10
|
+
Coveralls::SimpleCov::Formatter
|
11
|
+
]
|
12
|
+
|
13
|
+
add_group "Long files" do |src_file|
|
14
|
+
src_file.lines.count > 100
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Chuck J hardy
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
[![Code Climate](https://codeclimate.com/github/ChuckJHardy/GitSnatch.png)](https://codeclimate.com/github/ChuckJHardy/GitSnatch)
|
2
|
+
|
3
|
+
# GitSnatch
|
4
|
+
|
5
|
+
Grab content from a file with a github commit sha. Simple and lightweight.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'git_snatch', '~> 0.0.1', group :development
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install git_snatch
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
GitSnatch.configure do |config|
|
24
|
+
config.endpoint = 'https://github.company.com/organisation'
|
25
|
+
config.username = 'git-snatch-user'
|
26
|
+
config.password = 81ysnaks7HFHS619sn
|
27
|
+
end
|
28
|
+
|
29
|
+
repo = 'ContinuusLenimentus'
|
30
|
+
sha = '21c5f27a6997c4888056ae7d95dd193893378492'
|
31
|
+
|
32
|
+
GitSnatch.within(repo, sha).grab('app/controllers/user_controller.rb')
|
33
|
+
# => class UserController < ApplicationController...
|
34
|
+
|
35
|
+
## Configuration
|
36
|
+
|
37
|
+
Github Public
|
38
|
+
|
39
|
+
GitSnatch.configure do |config|
|
40
|
+
config.username = 'ChuckJHardy'
|
41
|
+
end
|
42
|
+
|
43
|
+
Github Private
|
44
|
+
|
45
|
+
GitSnatch.configure do |config|
|
46
|
+
config.username = 'ChuckJHardy'
|
47
|
+
config.password = 81ysnaks7HFHS619sn
|
48
|
+
end
|
49
|
+
|
50
|
+
Github Enterprise
|
51
|
+
|
52
|
+
GitSnatch.configure do |config|
|
53
|
+
config.endpoint = 'https://github.company.com/organisation'
|
54
|
+
config.username = 'git-snatch-user'
|
55
|
+
config.password = 81ysnaks7HFHS619sn
|
56
|
+
end
|
57
|
+
|
58
|
+
Required for all.
|
59
|
+
|
60
|
+
* `username` sets the username for the account.
|
61
|
+
|
62
|
+
Required for private or enterpise repo's.
|
63
|
+
|
64
|
+
* `password` sets the password for authentication.
|
65
|
+
|
66
|
+
Required for enterpise accounts.
|
67
|
+
|
68
|
+
* `endpoint` sets the base uri for github. Perfect for enterprise users. `https://raw.github.com`
|
69
|
+
|
70
|
+
|
71
|
+
## Requirements
|
72
|
+
|
73
|
+
* ruby > 1.9.x
|
74
|
+
* curl > 0.8.x
|
75
|
+
|
76
|
+
## Contributing
|
77
|
+
|
78
|
+
1. Fork it
|
79
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
80
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
81
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
82
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/git_snatch.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'git_snatch/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "git_snatch"
|
8
|
+
spec.version = GitSnatch::VERSION
|
9
|
+
spec.authors = ["Chuck J hardy"]
|
10
|
+
spec.email = ["chuckjhardy@gmail.com"]
|
11
|
+
spec.description = %q{Grab content from a file with a github commit sha}
|
12
|
+
spec.summary = %q{Grab content from a file with a github commit sha. Simple and lightweight.}
|
13
|
+
spec.homepage = "https://github.com/ChuckJHardy/GitSnatch"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "curb", "~> 0.8.5"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
24
|
+
spec.add_development_dependency "rake"
|
25
|
+
spec.add_development_dependency "simplecov", "~> 0.7.1"
|
26
|
+
spec.add_development_dependency "rspec", "~> 2.13.0"
|
27
|
+
spec.add_development_dependency 'webmock', '~> 1.15.2'
|
28
|
+
spec.add_development_dependency "vcr", "~> 2.7.0"
|
29
|
+
end
|
data/lib/git_snatch.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require "git_snatch/configuration"
|
2
|
+
require "git_snatch/url"
|
3
|
+
require "git_snatch/curler"
|
4
|
+
require "git_snatch/request"
|
5
|
+
require "git_snatch/grab"
|
6
|
+
require "git_snatch/version"
|
7
|
+
|
8
|
+
class GitSnatch
|
9
|
+
extend Configure
|
10
|
+
|
11
|
+
def initialize(repo, sha)
|
12
|
+
@repo = repo
|
13
|
+
@sha = sha
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.within(repo, sha)
|
17
|
+
new(repo, sha)
|
18
|
+
end
|
19
|
+
|
20
|
+
def grab(location)
|
21
|
+
Grab.new(@repo, @sha, location).content
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
@@ -0,0 +1,25 @@
|
|
1
|
+
class GitSnatch
|
2
|
+
module Configure
|
3
|
+
extend self
|
4
|
+
|
5
|
+
def configuration
|
6
|
+
@configuration ||= Configuration.new
|
7
|
+
end
|
8
|
+
|
9
|
+
def configure
|
10
|
+
yield(configuration)
|
11
|
+
configuration
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class Configuration
|
16
|
+
attr_accessor :endpoint, :auth_types, :username, :password
|
17
|
+
|
18
|
+
def initialize
|
19
|
+
self.endpoint = 'https://raw.github.com'
|
20
|
+
self.auth_types = :basic
|
21
|
+
self.username = nil
|
22
|
+
self.password = nil
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
class GitSnatch
|
2
|
+
class Curler
|
3
|
+
def initialize(curl)
|
4
|
+
@curl = curl
|
5
|
+
end
|
6
|
+
|
7
|
+
def build
|
8
|
+
@curl.tap do |c|
|
9
|
+
c.http_auth_types = auth_types if auth?
|
10
|
+
c.username = username if username
|
11
|
+
c.password = password if password
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def username
|
18
|
+
GitSnatch.configuration.username
|
19
|
+
end
|
20
|
+
|
21
|
+
def password
|
22
|
+
GitSnatch.configuration.password
|
23
|
+
end
|
24
|
+
|
25
|
+
def auth?
|
26
|
+
username && password
|
27
|
+
end
|
28
|
+
|
29
|
+
def auth_types
|
30
|
+
GitSnatch.configuration.auth_types
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class GitSnatch
|
2
|
+
class Grab
|
3
|
+
def initialize(repo, sha, location)
|
4
|
+
@repo = repo
|
5
|
+
@sha = sha
|
6
|
+
@location = location
|
7
|
+
end
|
8
|
+
|
9
|
+
def content
|
10
|
+
request.body
|
11
|
+
end
|
12
|
+
|
13
|
+
def request
|
14
|
+
Request.new(url)
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def url
|
20
|
+
Url.new(@repo, @sha, @location).full
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'curb'
|
2
|
+
|
3
|
+
class GitSnatch
|
4
|
+
class Request
|
5
|
+
def initialize(url)
|
6
|
+
@url = url
|
7
|
+
end
|
8
|
+
|
9
|
+
def body
|
10
|
+
get.body_str
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def get
|
16
|
+
curl.tap { |c| c.perform }
|
17
|
+
end
|
18
|
+
|
19
|
+
def curl
|
20
|
+
@curl ||= Curler.new(easy).build
|
21
|
+
end
|
22
|
+
|
23
|
+
def easy
|
24
|
+
Curl::Easy.new(@url)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
class GitSnatch
|
2
|
+
class Url
|
3
|
+
def initialize(repo, sha, location)
|
4
|
+
@repo = repo
|
5
|
+
@sha = sha
|
6
|
+
@location = location
|
7
|
+
end
|
8
|
+
|
9
|
+
def full
|
10
|
+
elements.join('/')
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
attr_reader :repo, :sha, :location
|
15
|
+
|
16
|
+
def elements
|
17
|
+
[ base, username, repo, mode, sha, location ].compact
|
18
|
+
end
|
19
|
+
|
20
|
+
def mode
|
21
|
+
'raw' unless github?
|
22
|
+
end
|
23
|
+
|
24
|
+
def github?
|
25
|
+
base.include?('raw')
|
26
|
+
end
|
27
|
+
|
28
|
+
def username
|
29
|
+
GitSnatch.configuration.username if github?
|
30
|
+
end
|
31
|
+
|
32
|
+
def base
|
33
|
+
GitSnatch.configuration.endpoint
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://john.smith:123456@github.company.com/organisation/www/raw/38209a615b72728ef4f3160619c7c63c37b8994c/continuus_lenimentus.enc
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers: {}
|
10
|
+
response:
|
11
|
+
status:
|
12
|
+
code: 200
|
13
|
+
message: !binary |-
|
14
|
+
T0s=
|
15
|
+
headers:
|
16
|
+
!binary "U2VydmVy":
|
17
|
+
- !binary |-
|
18
|
+
R2l0SHViLmNvbQ==
|
19
|
+
!binary "RGF0ZQ==":
|
20
|
+
- !binary |-
|
21
|
+
U2F0LCAwOSBOb3YgMjAxMyAxODozMzoxNCBHTVQ=
|
22
|
+
!binary "Q29udGVudC1UeXBl":
|
23
|
+
- !binary |-
|
24
|
+
dGV4dC9wbGFpbjsgY2hhcnNldD11dGYtOA==
|
25
|
+
!binary "Q29ubmVjdGlvbg==":
|
26
|
+
- !binary |-
|
27
|
+
a2VlcC1hbGl2ZQ==
|
28
|
+
!binary "U3RhdHVz":
|
29
|
+
- !binary |-
|
30
|
+
MjAwIE9L
|
31
|
+
!binary "Q2FjaGUtQ29udHJvbA==":
|
32
|
+
- !binary |-
|
33
|
+
cHJpdmF0ZQ==
|
34
|
+
!binary "U2V0LUNvb2tpZQ==":
|
35
|
+
- !binary |-
|
36
|
+
X2ZpX3Nlc3M9QkFoN0NEb1BjMlZ6YzJsdmJsOXBaQ0lsWXpabFpHWXdaV1l3
|
37
|
+
WkdFeU0yRXdZMlk0T1RNeU16ZG1ZMkpsTnpSbE5HUTZDWFZ6WlhKcFVqb1Fa
|
38
|
+
bWx1WjJWeWNISnBiblJKSWlVd056UmpOams1WldNelpUVmtNRE5pTTJaaE5t
|
39
|
+
UTNOR0ZtWWpJek5UQTNaUVk2QmtWVS0tNGQyYWEyYjM2ODc4YjNjZmQ2MzEw
|
40
|
+
YTc3MjE2YWJlNzMwZDYwYTZlODsgcGF0aD0vOyBleHBpcmVzPVN1biwgMDEt
|
41
|
+
SmFuLTIwMjMgMDA6MDA6MDAgR01UOyBzZWN1cmU7IEh0dHBPbmx5
|
42
|
+
- !binary |-
|
43
|
+
c3B5X3VzZXI9Y2hhcmxlcy1oYXJkeTsgcGF0aD0vOyBleHBpcmVzPVdlZCwg
|
44
|
+
MDktTm92LTIwMzMgMTg6MzM6MTQgR01UOyBIdHRwT25seQ==
|
45
|
+
- !binary |-
|
46
|
+
dXNlcl9zZXNzaW9uPWJKTGN0ZlY3Y04yNjRLY1VuVWd4M2NEWWVHSzl5T0hT
|
47
|
+
VXFSdmhBQU1KeHktbHV0UzsgcGF0aD0vOyBleHBpcmVzPVNhdCwgMjMtTm92
|
48
|
+
LTIwMTMgMTg6MzM6MTQgR01UOyBzZWN1cmU7IEh0dHBPbmx5
|
49
|
+
!binary "WC1GcmFtZS1PcHRpb25z":
|
50
|
+
- !binary |-
|
51
|
+
ZGVueQ==
|
52
|
+
!binary "QWNjZXNzLUNvbnRyb2wtQWxsb3ctT3JpZ2lu":
|
53
|
+
- !binary |-
|
54
|
+
aHR0cHM6Ly9yZW5kZXIuZ2l0aHViLm90YmVhY2guY29t
|
55
|
+
!binary "WC1Db250ZW50LVR5cGUtT3B0aW9ucw==":
|
56
|
+
- !binary |-
|
57
|
+
bm9zbmlmZg==
|
58
|
+
!binary "Q29udGVudC1MZW5ndGg=":
|
59
|
+
- !binary |-
|
60
|
+
MjM0
|
61
|
+
!binary "Q29udGVudC1EaXNwb3NpdGlvbg==":
|
62
|
+
- !binary |-
|
63
|
+
aW5saW5l
|
64
|
+
!binary "Q29udGVudC1UcmFuc2Zlci1FbmNvZGluZw==":
|
65
|
+
- !binary |-
|
66
|
+
YmluYXJ5
|
67
|
+
!binary "WC1SdW50aW1l":
|
68
|
+
- !binary |-
|
69
|
+
ODQ=
|
70
|
+
!binary "RXRhZw==":
|
71
|
+
- !binary |-
|
72
|
+
ImU3Mjc0Y2RiZTQ1ZjMxMjUxMWY0OGVjNDBkZjM5YWE1Ig==
|
73
|
+
!binary "WC1HaXRodWItUmVxdWVzdC1JZA==":
|
74
|
+
- !binary |-
|
75
|
+
OTc1MzliYmEtNTA4ZC00MmU1LThhNDgtYjIxNWNlN2E5M2My
|
76
|
+
body:
|
77
|
+
encoding: ASCII-8BIT
|
78
|
+
string: !binary |-
|
79
|
+
ezpjcmVhdGVkX2F0PT4yMDEzLTExLTA4IDE1OjM0OjExICswMDAwLCA6ZHVy
|
80
|
+
YXRpb249PjI0LjMxMTg0MiwgOmNvdW50cz0+ezpleGFtcGxlPT4yMzA0LCA6
|
81
|
+
ZmFpbHVyZT0+MywgOnBlbmRpbmc9PjV9LCA6bWV0cmljcz0+ezp0b3RhbF9s
|
82
|
+
aW5lcz0+Nzg2NSwgOmNvdmVyYWdlPT57OnBlcmNlbnQ9Pjc5LjgzNDcxMDc0
|
83
|
+
MzgwMTY1LCA6c3RyZW5ndGg9PjYuMzE1MDY2NzUxNDMwMzg4LCA6bGluZXM9
|
84
|
+
PjYyNzl9fX0K
|
85
|
+
http_version:
|
86
|
+
recorded_at: Sat, 09 Nov 2013 18:33:14 GMT
|
87
|
+
recorded_with: VCR 2.7.0
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe GitSnatch, :vcr do
|
4
|
+
let(:instance) { described_class.new(repo, sha) }
|
5
|
+
let(:repo) { 'www' }
|
6
|
+
let(:sha) { '38209a615b72728ef4f3160619c7c63c37b8994c' }
|
7
|
+
|
8
|
+
let(:endpoint) { 'https://github.company.com/organisation' }
|
9
|
+
let(:username) { 'john.smith' }
|
10
|
+
let(:password) { '123456' }
|
11
|
+
|
12
|
+
before do
|
13
|
+
GitSnatch.configuration.endpoint = endpoint
|
14
|
+
GitSnatch.configuration.username = username
|
15
|
+
GitSnatch.configuration.password = password
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '.within' do
|
19
|
+
subject { described_class.within(repo, sha) }
|
20
|
+
|
21
|
+
it 'returns an instance of GitSnatch' do
|
22
|
+
expect(subject).to be_an_instance_of(GitSnatch)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe '#grab' do
|
27
|
+
subject { instance.grab(location) }
|
28
|
+
|
29
|
+
let(:location) { 'continuus_lenimentus.enc' }
|
30
|
+
let(:response) do
|
31
|
+
%Q{{:created_at=>2013-11-08 15:34:11 +0000, :duration=>24.311842, :counts=>{:example=>2304, :failure=>3, :pending=>5}, :metrics=>{:total_lines=>7865, :coverage=>{:percent=>79.83471074380165, :strength=>6.315066751430388, :lines=>6279}}}\n}
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'returns content for request' do
|
35
|
+
expect(subject).to eq(response)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe GitSnatch::Configuration do
|
4
|
+
let(:instance) { described_class.new }
|
5
|
+
|
6
|
+
describe '.configuration' do
|
7
|
+
subject { Class.new { extend GitSnatch::Configure }.configuration }
|
8
|
+
|
9
|
+
it 'returns a configuration instance' do
|
10
|
+
expect(subject).to be_an_instance_of(GitSnatch::Configuration)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '.configure' do
|
15
|
+
subject { Class.new { extend GitSnatch::Configure } }
|
16
|
+
|
17
|
+
let(:new_endpoint) { 'http://github.company.com/organisation' }
|
18
|
+
|
19
|
+
it 'yields the current configuration' do
|
20
|
+
expect { |b| subject.configure(&b) }.to yield_control
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'returns the altered configuration' do
|
24
|
+
expect(
|
25
|
+
subject.configure { |c| c.endpoint = new_endpoint }
|
26
|
+
).to be_an_instance_of(GitSnatch::Configuration)
|
27
|
+
|
28
|
+
expect(subject.configuration.endpoint).to eql(new_endpoint)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "#endpoint" do
|
33
|
+
subject { instance.endpoint }
|
34
|
+
|
35
|
+
let(:default) { 'https://raw.github.com' }
|
36
|
+
let(:new) { 'http://github.company.com/organisation' }
|
37
|
+
|
38
|
+
it "returns a string" do
|
39
|
+
expect(subject).to be_an_instance_of(String)
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'returns default' do
|
43
|
+
expect(subject).to eq(default)
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'returns altered' do
|
47
|
+
instance.endpoint = new
|
48
|
+
expect(subject).to eq(new)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe "#auth_types" do
|
53
|
+
subject { instance.auth_types }
|
54
|
+
|
55
|
+
let(:default) { :basic }
|
56
|
+
let(:new) { :http }
|
57
|
+
|
58
|
+
it "returns a symbol" do
|
59
|
+
expect(subject).to be_an_instance_of(Symbol)
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'returns default' do
|
63
|
+
expect(subject).to eq(default)
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'returns altered' do
|
67
|
+
instance.auth_types = new
|
68
|
+
expect(subject).to eq(new)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe "#username" do
|
73
|
+
subject { instance.username }
|
74
|
+
|
75
|
+
let(:default) { nil }
|
76
|
+
let(:new) { 'john-smith' }
|
77
|
+
|
78
|
+
it 'returns default' do
|
79
|
+
expect(subject).to eq(default)
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'returns altered' do
|
83
|
+
instance.username = new
|
84
|
+
expect(subject).to eq(new)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
describe "#password" do
|
89
|
+
subject { instance.password }
|
90
|
+
|
91
|
+
let(:default) { nil }
|
92
|
+
let(:new) { '123456' }
|
93
|
+
|
94
|
+
it 'returns default' do
|
95
|
+
expect(subject).to eq(default)
|
96
|
+
end
|
97
|
+
|
98
|
+
it 'returns altered' do
|
99
|
+
instance.password = new
|
100
|
+
expect(subject).to eq(new)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe GitSnatch::Curler do
|
4
|
+
let(:instance) { described_class.new(curl) }
|
5
|
+
let(:curl) { double('Curl::Easy') }
|
6
|
+
|
7
|
+
describe '#build' do
|
8
|
+
subject { instance.build }
|
9
|
+
|
10
|
+
let(:auth) { :basic }
|
11
|
+
let(:username) { 'john-smith' }
|
12
|
+
let(:password) { '123456' }
|
13
|
+
|
14
|
+
it 'returns curl object' do
|
15
|
+
expect(subject).to eq(curl)
|
16
|
+
end
|
17
|
+
|
18
|
+
context 'configures curl' do
|
19
|
+
before do
|
20
|
+
GitSnatch.configuration.username = username
|
21
|
+
GitSnatch.configuration.password = password
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'with auth, username and password' do
|
25
|
+
curl.should_receive(:http_auth_types=).with(auth)
|
26
|
+
curl.should_receive(:username=).with(username)
|
27
|
+
curl.should_receive(:password=).with(password)
|
28
|
+
|
29
|
+
subject
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe GitSnatch::Grab do
|
4
|
+
let(:instance) { described_class.new(repo, sha, location) }
|
5
|
+
let(:repo) { 'random_project' }
|
6
|
+
let(:sha) { '214e301aef' }
|
7
|
+
let(:location) { 'readme.md' }
|
8
|
+
|
9
|
+
describe '#content' do
|
10
|
+
subject { instance.content }
|
11
|
+
|
12
|
+
let(:body) { 'Test Response' }
|
13
|
+
let(:request) do
|
14
|
+
double(
|
15
|
+
'GitSnatch::Request',
|
16
|
+
body: body
|
17
|
+
)
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'returns the body of the request' do
|
21
|
+
GitSnatch::Request.should_receive(:new).
|
22
|
+
with(an_instance_of(String)).
|
23
|
+
and_return(request)
|
24
|
+
|
25
|
+
expect(subject).to eq(body)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe '#request' do
|
30
|
+
subject { instance.request }
|
31
|
+
|
32
|
+
it 'returns an instance of Request' do
|
33
|
+
expect(subject).to be_an_instance_of(GitSnatch::Request)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe GitSnatch::Request do
|
4
|
+
let(:instance) { described_class.new(url) }
|
5
|
+
|
6
|
+
let(:url) { GitSnatch::Url.new(repo, sha, file).full }
|
7
|
+
let(:repo) { 'random_project' }
|
8
|
+
let(:sha) { '214e301aef' }
|
9
|
+
let(:file) { 'readme.md' }
|
10
|
+
|
11
|
+
describe '#body' do
|
12
|
+
subject { instance.body }
|
13
|
+
|
14
|
+
let(:body) { 'Test Response' }
|
15
|
+
let(:curl) do
|
16
|
+
double(
|
17
|
+
'Curl::Easy',
|
18
|
+
perform: stub,
|
19
|
+
body_str: body
|
20
|
+
)
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'returns reponse body from request' do
|
24
|
+
Curl::Easy.should_receive(:new).with(url).and_return(curl)
|
25
|
+
expect(subject).to eq(body)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe GitSnatch::Url do
|
4
|
+
let(:instance) { described_class.new(repo, sha, location) }
|
5
|
+
let(:repo) { 'random_project' }
|
6
|
+
let(:sha) { '214e301aef' }
|
7
|
+
let(:location) { 'readme.md' }
|
8
|
+
|
9
|
+
describe '#full' do
|
10
|
+
subject { instance.full }
|
11
|
+
|
12
|
+
context 'github' do
|
13
|
+
let(:expected_url) do
|
14
|
+
%Q{http://raw.github.com/ChuckJHardy/random_project/214e301aef/readme.md}
|
15
|
+
end
|
16
|
+
|
17
|
+
before do
|
18
|
+
GitSnatch.configuration.username = 'ChuckJHardy'
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'returns full url' do
|
22
|
+
expect(subject).to eq(expected_url)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'github enterprise' do
|
27
|
+
let(:expected_url) do
|
28
|
+
%Q{https://github.company.com/organisation/random_project/raw/214e301aef/readme.md}
|
29
|
+
end
|
30
|
+
|
31
|
+
before do
|
32
|
+
GitSnatch.configuration.endpoint = 'https://github.company.com/organisation'
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'returns full url' do
|
36
|
+
expect(subject).to eq(expected_url)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
require 'coveralls'
|
3
|
+
|
4
|
+
Coveralls.wear!
|
5
|
+
|
6
|
+
ENV["RAILS_ENV"] ||= 'test'
|
7
|
+
|
8
|
+
require 'webmock/rspec'
|
9
|
+
require 'rspec/autorun'
|
10
|
+
require 'vcr'
|
11
|
+
require 'git_snatch'
|
12
|
+
|
13
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
14
|
+
|
15
|
+
WebMock.disable_net_connect!
|
16
|
+
RSpec.configure do |config|
|
17
|
+
config.order = "random"
|
18
|
+
config.filter_run :focus => true
|
19
|
+
config.color_enabled = true
|
20
|
+
config.run_all_when_everything_filtered = true
|
21
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
22
|
+
|
23
|
+
config.before do
|
24
|
+
GitSnatch.configuration.endpoint = 'http://raw.github.com'
|
25
|
+
GitSnatch.configuration.auth_types = :basic
|
26
|
+
GitSnatch.configuration.username = nil
|
27
|
+
GitSnatch.configuration.password = nil
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
VCR.configure do |config|
|
32
|
+
config.cassette_library_dir = 'spec/fixtures'
|
33
|
+
config.hook_into :webmock
|
34
|
+
config.configure_rspec_metadata!
|
35
|
+
end
|
metadata
ADDED
@@ -0,0 +1,174 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: git_snatch
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Chuck J hardy
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-11-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: curb
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.8.5
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.8.5
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.3'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: simplecov
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.7.1
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.7.1
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 2.13.0
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 2.13.0
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: webmock
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ~>
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 1.15.2
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ~>
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 1.15.2
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: vcr
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ~>
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 2.7.0
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ~>
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 2.7.0
|
111
|
+
description: Grab content from a file with a github commit sha
|
112
|
+
email:
|
113
|
+
- chuckjhardy@gmail.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- .coveralls.yml
|
119
|
+
- .gitignore
|
120
|
+
- .simplecov
|
121
|
+
- .travis.yml
|
122
|
+
- Gemfile
|
123
|
+
- LICENSE.txt
|
124
|
+
- README.md
|
125
|
+
- Rakefile
|
126
|
+
- git_snatch.gemspec
|
127
|
+
- lib/git_snatch.rb
|
128
|
+
- lib/git_snatch/configuration.rb
|
129
|
+
- lib/git_snatch/curler.rb
|
130
|
+
- lib/git_snatch/grab.rb
|
131
|
+
- lib/git_snatch/request.rb
|
132
|
+
- lib/git_snatch/url.rb
|
133
|
+
- lib/git_snatch/version.rb
|
134
|
+
- spec/fixtures/GitSnatch/_grab/returns_content_for_request.yml
|
135
|
+
- spec/git_snatch_spec.rb
|
136
|
+
- spec/lib/configuration_spec.rb
|
137
|
+
- spec/lib/curler_spec.rb
|
138
|
+
- spec/lib/grab_spec.rb
|
139
|
+
- spec/lib/request_spec.rb
|
140
|
+
- spec/lib/url_spec.rb
|
141
|
+
- spec/spec_helper.rb
|
142
|
+
homepage: https://github.com/ChuckJHardy/GitSnatch
|
143
|
+
licenses:
|
144
|
+
- MIT
|
145
|
+
metadata: {}
|
146
|
+
post_install_message:
|
147
|
+
rdoc_options: []
|
148
|
+
require_paths:
|
149
|
+
- lib
|
150
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
151
|
+
requirements:
|
152
|
+
- - ! '>='
|
153
|
+
- !ruby/object:Gem::Version
|
154
|
+
version: '0'
|
155
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ! '>='
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
requirements: []
|
161
|
+
rubyforge_project:
|
162
|
+
rubygems_version: 2.1.9
|
163
|
+
signing_key:
|
164
|
+
specification_version: 4
|
165
|
+
summary: Grab content from a file with a github commit sha. Simple and lightweight.
|
166
|
+
test_files:
|
167
|
+
- spec/fixtures/GitSnatch/_grab/returns_content_for_request.yml
|
168
|
+
- spec/git_snatch_spec.rb
|
169
|
+
- spec/lib/configuration_spec.rb
|
170
|
+
- spec/lib/curler_spec.rb
|
171
|
+
- spec/lib/grab_spec.rb
|
172
|
+
- spec/lib/request_spec.rb
|
173
|
+
- spec/lib/url_spec.rb
|
174
|
+
- spec/spec_helper.rb
|