[SCM] ci-tooling packaging branch, master, updated. d5face6d7fedc083e46ef7f035735c15ff395b50

Harald Sitter apachelogger-guest at moszumanska.debian.org
Mon Mar 16 10:15:37 UTC 2015


Gitweb-URL: http://git.debian.org/?p=pkg-kde/ci-tooling.git;a=commitdiff;h=d5face6

The following commit has been merged in the master branch:
commit d5face6d7fedc083e46ef7f035735c15ff395b50
Author: Harald Sitter <sitter at kde.org>
Date:   Mon Mar 16 11:14:48 2015 +0100

    move upstream_scm logic into standalone class
    
    except for the untested weird qt stuff that would depend on checking
    component... not sure why that is harcoded rather than repo-bound or in
    a data file
---
 lib/ci/upstream_scm.rb                             | 33 +++++++++++++++
 lib/projects.rb                                    | 19 +++------
 .../test_override/debian/meta/upstream_scm.json    |  1 +
 .../debian/meta/upstream_scm.json                  |  1 +
 test/test_upstream_scm.rb                          | 47 ++++++++++++++++++++++
 5 files changed, 87 insertions(+), 14 deletions(-)

diff --git a/lib/ci/upstream_scm.rb b/lib/ci/upstream_scm.rb
new file mode 100644
index 0000000..31feab3
--- /dev/null
+++ b/lib/ci/upstream_scm.rb
@@ -0,0 +1,33 @@
+require 'json'
+
+class UpstreamSCM
+  attr_reader :type
+  attr_reader :url
+  attr_reader :branch
+
+  # FIXME: I really don't like how we have to eat name here in order to compose
+  # a default. it's all sorts of meh. Maybe deduce from debian/changelog or
+  # git origin's name?
+  def initialize(name, working_directory)
+    @directory = working_directory
+
+    @type = 'git'
+    @url = "git://anongit.kde.org/#{name.chomp('-qt4')}"
+    @branch = 'master'
+
+    @type = override['type'] || @type
+    @url = override['url'] || @url
+    @branch = override['branch'] || @branch
+  end
+
+  private
+
+  def override
+    return @override if defined?(@override)
+
+    @override = {}
+    file_path = File.join(@directory, 'debian/meta/upstream_scm.json')
+    @override = JSON.parse(File.read(file_path)) if File.exist?(file_path)
+    @override.freeze
+  end
+end
diff --git a/lib/projects.rb b/lib/projects.rb
index ce5973b..316949d 100644
--- a/lib/projects.rb
+++ b/lib/projects.rb
@@ -3,10 +3,9 @@ require 'pathname'
 require 'uri'
 require 'fileutils'
 
+require_relative 'ci/upstream_scm'
 require_relative 'debian/control'
 
-Scm = Struct.new(:type, :url, :branch)
-
 class Project
   # Name of the thing (e.g. the repo name)
   attr_reader :name
@@ -91,21 +90,13 @@ class Project
           @series_branches << branch.gsub('refs/remotes/origin/', '')
         end
 
-        upstream_scm = {}
-        if File.exist?('debian/meta/upstream_scm.json')
-          upstream_scm = JSON.parse(File.read('debian/meta/upstream_scm.json'))
-        end
-
+        @upstream_scm = UpstreamSCM.new(name, Dir.pwd)
+        # FIXME: why is this not a repo side override?
         if component == 'qt'
-          upstream_scm['url'] ||= "https://gitorious.org/qt/#{name}.git"
-          upstream_scm['branch'] ||= '5.4'
+          @upstream_scm.instance_variable_set(:@url, "https://gitorious.org/qt/#{name}.git")
+          @upstream_scm.instance_variable_set(:@branch, '5.4')
         end
 
-        default_repo_url = "git://anongit.kde.org/#{name.chomp('-qt4')}"
-        @upstream_scm = Scm.new(upstream_scm['type'] ||= 'git',
-                                upstream_scm['url'] ||= default_repo_url,
-                                upstream_scm['branch'] ||= 'master')
-
         # FIXME: Probably should be converted to a symbol at a later point
         #        since xs-testsuite could change to random other string in the
         #        future
diff --git a/test/data/test_upstream_scm/test_override/debian/meta/upstream_scm.json b/test/data/test_upstream_scm/test_override/debian/meta/upstream_scm.json
new file mode 100644
index 0000000..076a98a
--- /dev/null
+++ b/test/data/test_upstream_scm/test_override/debian/meta/upstream_scm.json
@@ -0,0 +1 @@
+{"branch":"brunch","url":"urlolo","type":"git2"}
diff --git a/test/data/test_upstream_scm/test_override_branch_only/debian/meta/upstream_scm.json b/test/data/test_upstream_scm/test_override_branch_only/debian/meta/upstream_scm.json
new file mode 100644
index 0000000..0dba4bb
--- /dev/null
+++ b/test/data/test_upstream_scm/test_override_branch_only/debian/meta/upstream_scm.json
@@ -0,0 +1 @@
+{"branch":"brunch"}
diff --git a/test/test_upstream_scm.rb b/test/test_upstream_scm.rb
new file mode 100644
index 0000000..e383834
--- /dev/null
+++ b/test/test_upstream_scm.rb
@@ -0,0 +1,47 @@
+require 'test/unit'
+
+require_relative '../lib/ci/upstream_scm'
+
+# Test ci/upstream_scm
+class UpstreamSCMTest < Test::Unit::TestCase
+  self.test_order = :defined
+
+  def setup
+    script_base_path = File.expand_path(File.dirname(__FILE__))
+    script_name = File.basename(__FILE__, '.rb')
+    @datadir = File.join(script_base_path, 'data', script_name)
+  end
+
+  def data
+    index = 0
+    caller = ''
+    until caller.start_with?('test_')
+      caller = caller_locations(index, 1)[0].label
+      index += 1
+    end
+    File.join(@datadir, caller)
+  end
+
+  def test_defaults
+    scm = UpstreamSCM.new('breeze-qt4', '/')
+    assert_equal('git', scm.type)
+    assert_equal('git://anongit.kde.org/breeze', scm.url)
+    assert_equal('master', scm.branch)
+  end
+
+  def test_override
+    scm = UpstreamSCM.new('trololo', data)
+    assert_equal('git2', scm.type)
+    assert_equal('urlolo', scm.url)
+    assert_equal('brunch', scm.branch)
+  end
+
+  def test_override_branch_only
+    # Make sure defaults fall through correctly. If only branch is overridden
+    # the rest should use the default values.
+    scm = UpstreamSCM.new('trololo', data)
+    assert_equal('git', scm.type)
+    assert_equal('git://anongit.kde.org/trololo', scm.url)
+    assert_equal('brunch', scm.branch)
+  end
+end

-- 
ci-tooling packaging



More information about the pkg-kde-commits mailing list