Compare commits
2 commits
603037ae0b
...
a350fa1a15
Author | SHA1 | Date | |
---|---|---|---|
a350fa1a15 | |||
86c85fc9b4 |
2 changed files with 35 additions and 30 deletions
25
README.md
Normal file
25
README.md
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
# Collect Repositories
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
```shell-session
|
||||||
|
$ collect-repos list -r ./Glenux.Pro gitea_glenux=false,github=false,gitlab=false,bitbucket=false
|
||||||
|
selector = gitea_glenux=false github=false gitlab=false bitbucket=false
|
||||||
|
PATH | GITHUB | GITLAB | BITBUCKET | GITEA_GLENUX
|
||||||
|
------------------------------------------------------|--------|--------|-----------|-------------
|
||||||
|
Glenux.Pro/50a/total-server-cloning-scripts | false | false | false | false
|
||||||
|
Glenux.Pro/50a/vedecom-ukko-remote | false | false | false | false
|
||||||
|
Glenux.Pro/50a/vedecom-ukko-ui | false | false | false | false
|
||||||
|
Glenux.Pro/50a/vedecom-ukko-ui.working | false | false | false | false
|
||||||
|
Glenux.Pro/cocoworker/cocoworker | false | false | false | false
|
||||||
|
Glenux.Pro/cocoworker/master | false | false | false | false
|
||||||
|
Glenux.Pro/l-ecole-multimedia/git-fcdm-lem-2018 | false | false | false | false
|
||||||
|
Glenux.Pro/l-ecole-multimedia/site-starbucks | false | false | false | false
|
||||||
|
Glenux.Pro/l-ecole-multimedia/teaching-devops-git-lem | false | false | false | false
|
||||||
|
```
|
||||||
|
|
||||||
|
## Authors
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
|
|
@ -7,58 +7,45 @@ require 'find'
|
||||||
require 'thor'
|
require 'thor'
|
||||||
require 'table_print'
|
require 'table_print'
|
||||||
require 'tty-spinner'
|
require 'tty-spinner'
|
||||||
require 'colorize'
|
|
||||||
|
|
||||||
class ListRepos < Thor
|
class ListRepos < Thor
|
||||||
|
|
||||||
desc 'list [SELECTOR]', 'List repositories'
|
desc 'list [SELECTOR]', 'List repositories'
|
||||||
method_option :root, type: :string, aliases: '-r'
|
method_option :root, type: :string, aliases: '-r'
|
||||||
|
|
||||||
def initialize(*args)
|
def list(selector_str="")
|
||||||
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'] || '.'
|
basedir = options['root'] || '.'
|
||||||
projects = []
|
projects = []
|
||||||
spinner = TTY::Spinner.new(
|
spinner = TTY::Spinner.new(
|
||||||
hide_cursor: true,
|
hide_cursor: true,
|
||||||
clear: true
|
clear: true
|
||||||
)
|
)
|
||||||
|
|
||||||
selector = self.class.build_selector(selector_str)
|
selector = self.class.build_selector(selector_str)
|
||||||
selector_str2 = selector.map { |k, v| "#{k}=#{v.to_s.colorize(:yellow)}" }.join(' AND ')
|
selector_str2 = selector.map { |k, v| "#{k}=#{v}" }.join(' ')
|
||||||
puts "SELECTOR: #{selector_str2}"
|
puts "selector = #{selector_str2}"
|
||||||
|
|
||||||
## COLLECT
|
## COLLECT
|
||||||
spinner.auto_spin
|
spinner.auto_spin
|
||||||
system 'tput civis' # hide cursor (fix)
|
|
||||||
Find.find(basedir) do |path|
|
Find.find(basedir) do |path|
|
||||||
next unless path =~ %r{.*/.git/config$}
|
next unless path =~ %r{.*/.git/config$}
|
||||||
|
|
||||||
project_root = File.dirname(File.dirname(path)).gsub(%r{^#{basedir}/}, '')
|
project_root = File.dirname(File.dirname(path))
|
||||||
lines = File.readlines(path)
|
lines = File.readlines(path)
|
||||||
projects << {
|
projects << {
|
||||||
path: project_root,
|
path: project_root,
|
||||||
github: lines.select { |line| line =~ /github\.com/ }.any?,
|
github: lines.select { |line| line =~ /github\.com/ }.any?,
|
||||||
gitlab: lines.select { |line| line =~ /gitlab\.com/ }.any?,
|
gitlab: lines.select { |line| line =~ /gitlab\.com/ }.any?,
|
||||||
bitbucket: lines.select { |line| line =~ /bitbucket\.(com|org)/ }.any?,
|
bitbucket: lines.select { |line| line =~ /bitbucket\.com/ }.any?,
|
||||||
gitea: lines.select { |line| line =~ /code\.(dinlas\.)?apps\.glenux\.net/ }.any?,
|
gitea_glenux: lines.select { |line| line =~ /code\.(dinlas\.)?apps\.glenux\.net/ }.any?,
|
||||||
mr: self.class.mr_enabled?(project_root, lines)
|
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
spinner.stop
|
spinner.stop
|
||||||
system 'tput cnorm' # show cursor (fix)
|
|
||||||
puts ''
|
|
||||||
|
|
||||||
## REDUCE
|
## REDUCE
|
||||||
projects_selected = projects.select do |vals|
|
projects_selected = projects.select do |vals|
|
||||||
res = true
|
res = true
|
||||||
selector.each do |k, v|
|
selector.each do |k,v|
|
||||||
res &&= (vals[k] == v)
|
res &&= (vals[k] == v)
|
||||||
end
|
end
|
||||||
res
|
res
|
||||||
|
@ -68,14 +55,7 @@ class ListRepos < Thor
|
||||||
# require 'pp'
|
# require 'pp'
|
||||||
# pp projects_selected
|
# pp projects_selected
|
||||||
tp.set :max_width, 100
|
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
|
end
|
||||||
|
|
||||||
def self.build_selector(str)
|
def self.build_selector(str)
|
||||||
|
|
Loading…
Add table
Reference in a new issue