Skip to content

Commit

Permalink
Merge pull request #46 from blackducksoftware/OTWO-4470
Browse files Browse the repository at this point in the history
OTWO-4470 Return timestamp for tags
  • Loading branch information
PDegenPortnoy authored Dec 22, 2016
2 parents cb98372 + e1ef92e commit ec65be8
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 14 deletions.
3 changes: 2 additions & 1 deletion .travis/.install_multiple_scms.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
sudo sh -c 'echo "deb http://opensource.wandisco.com/ubuntu precise svn18" >> /etc/apt/sources.list.d/subversion18.list'
sudo wget -q http://opensource.wandisco.com/wandisco-debian.gpg -O- | sudo apt-key add -
sudo apt-add-repository -y ppa:git-core/ppa
sudo apt-get update
sudo apt-get install -y subversion cvs bzr mercurial
sudo apt-get install -y git subversion cvs bzr mercurial
sudo ln -s /usr/bin/cvs /usr/bin/cvsnt
7 changes: 5 additions & 2 deletions lib/ohloh_scm/adapters/bzr/misc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,11 @@ def export(dest_dir, token=head_token)
def tags
tag_strings = run("cd '#{url}' && bzr tags").split(/\n/)
tag_strings.map do |tag_string|
tag_string.split(/\s+/)
end
tag_name, rev = tag_string.split(/\s+/)
next if rev == '?' || tag_name == '....'
time_string = run("cd '#{ url }' && bzr log -r #{ rev } | grep 'timestamp:' | sed 's/timestamp://'")
[tag_name, rev, Time.parse(time_string)]
end.compact
end
end
end
7 changes: 4 additions & 3 deletions lib/ohloh_scm/adapters/git/misc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,12 @@ def no_tags?

def tags
return [] if no_tags?
tag_strings = run("cd #{url} && git show-ref --tags").split(/\n/)
tag_strings = run("cd #{url} && git tag --format='%(creatordate:iso-strict) %(objectname) %(refname)'").split(/\n/)
tag_strings.map do |tag_string|
commit_hash, tag_path = tag_string.split(/\s/)
timestamp_string, commit_hash, tag_path = tag_string.split(/\s/)
timestamp = Time.parse(timestamp_string)
tag_name = tag_path.gsub('refs/tags/', '')
[tag_name, commit_hash]
[tag_name, commit_hash, timestamp]
end
end
end
Expand Down
5 changes: 3 additions & 2 deletions lib/ohloh_scm/adapters/hg/misc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ def tags
tag_strings = run("cd '#{path}' && hg tags").split(/\n/)
tag_strings.map do |tag_string|
tag_name, rev_number_and_hash = tag_string.split(/\s+/)
rev_number = rev_number_and_hash.slice(/\A\d+/)
[tag_name, rev_number]
rev = rev_number_and_hash.slice(/\A\d+/)
time_string = run("cd '#{ path }' && hg log -r #{ rev } | grep 'date:' | sed 's/date://'")
[tag_name, rev, Time.parse(time_string)]
end
end
end
Expand Down
4 changes: 3 additions & 1 deletion lib/ohloh_scm/adapters/svn/misc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,9 @@ def opt_auth
def tags
tag_strings = `svn ls -v #{ base_path}/tags`.split(/\n/)
tag_strings.map do |tag_string|
tag_string.split(' ').values_at(-1, 0).map { |v| v.chomp('/') }
date_string = tag_string.split(' ').values_at(-4, -3, -2).join(' ')
folder_and_rev = tag_string.split(' ').values_at(-1, 0).map { |v| v.chomp('/') }
folder_and_rev << Time.parse(date_string)
end[1..-1]
end

Expand Down
19 changes: 18 additions & 1 deletion test/unit/bzr_misc_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,24 @@ def test_export

def test_tags
with_bzr_repository('bzr') do |bzr|
assert_equal bzr.tags, [['v1.0.0', '5'], ['v2.0.0','7']]
time_1 = Time.parse('2009-02-04 00:25:40 +0000')
time_2 = Time.parse('2011-12-22 18:37:33 +0000')
monkey_patch_run_method_to_match_tag_patterns
assert_equal [['v1.0.0', '5', time_1], ['v2.0.0','7', time_2]], bzr.tags
end
end

private

def monkey_patch_run_method_to_match_tag_patterns
original_method = AbstractAdapter.method(:run)
AbstractAdapter.send :define_method, :run do |command|
if command =~ /bzr tags/
# The output of `bzr tags` sometimes has tags referring to ? while sometimes has dotted separators.
"0.11-1.1 ?\n0.14-1 ?\n....\n#{ original_method.call(command) }"
else
original_method.call(command)
end
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions test/unit/git_misc_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ def test_ls_tree_encoding

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

Expand Down
3 changes: 2 additions & 1 deletion test/unit/hg_misc_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ def test_ls_tree_encoding

def test_tags
with_hg_repository('hg') do |hg|
assert_equal hg.tags, [['tip', '5']]
time = Time.parse('Fri Jul 22 18:00:18 2016 +0530')
assert_equal [['tip', '5', time]], hg.tags
end
end
end
Expand Down
4 changes: 3 additions & 1 deletion test/unit/svn_misc_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ def test_tags
mkdir -p #{ source_scm.root.gsub(/^file:../, '') }/db/transactions
svn copy trunk tags/2.0 && svn commit -m 'v2.0' && svn update"

assert_equal([['2.0', '6']], source_scm.tags)
assert_equal(['2.0', '6'], source_scm.tags.first[0..1])
# Avoid millisecond comparision.
assert_equal(Time.now.strftime('%F %R'), source_scm.tags.first[-1].strftime('%F %R'))
end
end
end
Expand Down

0 comments on commit ec65be8

Please sign in to comment.