From e1ef92e82e4c768bc9582530f2f19600f9eb1853 Mon Sep 17 00:00:00 2001 From: Alex Johnson Date: Mon, 19 Dec 2016 20:28:15 +0530 Subject: [PATCH] OTWO-4470 Return timestamp for tags --- .travis/.install_multiple_scms.sh | 3 ++- lib/ohloh_scm/adapters/bzr/misc.rb | 7 +++++-- lib/ohloh_scm/adapters/git/misc.rb | 7 ++++--- lib/ohloh_scm/adapters/hg/misc.rb | 5 +++-- lib/ohloh_scm/adapters/svn/misc.rb | 4 +++- test/unit/bzr_misc_test.rb | 19 ++++++++++++++++++- test/unit/git_misc_test.rb | 4 ++-- test/unit/hg_misc_test.rb | 3 ++- test/unit/svn_misc_test.rb | 4 +++- 9 files changed, 42 insertions(+), 14 deletions(-) diff --git a/.travis/.install_multiple_scms.sh b/.travis/.install_multiple_scms.sh index 2344896e..3fd09e34 100644 --- a/.travis/.install_multiple_scms.sh +++ b/.travis/.install_multiple_scms.sh @@ -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 diff --git a/lib/ohloh_scm/adapters/bzr/misc.rb b/lib/ohloh_scm/adapters/bzr/misc.rb index 4e786168..c9eb65ed 100644 --- a/lib/ohloh_scm/adapters/bzr/misc.rb +++ b/lib/ohloh_scm/adapters/bzr/misc.rb @@ -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 diff --git a/lib/ohloh_scm/adapters/git/misc.rb b/lib/ohloh_scm/adapters/git/misc.rb index 1dec1961..280ad254 100644 --- a/lib/ohloh_scm/adapters/git/misc.rb +++ b/lib/ohloh_scm/adapters/git/misc.rb @@ -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 diff --git a/lib/ohloh_scm/adapters/hg/misc.rb b/lib/ohloh_scm/adapters/hg/misc.rb index 649fb531..1f25463e 100644 --- a/lib/ohloh_scm/adapters/hg/misc.rb +++ b/lib/ohloh_scm/adapters/hg/misc.rb @@ -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 diff --git a/lib/ohloh_scm/adapters/svn/misc.rb b/lib/ohloh_scm/adapters/svn/misc.rb index 6e4924df..88b6b857 100644 --- a/lib/ohloh_scm/adapters/svn/misc.rb +++ b/lib/ohloh_scm/adapters/svn/misc.rb @@ -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 diff --git a/test/unit/bzr_misc_test.rb b/test/unit/bzr_misc_test.rb index 113f6ce6..8e7b9786 100644 --- a/test/unit/bzr_misc_test.rb +++ b/test/unit/bzr_misc_test.rb @@ -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 diff --git a/test/unit/git_misc_test.rb b/test/unit/git_misc_test.rb index 1b65cc71..ab2464c6 100644 --- a/test/unit/git_misc_test.rb +++ b/test/unit/git_misc_test.rb @@ -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 diff --git a/test/unit/hg_misc_test.rb b/test/unit/hg_misc_test.rb index 137fe791..5dab6f01 100644 --- a/test/unit/hg_misc_test.rb +++ b/test/unit/hg_misc_test.rb @@ -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 diff --git a/test/unit/svn_misc_test.rb b/test/unit/svn_misc_test.rb index 551a785f..5be326ba 100644 --- a/test/unit/svn_misc_test.rb +++ b/test/unit/svn_misc_test.rb @@ -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