Skip to content

Commit ec65be8

Browse files
Merge pull request #46 from blackducksoftware/OTWO-4470
OTWO-4470 Return timestamp for tags
2 parents cb98372 + e1ef92e commit ec65be8

File tree

9 files changed

+42
-14
lines changed

9 files changed

+42
-14
lines changed

.travis/.install_multiple_scms.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
sudo sh -c 'echo "deb http://opensource.wandisco.com/ubuntu precise svn18" >> /etc/apt/sources.list.d/subversion18.list'
22
sudo wget -q http://opensource.wandisco.com/wandisco-debian.gpg -O- | sudo apt-key add -
3+
sudo apt-add-repository -y ppa:git-core/ppa
34
sudo apt-get update
4-
sudo apt-get install -y subversion cvs bzr mercurial
5+
sudo apt-get install -y git subversion cvs bzr mercurial
56
sudo ln -s /usr/bin/cvs /usr/bin/cvsnt

lib/ohloh_scm/adapters/bzr/misc.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,11 @@ def export(dest_dir, token=head_token)
4242
def tags
4343
tag_strings = run("cd '#{url}' && bzr tags").split(/\n/)
4444
tag_strings.map do |tag_string|
45-
tag_string.split(/\s+/)
46-
end
45+
tag_name, rev = tag_string.split(/\s+/)
46+
next if rev == '?' || tag_name == '....'
47+
time_string = run("cd '#{ url }' && bzr log -r #{ rev } | grep 'timestamp:' | sed 's/timestamp://'")
48+
[tag_name, rev, Time.parse(time_string)]
49+
end.compact
4750
end
4851
end
4952
end

lib/ohloh_scm/adapters/git/misc.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,12 @@ def no_tags?
7676

7777
def tags
7878
return [] if no_tags?
79-
tag_strings = run("cd #{url} && git show-ref --tags").split(/\n/)
79+
tag_strings = run("cd #{url} && git tag --format='%(creatordate:iso-strict) %(objectname) %(refname)'").split(/\n/)
8080
tag_strings.map do |tag_string|
81-
commit_hash, tag_path = tag_string.split(/\s/)
81+
timestamp_string, commit_hash, tag_path = tag_string.split(/\s/)
82+
timestamp = Time.parse(timestamp_string)
8283
tag_name = tag_path.gsub('refs/tags/', '')
83-
[tag_name, commit_hash]
84+
[tag_name, commit_hash, timestamp]
8485
end
8586
end
8687
end

lib/ohloh_scm/adapters/hg/misc.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ def tags
2323
tag_strings = run("cd '#{path}' && hg tags").split(/\n/)
2424
tag_strings.map do |tag_string|
2525
tag_name, rev_number_and_hash = tag_string.split(/\s+/)
26-
rev_number = rev_number_and_hash.slice(/\A\d+/)
27-
[tag_name, rev_number]
26+
rev = rev_number_and_hash.slice(/\A\d+/)
27+
time_string = run("cd '#{ path }' && hg log -r #{ rev } | grep 'date:' | sed 's/date://'")
28+
[tag_name, rev, Time.parse(time_string)]
2829
end
2930
end
3031
end

lib/ohloh_scm/adapters/svn/misc.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,9 @@ def opt_auth
146146
def tags
147147
tag_strings = `svn ls -v #{ base_path}/tags`.split(/\n/)
148148
tag_strings.map do |tag_string|
149-
tag_string.split(' ').values_at(-1, 0).map { |v| v.chomp('/') }
149+
date_string = tag_string.split(' ').values_at(-4, -3, -2).join(' ')
150+
folder_and_rev = tag_string.split(' ').values_at(-1, 0).map { |v| v.chomp('/') }
151+
folder_and_rev << Time.parse(date_string)
150152
end[1..-1]
151153
end
152154

test/unit/bzr_misc_test.rb

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,24 @@ def test_export
3636

3737
def test_tags
3838
with_bzr_repository('bzr') do |bzr|
39-
assert_equal bzr.tags, [['v1.0.0', '5'], ['v2.0.0','7']]
39+
time_1 = Time.parse('2009-02-04 00:25:40 +0000')
40+
time_2 = Time.parse('2011-12-22 18:37:33 +0000')
41+
monkey_patch_run_method_to_match_tag_patterns
42+
assert_equal [['v1.0.0', '5', time_1], ['v2.0.0','7', time_2]], bzr.tags
43+
end
44+
end
45+
46+
private
47+
48+
def monkey_patch_run_method_to_match_tag_patterns
49+
original_method = AbstractAdapter.method(:run)
50+
AbstractAdapter.send :define_method, :run do |command|
51+
if command =~ /bzr tags/
52+
# The output of `bzr tags` sometimes has tags referring to ? while sometimes has dotted separators.
53+
"0.11-1.1 ?\n0.14-1 ?\n....\n#{ original_method.call(command) }"
54+
else
55+
original_method.call(command)
56+
end
4057
end
4158
end
4259
end

test/unit/git_misc_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ def test_ls_tree_encoding
4747

4848
def test_tags
4949
with_git_repository('git') do |git|
50-
assert_equal git.tags, [['v1.0.0', 'f6e5a894ac4173f8f2a200f2c36df38a1e61121a'],
51-
['v2.1.0', '1df547800dcd168e589bb9b26b4039bff3a7f7e4']]
50+
assert_equal git.tags, [['v1.0.0', 'f6e5a894ac4173f8f2a200f2c36df38a1e61121a', Time.parse('2016-07-31T07:58:30+05:30')],
51+
['v2.1.0', '1df547800dcd168e589bb9b26b4039bff3a7f7e4', Time.parse('2006-07-14T16:07:15-07:00')]]
5252
end
5353
end
5454

test/unit/hg_misc_test.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ def test_ls_tree_encoding
3939

4040
def test_tags
4141
with_hg_repository('hg') do |hg|
42-
assert_equal hg.tags, [['tip', '5']]
42+
time = Time.parse('Fri Jul 22 18:00:18 2016 +0530')
43+
assert_equal [['tip', '5', time]], hg.tags
4344
end
4445
end
4546
end

test/unit/svn_misc_test.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,9 @@ def test_tags
111111
mkdir -p #{ source_scm.root.gsub(/^file:../, '') }/db/transactions
112112
svn copy trunk tags/2.0 && svn commit -m 'v2.0' && svn update"
113113

114-
assert_equal([['2.0', '6']], source_scm.tags)
114+
assert_equal(['2.0', '6'], source_scm.tags.first[0..1])
115+
# Avoid millisecond comparision.
116+
assert_equal(Time.now.strftime('%F %R'), source_scm.tags.first[-1].strftime('%F %R'))
115117
end
116118
end
117119
end

0 commit comments

Comments
 (0)