Compare commits
4 commits
a350fa1a15
...
603037ae0b
Author | SHA1 | Date | |
---|---|---|---|
603037ae0b | |||
3eb0d70f1a | |||
84615d228e | |||
7f9db265b4 |
1 changed files with 30 additions and 10 deletions
|
@ -7,13 +7,22 @@ require 'find'
|
|||
require 'thor'
|
||||
require 'table_print'
|
||||
require 'tty-spinner'
|
||||
require 'colorize'
|
||||
|
||||
class ListRepos < Thor
|
||||
|
||||
desc 'list [SELECTOR]', 'List repositories'
|
||||
method_option :root, type: :string, aliases: '-r'
|
||||
|
||||
def list(selector_str="")
|
||||
def initialize(*args)
|
||||
String.disable_colorization = true unless ENV['NO_COLOR'].nil?
|
||||
super
|
||||
end
|
||||
|
||||
def list(selector_str='')
|
||||
trap 'SIGINT' do
|
||||
system 'tput cnorm' # show cursor (fix)
|
||||
exit! 130
|
||||
end
|
||||
basedir = options['root'] || '.'
|
||||
projects = []
|
||||
spinner = TTY::Spinner.new(
|
||||
|
@ -22,25 +31,29 @@ class ListRepos < Thor
|
|||
)
|
||||
|
||||
selector = self.class.build_selector(selector_str)
|
||||
selector_str2 = selector.map { |k, v| "#{k}=#{v}" }.join(' ')
|
||||
puts "selector = #{selector_str2}"
|
||||
selector_str2 = selector.map { |k, v| "#{k}=#{v.to_s.colorize(:yellow)}" }.join(' AND ')
|
||||
puts "SELECTOR: #{selector_str2}"
|
||||
|
||||
## COLLECT
|
||||
spinner.auto_spin
|
||||
system 'tput civis' # hide cursor (fix)
|
||||
Find.find(basedir) do |path|
|
||||
next unless path =~ %r{.*/.git/config$}
|
||||
|
||||
project_root = File.dirname(File.dirname(path))
|
||||
project_root = File.dirname(File.dirname(path)).gsub(%r{^#{basedir}/}, '')
|
||||
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?,
|
||||
bitbucket: lines.select { |line| line =~ /bitbucket\.(com|org)/ }.any?,
|
||||
gitea: lines.select { |line| line =~ /code\.(dinlas\.)?apps\.glenux\.net/ }.any?,
|
||||
mr: self.class.mr_enabled?(project_root, lines)
|
||||
}
|
||||
end
|
||||
spinner.stop
|
||||
system 'tput cnorm' # show cursor (fix)
|
||||
puts ''
|
||||
|
||||
## REDUCE
|
||||
projects_selected = projects.select do |vals|
|
||||
|
@ -55,7 +68,14 @@ class ListRepos < Thor
|
|||
# require 'pp'
|
||||
# pp projects_selected
|
||||
tp.set :max_width, 100
|
||||
tp projects_selected, :path, :github, :gitlab, :bitbucket, :gitea_glenux
|
||||
|
||||
columns = [:path] + ([:github, :gitlab, :bitbucket, :gitea, :mr] - selector.keys)
|
||||
tp projects_selected, *columns
|
||||
end
|
||||
|
||||
def self.mr_enabled?(project_root, _lines)
|
||||
system "cd #{project_root} && mr status >/dev/null 2>&1"
|
||||
$?.success?
|
||||
end
|
||||
|
||||
def self.build_selector(str)
|
||||
|
|
Loading…
Add table
Reference in a new issue