asgit 0.0.7 → 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 +4 -4
- data/lib/asgit/project.rb +31 -0
- data/lib/asgit/services/bitbucket.rb +29 -0
- data/lib/asgit/services/github.rb +33 -0
- data/lib/asgit/services/service.rb +40 -0
- data/lib/asgit/services.rb +18 -20
- data/lib/asgit/url.rb +39 -29
- data/lib/asgit/version.rb +1 -1
- data/lib/asgit.rb +1 -1
- data/spec/lib/asgit/project_spec.rb +64 -0
- data/spec/lib/asgit/services_spec.rb +51 -0
- data/spec/lib/asgit/url_spec.rb +104 -0
- metadata +14 -11
- data/lib/asgit/config.rb +0 -39
- data/spec/asgit/config_spec.rb +0 -76
- data/spec/asgit/services_spec.rb +0 -27
- data/spec/asgit/url_spec.rb +0 -57
- /data/spec/{asgit_spec.rb → lib/asgit_spec.rb} +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c28ffc8cb032e8af5e3ea65f5056accba05ce982
|
4
|
+
data.tar.gz: 561a141bde4cf33c7202b11b742b982e1d2408b0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ab9a787571aba61904b6107a683ccdba5e0d835fa17163904e8ef3b05ab08b5f8f0f0d2136a8b5263932fb4e35bc8b1c96f4b1ad82363dc8b4bf42137cb7326c
|
7
|
+
data.tar.gz: 0fad5d6dc5debb3d57a15a0d0a5a98c8e70bd12db3fcf79bf697a3db8c4733629efc1a3f042577ea8e0a0dc30008fb2466520b05c070eeae14c12daff0369441
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Asgit
|
2
|
+
class Project
|
3
|
+
|
4
|
+
def initialize project_details={}
|
5
|
+
project_details.each do |k,v|
|
6
|
+
begin
|
7
|
+
details.public_send( :"#{k}=", v )
|
8
|
+
rescue NoMethodError => e
|
9
|
+
raise ArgumentError, "unknown keyword: #{e.name.to_s.chomp('=')}"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def details
|
15
|
+
@_details ||= Details.new
|
16
|
+
end
|
17
|
+
|
18
|
+
def service
|
19
|
+
@_service ||= Services.fetch( details.service ).new
|
20
|
+
end
|
21
|
+
|
22
|
+
def urls
|
23
|
+
@_urls ||= Url.new details, service
|
24
|
+
end
|
25
|
+
|
26
|
+
class Details
|
27
|
+
attr_accessor :service, :organization, :project, :default_branch
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Asgit
|
2
|
+
module Services
|
3
|
+
class Bitbucket < Service
|
4
|
+
|
5
|
+
register_as :bitbucket
|
6
|
+
|
7
|
+
def base_url
|
8
|
+
"https://bitbucket.org"
|
9
|
+
end
|
10
|
+
|
11
|
+
def base_structure
|
12
|
+
"%{base_url}/%{organization}/%{project}"
|
13
|
+
end
|
14
|
+
|
15
|
+
def commit_uri
|
16
|
+
"commits/%{commit}"
|
17
|
+
end
|
18
|
+
|
19
|
+
def branch_uri
|
20
|
+
"branch/%{branch}"
|
21
|
+
end
|
22
|
+
|
23
|
+
def file_at_commit_uri
|
24
|
+
"src/%{commit}/%{file_path}?at=%{branch}"
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Asgit
|
2
|
+
module Services
|
3
|
+
class GitHub < Service
|
4
|
+
|
5
|
+
register_as :github
|
6
|
+
|
7
|
+
def base_url
|
8
|
+
"https://github.com"
|
9
|
+
end
|
10
|
+
|
11
|
+
def base_structure
|
12
|
+
"%{base_url}/%{organization}/%{project}"
|
13
|
+
end
|
14
|
+
|
15
|
+
def commit_uri
|
16
|
+
"commit/%{commit}"
|
17
|
+
end
|
18
|
+
|
19
|
+
def branch_uri
|
20
|
+
"tree/%{branch}"
|
21
|
+
end
|
22
|
+
|
23
|
+
def file_uri
|
24
|
+
"blob/%{branch}/%{file_path}%{line}"
|
25
|
+
end
|
26
|
+
|
27
|
+
def file_at_commit_uri
|
28
|
+
"blob/%{commit}/%{file_path}%{line}"
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Asgit
|
2
|
+
module Services
|
3
|
+
class Service
|
4
|
+
|
5
|
+
class << self
|
6
|
+
def register_as name
|
7
|
+
Services.register( self, name )
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def base_url
|
12
|
+
raise MissingUrlStructure, "#{self.class} does not implement #{__method__}"
|
13
|
+
end
|
14
|
+
|
15
|
+
def base_structure
|
16
|
+
raise MissingUrlStructure, "#{self.class} does not implement #{__method__}"
|
17
|
+
end
|
18
|
+
|
19
|
+
def commit_uri
|
20
|
+
raise MissingUrlStructure, "#{self.class} does not implement #{__method__}"
|
21
|
+
end
|
22
|
+
|
23
|
+
def branch_uri
|
24
|
+
raise MissingUrlStructure, "#{self.class} does not implement #{__method__}"
|
25
|
+
end
|
26
|
+
|
27
|
+
def file_uri
|
28
|
+
raise MissingUrlStructure, "#{self.class} does not implement #{__method__}"
|
29
|
+
end
|
30
|
+
|
31
|
+
def file_at_commit_uri
|
32
|
+
raise MissingUrlStructure, "#{self.class} does not implement #{__method__}"
|
33
|
+
end
|
34
|
+
|
35
|
+
class MissingUrlStructure < StandardError
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/lib/asgit/services.rb
CHANGED
@@ -1,32 +1,30 @@
|
|
1
1
|
module Asgit
|
2
2
|
module Services
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
commit_uri: "commit/%{commit}",
|
9
|
-
branch_uri: "tree/%{branch}",
|
10
|
-
file_uri: "blob/%{branch}/%{file_path}%{line}"
|
11
|
-
}
|
12
|
-
}
|
13
|
-
|
14
|
-
DATA.each_key do |service|
|
15
|
-
define_singleton_method(service) do
|
16
|
-
instance_variable_get("@_#{service}") || instance_variable_set("@_#{service}", Service.new( DATA[service] ))
|
4
|
+
class << self
|
5
|
+
|
6
|
+
def registered
|
7
|
+
@_registered ||= {}
|
17
8
|
end
|
18
|
-
end
|
19
9
|
|
20
|
-
|
10
|
+
def register service, key
|
11
|
+
registered[key] = service
|
12
|
+
end
|
21
13
|
|
22
|
-
def
|
23
|
-
|
24
|
-
|
14
|
+
def fetch service
|
15
|
+
registered.fetch(service) do
|
16
|
+
raise UndefinedService, "undefined service #{service}"
|
25
17
|
end
|
26
|
-
return self.freeze
|
27
18
|
end
|
28
19
|
|
29
20
|
end
|
30
21
|
|
22
|
+
class UndefinedService < StandardError
|
23
|
+
end
|
24
|
+
|
31
25
|
end
|
32
|
-
end
|
26
|
+
end
|
27
|
+
|
28
|
+
require_relative 'services/service'
|
29
|
+
require_relative 'services/github'
|
30
|
+
require_relative 'services/bitbucket'
|
data/lib/asgit/url.rb
CHANGED
@@ -1,43 +1,53 @@
|
|
1
1
|
module Asgit
|
2
|
-
|
2
|
+
class Url
|
3
3
|
|
4
|
-
|
4
|
+
attr_reader :details, :service
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
project: Asgit.config.project
|
11
|
-
}
|
12
|
-
end
|
6
|
+
def initialize details, service
|
7
|
+
@details = details
|
8
|
+
@service = service
|
9
|
+
end
|
13
10
|
|
14
|
-
|
15
|
-
|
16
|
-
|
11
|
+
def project
|
12
|
+
service.base_structure % {
|
13
|
+
base_url: service.base_url,
|
14
|
+
organization: details.organization,
|
15
|
+
project: details.project
|
16
|
+
}
|
17
|
+
end
|
17
18
|
|
18
|
-
|
19
|
-
|
20
|
-
|
19
|
+
def commit sha
|
20
|
+
File.join( project, service.commit_uri % { commit: sha } )
|
21
|
+
end
|
21
22
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
line = options.has_key?(:line) ? format_lines(options[:line]) : ''
|
23
|
+
def branch name
|
24
|
+
File.join( project, service.branch_uri % { branch: name } )
|
25
|
+
end
|
26
26
|
|
27
|
-
|
28
|
-
|
27
|
+
def file file_path, options={}
|
28
|
+
file_path = file_path.gsub( /^\//, '' )
|
29
|
+
branch = options.fetch(:branch) { details.default_branch }
|
30
|
+
line = options.has_key?(:line) ? format_lines(options[:line]) : ''
|
29
31
|
|
30
|
-
|
32
|
+
File.join( project, service.file_uri % { file_path: file_path, branch: branch, line: line } )
|
33
|
+
end
|
31
34
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
else
|
36
|
-
return "#L#{input}"
|
37
|
-
end
|
38
|
-
end
|
35
|
+
def file_at_commit file_path, commit=commit, options={}
|
36
|
+
file_path = file_path.gsub( /^\//, '' )
|
37
|
+
line = options.has_key?(:line) ? format_lines(options[:line]) : ''
|
39
38
|
|
39
|
+
File.join( project, service.file_at_commit_uri % { file_path: file_path, commit: commit, line: line } )
|
40
40
|
end
|
41
41
|
|
42
|
+
private
|
43
|
+
|
44
|
+
def format_lines input
|
45
|
+
if input.respond_to?(:begin) && input.respond_to?(:end)
|
46
|
+
return "#L#{input.begin}-L#{input.end}"
|
47
|
+
else
|
48
|
+
return "#L#{input}"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
42
52
|
end
|
43
53
|
end
|
data/lib/asgit/version.rb
CHANGED
data/lib/asgit.rb
CHANGED
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Asgit::Project do
|
4
|
+
|
5
|
+
let(:default_details) do
|
6
|
+
{
|
7
|
+
service: :github,
|
8
|
+
organization: 'stevenosloan',
|
9
|
+
project: 'asgit',
|
10
|
+
default_branch: 'master'
|
11
|
+
}
|
12
|
+
end
|
13
|
+
|
14
|
+
let(:default_project) { described_class.new( default_details ) }
|
15
|
+
|
16
|
+
describe "#initialize" do
|
17
|
+
it "sets detail's attributes" do
|
18
|
+
details_double = instance_double( "Asgit::Project::Details" )
|
19
|
+
allow( Asgit::Project::Details ).to receive(:new).and_return(details_double)
|
20
|
+
|
21
|
+
expect( details_double ).to receive(:service=).with(:github)
|
22
|
+
expect( details_double ).to receive(:organization=).with('stevenosloan')
|
23
|
+
expect( details_double ).to receive(:project=).with('asgit')
|
24
|
+
expect( details_double ).to receive(:default_branch=).with('master')
|
25
|
+
|
26
|
+
described_class.new( default_details )
|
27
|
+
end
|
28
|
+
|
29
|
+
it "raises an ArgumentError if an out-of-scope arg is passed" do
|
30
|
+
expect{
|
31
|
+
described_class.new( foo: 'bar' )
|
32
|
+
}.to raise_error ArgumentError, 'unknown keyword: foo'
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "#details" do
|
37
|
+
it "returns a Details instance" do
|
38
|
+
expect( default_project.details.is_a? Asgit::Project::Details ).to be_truthy
|
39
|
+
end
|
40
|
+
|
41
|
+
it "returns the same instance on each call" do
|
42
|
+
expect( default_project.details ).to eq default_project.details
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "#service" do
|
47
|
+
it "returns a Service instance with defined service" do
|
48
|
+
expect( default_project.service.is_a? Asgit::Services::GitHub ).to be_truthy
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe "#urls" do
|
53
|
+
it "returns a Url instance" do
|
54
|
+
expect( default_project.urls.is_a? Asgit::Url ).to be_truthy
|
55
|
+
end
|
56
|
+
|
57
|
+
it "creates Url instance with #details and #service" do
|
58
|
+
expect( Asgit::Url ).to receive(:new).with( default_project.details, default_project.service )
|
59
|
+
|
60
|
+
default_project.urls
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Asgit::Services do
|
4
|
+
|
5
|
+
before :all do
|
6
|
+
class Foo; end
|
7
|
+
end
|
8
|
+
|
9
|
+
before :each do
|
10
|
+
if described_class.instance_variable_defined?(:@_registered)
|
11
|
+
described_class.send(:remove_instance_variable, :@_registered)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
after :all do
|
16
|
+
Asgit::Services.register( Asgit::Services::GitHub, :github )
|
17
|
+
Asgit::Services.register( Asgit::Services::Bitbucket, :bitbucket )
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "::registered" do
|
21
|
+
it "returns a Hash" do
|
22
|
+
expect( described_class.registered ).to be_a Hash
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "::register" do
|
27
|
+
|
28
|
+
it "adds a service to the registered" do
|
29
|
+
expect{ described_class.register(Foo,:foo) }.to change{ Asgit::Services.registered.keys.count }.by(1)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "adds service with provided key" do
|
33
|
+
described_class.register(Foo,:foo)
|
34
|
+
expect( described_class.registered[:foo] ).to eq Foo
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "#fetch" do
|
39
|
+
it "returns a Service if that service is registered" do
|
40
|
+
described_class.register( Foo, :github )
|
41
|
+
expect( described_class.fetch(:github) ).to eq Foo
|
42
|
+
end
|
43
|
+
|
44
|
+
it "raises UndefinedService if service is not defined" do
|
45
|
+
expect{
|
46
|
+
described_class.fetch(:foo)
|
47
|
+
}.to raise_error Asgit::Services::UndefinedService
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Asgit::Url do
|
4
|
+
|
5
|
+
before :all do
|
6
|
+
class NullService < Asgit::Services::Service
|
7
|
+
register_as :null
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
let(:service) { Asgit::Services.fetch(:github).new.dup }
|
12
|
+
let(:null_service) { Asgit::Services.fetch(:null).new.dup }
|
13
|
+
let(:details) do
|
14
|
+
instance_double( "Asgit::Project::Details",
|
15
|
+
organization: 'stevenosloan',
|
16
|
+
project: 'asgit',
|
17
|
+
default_branch: 'master'
|
18
|
+
)
|
19
|
+
end
|
20
|
+
|
21
|
+
let(:subject) { described_class.new( details, service ) }
|
22
|
+
let(:null_subject) { described_class.new( details, null_service ) }
|
23
|
+
|
24
|
+
describe "#initialize" do
|
25
|
+
it "sets the details & service attributes" do
|
26
|
+
expect( subject.details ).to eq details
|
27
|
+
expect( subject.service ).to eq service
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "#project" do
|
32
|
+
it "returns expected url" do
|
33
|
+
expect( subject.project ).to eq 'https://github.com/stevenosloan/asgit'
|
34
|
+
end
|
35
|
+
it "raises MissingUrlStructure if service doesn't implement #base_structure" do
|
36
|
+
expect{
|
37
|
+
null_subject.project
|
38
|
+
}.to raise_error Asgit::Services::Service::MissingUrlStructure
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "#commit" do
|
43
|
+
it "returns url of commit" do
|
44
|
+
expect( subject.commit 'commit_sha' ).to eq 'https://github.com/stevenosloan/asgit/commit/commit_sha'
|
45
|
+
end
|
46
|
+
it "raises MissingUrlStructure if service doesn't implement #commit_uri" do
|
47
|
+
expect{
|
48
|
+
null_subject.commit 'commit_sha'
|
49
|
+
}.to raise_error Asgit::Services::Service::MissingUrlStructure
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe "#branch" do
|
54
|
+
it "returns url of the branch" do
|
55
|
+
expect( subject.branch 'branch_name' ).to eq 'https://github.com/stevenosloan/asgit/tree/branch_name'
|
56
|
+
end
|
57
|
+
it "raises MissingUrlStructure if service doesn't implement #branch_uri" do
|
58
|
+
expect{
|
59
|
+
null_subject.branch 'branch_name'
|
60
|
+
}.to raise_error Asgit::Services::Service::MissingUrlStructure
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe '#file' do
|
65
|
+
it "returns url for the file" do
|
66
|
+
expect( subject.file 'lib/asgit.rb' ).to eq 'https://github.com/stevenosloan/asgit/blob/master/lib/asgit.rb'
|
67
|
+
end
|
68
|
+
it "adjusts for paths with leading slash" do
|
69
|
+
expect( subject.file '/lib/asgit.rb' ).to eq 'https://github.com/stevenosloan/asgit/blob/master/lib/asgit.rb'
|
70
|
+
end
|
71
|
+
it "returns url for the file on a specific branch" do
|
72
|
+
expect( subject.file 'lib/asgit.rb', branch: 'branch_name' ).to eq 'https://github.com/stevenosloan/asgit/blob/branch_name/lib/asgit.rb'
|
73
|
+
end
|
74
|
+
it "returns url for the file with a line number" do
|
75
|
+
expect( subject.file 'lib/asgit.rb', line: '15' ).to eq 'https://github.com/stevenosloan/asgit/blob/master/lib/asgit.rb#L15'
|
76
|
+
end
|
77
|
+
it "returns url for the file with a range of line numbers" do
|
78
|
+
expect( subject.file 'lib/asgit.rb', line: (15..18) ).to eq 'https://github.com/stevenosloan/asgit/blob/master/lib/asgit.rb#L15-L18'
|
79
|
+
end
|
80
|
+
it "raises MissingUrlStructure if service doesn't implement #file_uri" do
|
81
|
+
expect{
|
82
|
+
null_subject.file 'lib/asgit.rb'
|
83
|
+
}.to raise_error Asgit::Services::Service::MissingUrlStructure
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe "#file_at_commit" do
|
88
|
+
it "returns url for file at commit_sha" do
|
89
|
+
expect( subject.file_at_commit 'lib/asgit.rb', 'commit_sha' ).to eq 'https://github.com/stevenosloan/asgit/blob/commit_sha/lib/asgit.rb'
|
90
|
+
end
|
91
|
+
it "returns url for file at commit_sha with line numbers" do
|
92
|
+
expect( subject.file_at_commit 'lib/asgit.rb', 'commit_sha', line: '15' ).to eq 'https://github.com/stevenosloan/asgit/blob/commit_sha/lib/asgit.rb#L15'
|
93
|
+
end
|
94
|
+
it "returns url for file at commit_sha with range of line numbers" do
|
95
|
+
expect( subject.file_at_commit 'lib/asgit.rb', 'commit_sha', line: (15..18) ).to eq 'https://github.com/stevenosloan/asgit/blob/commit_sha/lib/asgit.rb#L15-L18'
|
96
|
+
end
|
97
|
+
it "raises MissingUrlStructure if service doesn't implement #file_at_commit_uri" do
|
98
|
+
expect{
|
99
|
+
null_subject.file_at_commit 'lib/asgit.rb', 'commit_sha'
|
100
|
+
}.to raise_error Asgit::Services::Service::MissingUrlStructure
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: asgit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steven Sloan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-12-
|
11
|
+
date: 2013-12-31 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: ' A simple query interface for git. '
|
14
14
|
email:
|
@@ -17,16 +17,19 @@ executables: []
|
|
17
17
|
extensions: []
|
18
18
|
extra_rdoc_files: []
|
19
19
|
files:
|
20
|
-
- lib/asgit/
|
20
|
+
- lib/asgit/project.rb
|
21
|
+
- lib/asgit/services/bitbucket.rb
|
22
|
+
- lib/asgit/services/github.rb
|
23
|
+
- lib/asgit/services/service.rb
|
21
24
|
- lib/asgit/services.rb
|
22
25
|
- lib/asgit/shell.rb
|
23
26
|
- lib/asgit/url.rb
|
24
27
|
- lib/asgit/version.rb
|
25
28
|
- lib/asgit.rb
|
26
|
-
- spec/asgit/
|
27
|
-
- spec/asgit/services_spec.rb
|
28
|
-
- spec/asgit/url_spec.rb
|
29
|
-
- spec/asgit_spec.rb
|
29
|
+
- spec/lib/asgit/project_spec.rb
|
30
|
+
- spec/lib/asgit/services_spec.rb
|
31
|
+
- spec/lib/asgit/url_spec.rb
|
32
|
+
- spec/lib/asgit_spec.rb
|
30
33
|
- spec/spec_helper.rb
|
31
34
|
- spec/support/eat_stdout.rb
|
32
35
|
- spec/support/fake_stdout.rb
|
@@ -55,10 +58,10 @@ signing_key:
|
|
55
58
|
specification_version: 4
|
56
59
|
summary: A simple query interface for git
|
57
60
|
test_files:
|
58
|
-
- spec/asgit/
|
59
|
-
- spec/asgit/services_spec.rb
|
60
|
-
- spec/asgit/url_spec.rb
|
61
|
-
- spec/asgit_spec.rb
|
61
|
+
- spec/lib/asgit/project_spec.rb
|
62
|
+
- spec/lib/asgit/services_spec.rb
|
63
|
+
- spec/lib/asgit/url_spec.rb
|
64
|
+
- spec/lib/asgit_spec.rb
|
62
65
|
- spec/spec_helper.rb
|
63
66
|
- spec/support/eat_stdout.rb
|
64
67
|
- spec/support/fake_stdout.rb
|
data/lib/asgit/config.rb
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
module Asgit
|
2
|
-
class Config
|
3
|
-
|
4
|
-
attr_reader :service
|
5
|
-
attr_writer :default_branch
|
6
|
-
attr_accessor :organization, :project
|
7
|
-
|
8
|
-
def service= name
|
9
|
-
@service = Asgit::Services.send(name.to_sym)
|
10
|
-
end
|
11
|
-
|
12
|
-
def default_branch
|
13
|
-
@default_branch || 'master'
|
14
|
-
end
|
15
|
-
|
16
|
-
def required_attributes
|
17
|
-
[ :service, :organization, :project ]
|
18
|
-
end
|
19
|
-
|
20
|
-
end
|
21
|
-
|
22
|
-
class << self
|
23
|
-
def configure &block
|
24
|
-
yield config
|
25
|
-
end
|
26
|
-
|
27
|
-
def config
|
28
|
-
@_config ||= Config.new
|
29
|
-
end
|
30
|
-
|
31
|
-
def configured?
|
32
|
-
config.required_attributes.each do |attr|
|
33
|
-
return false unless config.send(attr)
|
34
|
-
end
|
35
|
-
|
36
|
-
true
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
data/spec/asgit/config_spec.rb
DELETED
@@ -1,76 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Asgit::Config do
|
4
|
-
|
5
|
-
describe "#default_branch" do
|
6
|
-
context "when no branch is set" do
|
7
|
-
it "returns 'master'" do
|
8
|
-
expect( Asgit::Config.new.default_branch ).to eq 'master'
|
9
|
-
end
|
10
|
-
end
|
11
|
-
context "when a branch is set" do
|
12
|
-
it "returns the set branch" do
|
13
|
-
config = Asgit::Config.new
|
14
|
-
config.default_branch = 'foo'
|
15
|
-
expect( config.default_branch ).to eq 'foo'
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
describe "::config" do
|
21
|
-
it "returns a config" do
|
22
|
-
expect( Asgit.config.class ).to eq Asgit::Config
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
describe "::configure" do
|
27
|
-
it "yields the config" do
|
28
|
-
Asgit.configure do |config|
|
29
|
-
expect( config.class ).to eq Asgit::Config
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
it "sets attributes on Config" do
|
34
|
-
Asgit.configure do |config|
|
35
|
-
config.project = "woot"
|
36
|
-
end
|
37
|
-
|
38
|
-
expect( Asgit.config.project ).to eq "woot"
|
39
|
-
end
|
40
|
-
|
41
|
-
describe "#service" do
|
42
|
-
it "sets as an Asgit::Services::Service" do
|
43
|
-
Asgit.configure do |c|
|
44
|
-
c.service = :github
|
45
|
-
end
|
46
|
-
|
47
|
-
expect( Asgit.config.service.class ).to eq Asgit::Services::Service
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
describe "::configured?" do
|
53
|
-
it "returns false if configuration hasn't been set" do
|
54
|
-
expect( Asgit.configured? ).to be_falsy
|
55
|
-
end
|
56
|
-
|
57
|
-
it "returns false if config is partially set" do
|
58
|
-
Asgit.configure do |c|
|
59
|
-
c.project = 'foo'
|
60
|
-
end
|
61
|
-
|
62
|
-
expect( Asgit.configured? ).to be_falsy
|
63
|
-
end
|
64
|
-
|
65
|
-
it "returns true if configuration has been set" do
|
66
|
-
Asgit.configure do |c|
|
67
|
-
c.project = 'foo'
|
68
|
-
c.organization = 'bar'
|
69
|
-
c.service = :github
|
70
|
-
end
|
71
|
-
|
72
|
-
expect( Asgit.configured? ).to be_truthy
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
end
|
data/spec/asgit/services_spec.rb
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Asgit::Services do
|
4
|
-
|
5
|
-
it "returns a Service for services that exist" do
|
6
|
-
expect( Asgit::Services.github.class ).to eq Asgit::Services::Service
|
7
|
-
end
|
8
|
-
|
9
|
-
it "doesn't redefine a service if it is set" do
|
10
|
-
Asgit::Services.instance_variable_set("@_github", "foo")
|
11
|
-
expect( Asgit::Services.github ).to eq "foo"
|
12
|
-
|
13
|
-
# teardown, just to keep from poluting the rest of the tests
|
14
|
-
Asgit::Services.send(:remove_instance_variable, "@_github")
|
15
|
-
end
|
16
|
-
|
17
|
-
describe Asgit::Services::Service do
|
18
|
-
|
19
|
-
let(:github) { Asgit::Services.github }
|
20
|
-
|
21
|
-
it "returns data for each key" do
|
22
|
-
expect( github.base_url ).to eq "https://github.com"
|
23
|
-
end
|
24
|
-
|
25
|
-
end
|
26
|
-
|
27
|
-
end
|
data/spec/asgit/url_spec.rb
DELETED
@@ -1,57 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Asgit::Url do
|
4
|
-
|
5
|
-
before :all do
|
6
|
-
Asgit.configure do |c|
|
7
|
-
c.organization = "wu"
|
8
|
-
c.project = "tang"
|
9
|
-
c.service = :github
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
after :all do
|
14
|
-
Asgit::Services.send(:remove_instance_variable, "@_github")
|
15
|
-
end
|
16
|
-
|
17
|
-
describe "::project" do
|
18
|
-
it "returns correct url for the project" do
|
19
|
-
expect( Asgit::Url.project ).to eq "https://github.com/wu/tang"
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
describe "::commit" do
|
24
|
-
it "returns the correct url for the provided commit" do
|
25
|
-
expect( Asgit::Url.commit "woot" ).to eq "https://github.com/wu/tang/commit/woot"
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
describe "::branch" do
|
30
|
-
it "returns the correct url for the provided branch" do
|
31
|
-
expect( Asgit::Url.branch "woot" ).to eq "https://github.com/wu/tang/tree/woot"
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
describe "::file" do
|
36
|
-
it "returns the correct url for a file" do
|
37
|
-
expect( Asgit::Url.file "lib/tang.rb" ).to eq "https://github.com/wu/tang/blob/master/lib/tang.rb"
|
38
|
-
end
|
39
|
-
|
40
|
-
it "adjust for fives given with a leading slash" do
|
41
|
-
expect( Asgit::Url.file "/lib/tang.rb" ).to eq "https://github.com/wu/tang/blob/master/lib/tang.rb"
|
42
|
-
end
|
43
|
-
|
44
|
-
it "returns the correct url for a file with a passed branch" do
|
45
|
-
expect( Asgit::Url.file "/lib/tang.rb", branch: 'dev' ).to eq "https://github.com/wu/tang/blob/dev/lib/tang.rb"
|
46
|
-
end
|
47
|
-
|
48
|
-
it "returns the correct url for a file with a line number" do
|
49
|
-
expect( Asgit::Url.file "/lib/tang.rb", branch: 'dev', line: "15" ).to eq "https://github.com/wu/tang/blob/dev/lib/tang.rb#L15"
|
50
|
-
end
|
51
|
-
|
52
|
-
it "returns the correct url for a file with a range of line numbers" do
|
53
|
-
expect( Asgit::Url.file "/lib/tang.rb", branch: 'dev', line: (15..18) ).to eq "https://github.com/wu/tang/blob/dev/lib/tang.rb#L15-L18"
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
end
|
File without changes
|