libdolt 0.31.0 → 0.32.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.
- data/Gemfile.lock +1 -1
- data/lib/libdolt/version.rb +1 -1
- data/lib/libdolt/view/submodule_url.rb +140 -0
- data/lib/libdolt/view/tree.rb +1 -1
- data/lib/libdolt/view/urls.rb +4 -0
- data/test/libdolt/view/submodule_url_test.rb +102 -0
- data/test/libdolt/view/tree_test.rb +36 -4
- metadata +4 -2
data/Gemfile.lock
CHANGED
data/lib/libdolt/version.rb
CHANGED
@@ -0,0 +1,140 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#--
|
3
|
+
# Copyright (C) 2013 Gitorious AS
|
4
|
+
#
|
5
|
+
# This program is free software: you can redistribute it and/or modify
|
6
|
+
# it under the terms of the GNU Affero General Public License as published by
|
7
|
+
# the Free Software Foundation, either version 3 of the License, or
|
8
|
+
# (at your option) any later version.
|
9
|
+
#
|
10
|
+
# This program is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
+
# GNU Affero General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU Affero General Public License
|
16
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
17
|
+
#++
|
18
|
+
|
19
|
+
module Dolt
|
20
|
+
module View
|
21
|
+
module SubmoduleUrl
|
22
|
+
def self.for(submodule)
|
23
|
+
url = submodule[:url]
|
24
|
+
commit = submodule[:oid]
|
25
|
+
|
26
|
+
parsers.map { |p| p.browse_url(url, commit) }.compact.first
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.parsers
|
30
|
+
@parsers ||= [GitoriousOrg.new, GitHub.new, BitBucket.new, GenericParser.new]
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.parsers=(value)
|
34
|
+
@parsers = value
|
35
|
+
end
|
36
|
+
|
37
|
+
module Parser
|
38
|
+
def browse_url(url, commit)
|
39
|
+
mountpoints.each do |mountpoint|
|
40
|
+
path = parse_mountpoint(mountpoint, url)
|
41
|
+
return generate_url(*path, commit) if path
|
42
|
+
end
|
43
|
+
return nil
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def parse_mountpoint(mountpoint, url)
|
49
|
+
base_url = mountpoint.base_url
|
50
|
+
return nil unless url.include?(base_url)
|
51
|
+
parts = url.gsub(base_url, '').gsub(/\.git$/, '').split("/")
|
52
|
+
return parts[-2..-1]
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
class HttpMountPoint
|
57
|
+
attr_reader :host, :protocol
|
58
|
+
|
59
|
+
def initialize(host, protocol = 'http')
|
60
|
+
@host = host
|
61
|
+
@protocol = protocol
|
62
|
+
end
|
63
|
+
|
64
|
+
def base_url
|
65
|
+
"#{protocol}://#{host}/"
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
class GitMountPoint
|
70
|
+
attr_reader :host
|
71
|
+
|
72
|
+
def initialize(host)
|
73
|
+
@host = host
|
74
|
+
end
|
75
|
+
|
76
|
+
def base_url
|
77
|
+
"git://#{host}/"
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
class GitSshMountPoint
|
82
|
+
attr_reader :user, :host
|
83
|
+
|
84
|
+
def initialize(user, host)
|
85
|
+
@user = user
|
86
|
+
@host = host
|
87
|
+
end
|
88
|
+
|
89
|
+
def base_url
|
90
|
+
"#{user}@#{host}:"
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
class BitBucket
|
95
|
+
include Parser
|
96
|
+
|
97
|
+
def mountpoints
|
98
|
+
[HttpMountPoint.new("bitbucket.org", "https"), GitSshMountPoint.new("git", "bitbucket.org")]
|
99
|
+
end
|
100
|
+
|
101
|
+
def generate_url(project, repository, commit)
|
102
|
+
"https://bitbucket.org/#{project}/#{repository}/src/#{commit}"
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
class GitHub
|
107
|
+
include Parser
|
108
|
+
|
109
|
+
def mountpoints
|
110
|
+
[GitMountPoint.new("github.com"), HttpMountPoint.new("github.com", "https"), GitSshMountPoint.new("git", "github.com")]
|
111
|
+
end
|
112
|
+
|
113
|
+
def generate_url(project, repository, commit)
|
114
|
+
"https://github.com/#{project}/#{repository}/tree/#{commit}"
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
class GitoriousOrg
|
119
|
+
include Parser
|
120
|
+
|
121
|
+
def mountpoints
|
122
|
+
[GitMountPoint.new("gitorious.org"),
|
123
|
+
HttpMountPoint.new("git.gitorious.org", "http"),
|
124
|
+
HttpMountPoint.new("git.gitorious.org", "https"),
|
125
|
+
GitSshMountPoint.new("git", "gitorious.org")]
|
126
|
+
end
|
127
|
+
|
128
|
+
def generate_url(project, repository, commit)
|
129
|
+
"https://gitorious.org/#{project}/#{repository}/source/#{commit}"
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
class GenericParser
|
134
|
+
def browse_url(url, commit)
|
135
|
+
url
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
data/lib/libdolt/view/tree.rb
CHANGED
@@ -20,11 +20,11 @@ module Dolt
|
|
20
20
|
module View
|
21
21
|
module Tree
|
22
22
|
def object_path(root, object)
|
23
|
+
return object if object[:type] == :submodule
|
23
24
|
File.join(root, object[:name]).sub(/^\//, "")
|
24
25
|
end
|
25
26
|
|
26
27
|
def object_url(repository, ref, path, object)
|
27
|
-
return object[:url] if object[:type] == :submodule
|
28
28
|
send(:"#{object[:type]}_url", repository, ref, object_path(path, object))
|
29
29
|
end
|
30
30
|
|
data/lib/libdolt/view/urls.rb
CHANGED
@@ -0,0 +1,102 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#--
|
3
|
+
# Copyright (C) 2013 Gitorious AS
|
4
|
+
#
|
5
|
+
# This program is free software: you can redistribute it and/or modify
|
6
|
+
# it under the terms of the GNU Affero General Public License as published by
|
7
|
+
# the Free Software Foundation, either version 3 of the License, or
|
8
|
+
# (at your option) any later version.
|
9
|
+
#
|
10
|
+
# This program is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
+
# GNU Affero General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU Affero General Public License
|
16
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
17
|
+
#++
|
18
|
+
|
19
|
+
module Dolt
|
20
|
+
module View
|
21
|
+
class SubmoduleUrlTest < MiniTest::Spec
|
22
|
+
describe SubmoduleUrl do
|
23
|
+
it "recognizes urls from gitorious.org" do
|
24
|
+
submodule = { :url => "http://git.gitorious.org/bar/baz.git", :oid => "sha123" }
|
25
|
+
|
26
|
+
assert_equal "https://gitorious.org/bar/baz/source/sha123", SubmoduleUrl.for(submodule)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "recognizes urls from bitbucket.org" do
|
30
|
+
submodule = { :url => "https://bitbucket.org/bar/baz.git", :oid => "sha123" }
|
31
|
+
|
32
|
+
assert_equal "https://bitbucket.org/bar/baz/src/sha123", SubmoduleUrl.for(submodule)
|
33
|
+
end
|
34
|
+
|
35
|
+
it "recognizes urls from github.com" do
|
36
|
+
submodule = { :url => "git://github.com/bar/baz.git", :oid => "sha123" }
|
37
|
+
|
38
|
+
assert_equal "https://github.com/bar/baz/tree/sha123", SubmoduleUrl.for(submodule)
|
39
|
+
end
|
40
|
+
|
41
|
+
it "returns other urls unchanged" do
|
42
|
+
submodule = { :url => "git://foobar.com/bar/baz.git", :oid => "sha123" }
|
43
|
+
|
44
|
+
assert_equal "git://foobar.com/bar/baz.git", SubmoduleUrl.for(submodule)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe SubmoduleUrl::GitoriousOrg do
|
49
|
+
let(:parser) { SubmoduleUrl::GitoriousOrg.new }
|
50
|
+
let(:expected_url) { "https://gitorious.org/foo/bar/source/sha123" }
|
51
|
+
|
52
|
+
describe "ssh urls" do
|
53
|
+
it "returns nil for other users" do
|
54
|
+
assert_nil parser.browse_url("foo@gitorious.org:foo/bar.git", "sha123")
|
55
|
+
end
|
56
|
+
|
57
|
+
it "returns nil for other domains" do
|
58
|
+
assert_nil parser.browse_url("git@github.com:foo/bar.git", "sha123")
|
59
|
+
end
|
60
|
+
|
61
|
+
it "returns repository url for matching protocol and domain" do
|
62
|
+
assert_equal expected_url, parser.browse_url("git@gitorious.org:foo/bar.git", "sha123")
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe "https urls" do
|
67
|
+
it "returns nil for other domains" do
|
68
|
+
assert_nil parser.browse_url("http://git.github.com/foo/bar.git", "sha123")
|
69
|
+
end
|
70
|
+
|
71
|
+
it "returns repository url for matching protocol and domain" do
|
72
|
+
assert_equal expected_url, parser.browse_url("http://git.gitorious.org/foo/bar.git", "sha123")
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe "git urls" do
|
77
|
+
it "returns nil for other domains" do
|
78
|
+
assert_nil parser.browse_url("git://github.com/foo/bar.git", "sha123")
|
79
|
+
end
|
80
|
+
|
81
|
+
it "returns repository url for matching protocol and domain" do
|
82
|
+
assert_equal expected_url, parser.browse_url("git://gitorious.org/foo/bar.git", "sha123")
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
describe "legacy urls" do
|
87
|
+
it "returns repository url for legacy git url" do
|
88
|
+
assert_equal expected_url, parser.browse_url("git://gitorious.org/~baz/foo/bar.git", "sha123")
|
89
|
+
end
|
90
|
+
|
91
|
+
it "returns repository url for legacy http url" do
|
92
|
+
assert_equal expected_url, parser.browse_url("http://git.gitorious.org/~baz/foo/bar.git", "sha123")
|
93
|
+
end
|
94
|
+
|
95
|
+
it "returns repository url for legacy ssh url" do
|
96
|
+
assert_equal expected_url, parser.browse_url("git@gitorious.org:+baz/foo/bar.git", "sha123")
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
@@ -238,9 +238,41 @@ describe Dolt::View::Tree do
|
|
238
238
|
end
|
239
239
|
end
|
240
240
|
|
241
|
-
|
242
|
-
url
|
243
|
-
|
244
|
-
|
241
|
+
describe "submodule url" do
|
242
|
+
def generated_url(url)
|
243
|
+
object = { :type => :submodule, :url => url, :oid => "sha123" }
|
244
|
+
object_url("gitorious", "master", "vendor", object)
|
245
|
+
end
|
246
|
+
|
247
|
+
it "links submodules with unknown hosting to original url" do
|
248
|
+
url = "git://example.com/gitorious/ui3.git"
|
249
|
+
assert_equal url, generated_url(url)
|
250
|
+
end
|
251
|
+
|
252
|
+
it "links submodules hosted on github.com to the correct commit on github.com" do
|
253
|
+
correct_url = "https://github.com/gitorious/ui3/tree/sha123"
|
254
|
+
|
255
|
+
assert_equal correct_url, generated_url("git@github.com:gitorious/ui3.git")
|
256
|
+
assert_equal correct_url, generated_url("git://github.com/gitorious/ui3.git")
|
257
|
+
assert_equal correct_url, generated_url("https://github.com/gitorious/ui3.git")
|
258
|
+
end
|
259
|
+
|
260
|
+
it "links submodules hosted on gitorious.org to the correct commit on gitorious.org" do
|
261
|
+
correct_url = "https://gitorious.org/gitorious/ui3/source/sha123"
|
262
|
+
|
263
|
+
assert_equal correct_url, generated_url("git@gitorious.org:gitorious/ui3.git")
|
264
|
+
assert_equal correct_url, generated_url("git://gitorious.org/gitorious/ui3.git")
|
265
|
+
assert_equal correct_url, generated_url("http://git.gitorious.org/gitorious/ui3.git")
|
266
|
+
assert_equal correct_url, generated_url("https://git.gitorious.org/gitorious/ui3.git")
|
267
|
+
assert_equal correct_url, generated_url("http://git.gitorious.org/~foo/gitorious/ui3.git")
|
268
|
+
assert_equal correct_url, generated_url("http://git.gitorious.org/+bar/gitorious/ui3.git")
|
269
|
+
end
|
270
|
+
|
271
|
+
it "links submodules hosted on bitbucket.org to the correct commit on bitbucket.org" do
|
272
|
+
correct_url = "https://bitbucket.org/gitorious/ui3/src/sha123"
|
273
|
+
|
274
|
+
assert_equal correct_url, generated_url("git@bitbucket.org:gitorious/ui3.git")
|
275
|
+
assert_equal correct_url, generated_url("https://bitbucket.org/gitorious/ui3.git")
|
276
|
+
end
|
245
277
|
end
|
246
278
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: libdolt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.32.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-09-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rugged
|
@@ -225,6 +225,7 @@ files:
|
|
225
225
|
- lib/libdolt/view/object.rb
|
226
226
|
- lib/libdolt/view/single_repository.rb
|
227
227
|
- lib/libdolt/view/smart_blob_renderer.rb
|
228
|
+
- lib/libdolt/view/submodule_url.rb
|
228
229
|
- lib/libdolt/view/syntax_highlight.rb
|
229
230
|
- lib/libdolt/view/tab_width.rb
|
230
231
|
- lib/libdolt/view/tree.rb
|
@@ -299,6 +300,7 @@ files:
|
|
299
300
|
- test/libdolt/view/object_test.rb
|
300
301
|
- test/libdolt/view/single_repository_test.rb
|
301
302
|
- test/libdolt/view/smart_blob_renderer_test.rb
|
303
|
+
- test/libdolt/view/submodule_url_test.rb
|
302
304
|
- test/libdolt/view/syntax_highlight_test.rb
|
303
305
|
- test/libdolt/view/tab_width_test.rb
|
304
306
|
- test/libdolt/view/tree_test.rb
|