From 4b6e87fadd4ecddb5af6cca5fb51c88880e9d61b Mon Sep 17 00:00:00 2001 From: Harald Sitter Date: Wed, 17 Oct 2018 13:51:05 +0200 Subject: [PATCH] revise debian factory --- ci-tooling/lib/projects/factory/debian.rb | 129 +--------------------- 1 file changed, 5 insertions(+), 124 deletions(-) diff --git a/ci-tooling/lib/projects/factory/debian.rb b/ci-tooling/lib/projects/factory/debian.rb index ce855860..339246ca 100644 --- a/ci-tooling/lib/projects/factory/debian.rb +++ b/ci-tooling/lib/projects/factory/debian.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true # -# Copyright (C) 2016 Harald Sitter +# Copyright (C) 2018 Harald Sitter . -require_relative 'base' -require_relative 'common' +require_relative 'gitlab' class ProjectsFactory # Debian specific project factory. - class Debian < Base - include ProjectsFactoryCommon - DEFAULT_URL_BASE = 'git://anonscm.debian.org' - - # FIXME: same as in neon - # FIXME: needs a writer! - def self.url_base - @url_base ||= DEFAULT_URL_BASE - end + class Debian < Gitlab + @url_base = 'https://salsa.debian.org' def self.understand?(type) - type == 'git.debian.org' - end - - private - - # FIXME: not exactly the same as in Neon. prefix is only here. could be in - # neon too though - def split_entry(entry) - parts = entry.split('/') - name = parts[-1] - component = parts[-2] || 'debian' - [name, component, parts[0..-3]] - end - - def params(str) - name, component, prefix = split_entry(str) - default_params.merge( - name: name, - component: component, - url_base: "#{self.class.url_base}/#{prefix.join('/')}" - ) - end - - # FIXME: test needs to check that we get the correct url out - # FIXME: same as in neon - def from_string(str, params = {}) - kwords = params(str) - kwords.merge!(symbolize(params)) - puts "new_project(#{kwords})" - new_project(**kwords) - rescue Project::GitTransactionError, RuntimeError => e - p e - nil - end - - # FIXME: same as in neon - def split_hash(hash) - clean_hash(*hash.first) - end - - # FIXME: same as in neon - def clean_hash(base, subset) - subset.collect! do |sub| - # Coerce flat strings into hash. This makes handling more consistent - # further down the line. Flat strings simply have empty properties {}. - sub = sub.is_a?(Hash) ? sub : { sub => {} } - # Convert the subset into a pattern matching set by converting the - # keys into suitable patterns. - key = sub.keys[0] - sub[CI::FNMatchPattern.new(join_path(base, key))] = sub.delete(key) - sub - end - [base, subset] - end - - # FIXME: same as in neon - def each_pattern_value(subset) - subset.each do |sub| - pattern = sub.keys[0] - value = sub.values[0] - yield pattern, value - end - end - - # FIXME: same as in neon - def match_path_to_subsets(path, subset) - matches = {} - each_pattern_value(subset) do |pattern, value| - next unless pattern.match?(path) - match = [path, value] # This will be an argument list for from_string. - matches[pattern] = match - end - matches - end - - def from_hash(hash) - base, subset = split_hash(hash) - raise 'not array' unless subset.is_a?(Array) - - selection = self.class.ls(base).collect do |path| - next nil unless path.start_with?(base) # speed-up, these can't match... - matches = match_path_to_subsets(path, subset) - # Get best matching pattern. - CI::PatternBase.sort_hash(matches).values[0] - end - selection.compact.collect { |s| from_string(*s) } - end - - class << self - def ls(base) - # NOTE: unlike neon we have a segmented cache here for each base. - # This is vastly more efficient than listing recursively as we do not - # really know the maximum useful depth so a boundless find would take - # years as it needs to traverse the entire file tree of /git (or a - # subset at least). Since this includes the actual repos, their .git - # etc. it is not viable. - # Performance testing suggests that each ssh access takes - # approximately 1 second, which is very acceptable. - @list_cache ||= {} - return @list_cache[base] if @list_cache.key?(base) - output = `ssh git.debian.org find /git/#{base} -maxdepth 1 -type d` - raise 'Failed to find repo list on host' unless $?.to_i.zero? - @list_cache[base] = cleanup_ls(output).freeze - end - - private - - def cleanup_ls(data) - data.chop.split(' ').collect do |line| - line.gsub('/git/', '').gsub('.git', '') - end - end + type == 'salsa.debian.org' end end end -- 2.17.1