From dfc0aa33ad72438b5112119c3db7ac443a66302c Mon Sep 17 00:00:00 2001 From: Glenn Date: Tue, 16 Aug 2022 00:52:49 +0200 Subject: [PATCH] Initial import --- Gemfile | 10 ++++++ Gemfile.lock | 17 ++++++++++ bin/collector-repos | 82 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 109 insertions(+) create mode 100644 Gemfile create mode 100644 Gemfile.lock create mode 100755 bin/collector-repos diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..77cc770 --- /dev/null +++ b/Gemfile @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +source 'https://rubygems.org' + +# git_source(:github) { |repo_name| "https://github.com/#{repo_name}" } + +#gem 'table_print' +gem 'thor' +gem 'tty-spinner' + diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..34c8070 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,17 @@ +GEM + remote: https://rubygems.org/ + specs: + thor (1.2.1) + tty-cursor (0.7.1) + tty-spinner (0.9.3) + tty-cursor (~> 0.7) + +PLATFORMS + x86_64-linux + +DEPENDENCIES + thor + tty-spinner + +BUNDLED WITH + 2.3.20 diff --git a/bin/collector-repos b/bin/collector-repos new file mode 100755 index 0000000..db95e64 --- /dev/null +++ b/bin/collector-repos @@ -0,0 +1,82 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# vim: set ts=2 sw=2 et ft=ruby: + +require 'find' +require 'thor' +require 'table_print' +require 'tty-spinner' + +class ListRepos < Thor + + desc 'list [SELECTOR]', 'List repositories' + method_option :root, type: :string, aliases: '-r' + + def list(selector_str="") + basedir = options['root'] || '.' + projects = [] + spinner = TTY::Spinner.new( + hide_cursor: true, + clear: true + ) + + selector = self.class.build_selector(selector_str) + selector_str2 = selector.map { |k, v| "#{k}=#{v}" }.join(' ') + puts "selector = #{selector_str2}" + + ## COLLECT + spinner.auto_spin + Find.find(basedir) do |path| + next unless path =~ %r{.*/.git/config$} + + project_root = File.dirname(File.dirname(path)) + lines = File.readlines(path) + projects << { + path: project_root, + github: lines.select { |line| line =~ /github\.com/ }.any?, + gitlab: lines.select { |line| line =~ /gitlab\.com/ }.any?, + bitbucket: lines.select { |line| line =~ /bitbucket\.com/ }.any?, + gitea_glenux: lines.select { |line| line =~ /code\.(dinlas\.)?apps\.glenux\.net/ }.any?, + } + end + spinner.stop + + ## REDUCE + projects_selected = projects.select do |vals| + res = true + selector.each do |k,v| + res &&= (vals[k] == v) + end + res + end + + ## DISPLAY + # require 'pp' + # pp projects_selected + tp.set :max_width, 100 + tp projects_selected, :path, :github, :gitlab, :bitbucket, :gitea_glenux + end + + def self.build_selector(str) + str.split(',').map do |keyval| + name, value = keyval.split('=') + { name.to_sym => (value =~ /true/i) ? true : false } + end + .inject({}, &:merge) + end +end + +ListRepos.start(ARGV) + +# find ~/src -ipath '*/.git/config' -exec sh -c "grep -l 'github.com' {} \ +# | sed -e 's,^,github ,' -e 's,.git/config$,,'" \; +# +# find ~/src -ipath '*/.git/config' -exec sh -c "grep -l 'bitbucket.com' {} \ +# | sed -e 's,^,bitbucket ,' -e 's,.git/config$,,'" \; +# +# find ~/src -ipath '*/.git/config' -exec sh -c "grep -l 'gitlab.com' {} \ +# | sed -e 's,^,gitlab ,' -e 's,.git/config$,,'" \; +# +# find ~/src -ipath '*/.git/config' -exec sh -c "grep -l 'code.dinlas.apps.glenux.net' {} \ +# | sed -e 's,^,gitea-glenux ,' -e 's,.git/config$,,'" \;