spaarti 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/spaarti +1 -1
- data/lib/spaarti/repo.rb +12 -12
- data/lib/spaarti/site.rb +20 -25
- data/lib/spaarti/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 60f66d0c8df26290e5fd5b9db40167d6e757f25b
|
4
|
+
data.tar.gz: 0f0cd166dc2e6b01a04bb6ad080a5dec07f0e392
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9daab0358cfc4e3daab536e1b7c90f2b7d633c29df5b470ded1bf158960c1a5258728a628dfe45e745376767355e889dd43e50cb1ebd85829230dac2b531e8a3
|
7
|
+
data.tar.gz: 519a19ddb18f4347f2513fb73fe020c38684c7bb86f20dac5dd7aa26064687da3b734e443b5d9202dfa44483f9d1da6f5572811fdda35e9382e3a976a9dc26b9
|
data/bin/spaarti
CHANGED
@@ -8,7 +8,7 @@ Mercenary.program(:spaarti) do |p|
|
|
8
8
|
p.description 'Tool for managing local checkouts of git repos'
|
9
9
|
p.syntax 'spaarti [options]'
|
10
10
|
|
11
|
-
p.option :
|
11
|
+
p.option :config_file, '-c FILE', '--config FILE', 'Config file'
|
12
12
|
p.option :purge, '-p', '--purge', 'Remove orphaned repos'
|
13
13
|
p.option :quiet, '-q', '--quiet', 'Silence standard output'
|
14
14
|
|
data/lib/spaarti/repo.rb
CHANGED
@@ -4,15 +4,15 @@ module Spaarti
|
|
4
4
|
##
|
5
5
|
# Repo object, handles individual repo syncing and state
|
6
6
|
class Repo
|
7
|
-
def initialize(data, client, params)
|
8
|
-
@
|
7
|
+
def initialize(data, client, params = {})
|
8
|
+
@data = data
|
9
9
|
@client = client
|
10
|
-
@
|
11
|
-
@path = @
|
10
|
+
@options = params
|
11
|
+
@path = @options[:format] % @data
|
12
12
|
end
|
13
13
|
|
14
14
|
def sync!
|
15
|
-
return log("#{@
|
15
|
+
return log("#{@data[:full_name]} already cloned") if Dir.exist?(@path)
|
16
16
|
clone
|
17
17
|
Dir.chdir(@path) { config && add_upstream }
|
18
18
|
end
|
@@ -24,7 +24,7 @@ module Spaarti
|
|
24
24
|
private
|
25
25
|
|
26
26
|
def log(msg)
|
27
|
-
puts msg unless @
|
27
|
+
puts msg unless @options[:quiet]
|
28
28
|
end
|
29
29
|
|
30
30
|
def err(msg)
|
@@ -37,22 +37,22 @@ module Spaarti
|
|
37
37
|
end
|
38
38
|
|
39
39
|
def clone
|
40
|
-
log "Cloning #{@
|
40
|
+
log "Cloning #{@data[:ssh_url]} to #{@path}"
|
41
41
|
run(
|
42
|
-
"git clone '#{@
|
43
|
-
"Failed to clone #{@
|
42
|
+
"git clone '#{@data[:ssh_url]}' '#{@path}' &>/dev/null",
|
43
|
+
"Failed to clone #{@data[:ssh_url]}"
|
44
44
|
)
|
45
45
|
end
|
46
46
|
|
47
47
|
def config
|
48
|
-
@
|
48
|
+
@options[:git_config].each do |k, v|
|
49
49
|
run("git config '#{k}' '#{v}'", "Failed to set config for #{@path}")
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
53
53
|
def add_upstream
|
54
|
-
return unless @
|
55
|
-
upstream = @client.repo(@
|
54
|
+
return unless @data[:fork]
|
55
|
+
upstream = @client.repo(@data[:id]).source.git_url
|
56
56
|
run(
|
57
57
|
"git remote add upstream '#{upstream}'",
|
58
58
|
"Failed to add upstrema for #{@path}"
|
data/lib/spaarti/site.rb
CHANGED
@@ -6,29 +6,31 @@ require 'pathname'
|
|
6
6
|
##
|
7
7
|
# Main Spaarti code, defines defaults and Site object
|
8
8
|
module Spaarti
|
9
|
-
|
10
|
-
|
11
|
-
DEFAULT_CONFIG = {
|
9
|
+
DEFAULT_OPTIONS = {
|
12
10
|
base_path: './',
|
13
11
|
auth_file: :default,
|
12
|
+
config_file: File.expand_path('~/.spaarti.yml'),
|
14
13
|
exclude: [],
|
15
14
|
format: '%{full_name}',
|
16
|
-
git_config: []
|
15
|
+
git_config: [],
|
16
|
+
quiet: false,
|
17
|
+
purge: false
|
17
18
|
}
|
18
19
|
|
19
20
|
##
|
20
|
-
# Site object, represents a group of repos
|
21
|
+
# Site object, represents a group of repos
|
21
22
|
class Site
|
22
|
-
def initialize(
|
23
|
-
|
24
|
-
|
25
|
-
fail '
|
23
|
+
def initialize(params = {})
|
24
|
+
if params[:config_file]
|
25
|
+
params[:config_file] = File.expand_path params[:config_file]
|
26
|
+
fail 'Conf file does not exist' unless File.exist? params[:config_file]
|
26
27
|
end
|
27
|
-
@options
|
28
|
+
@options = DEFAULT_OPTIONS.dup.merge params
|
29
|
+
load_config
|
28
30
|
end
|
29
31
|
|
30
32
|
def sync!
|
31
|
-
Dir.chdir(
|
33
|
+
Dir.chdir(@options[:base_path]) do
|
32
34
|
repos.each(&:sync!)
|
33
35
|
purge! if @options[:purge]
|
34
36
|
end
|
@@ -44,17 +46,10 @@ module Spaarti
|
|
44
46
|
|
45
47
|
private
|
46
48
|
|
47
|
-
def
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
def build_config
|
52
|
-
path = @options[:config]
|
53
|
-
config = DEFAULT_CONFIG.dup
|
54
|
-
return config unless File.exist?(path)
|
55
|
-
file = File.open(path) { |fh| YAML.load fh.read }
|
56
|
-
return nest if file.is_a? Array
|
57
|
-
config.merge! Cymbal.symbolize(file)
|
49
|
+
def load_config
|
50
|
+
return unless File.exist?(@options[:config_file])
|
51
|
+
config = File.open(@options[:config_file]) { |fh| YAML.load fh.read }
|
52
|
+
@options.merge! Cymbal.symbolize(config)
|
58
53
|
end
|
59
54
|
|
60
55
|
def client
|
@@ -68,7 +63,7 @@ module Spaarti
|
|
68
63
|
def auth
|
69
64
|
@auth ||= Octoauth.new(
|
70
65
|
note: 'spaarti',
|
71
|
-
file:
|
66
|
+
file: @options[:auth_file],
|
72
67
|
autosave: true
|
73
68
|
)
|
74
69
|
end
|
@@ -76,12 +71,12 @@ module Spaarti
|
|
76
71
|
def repos
|
77
72
|
@repos ||= client.repos.map do |data|
|
78
73
|
next if excluded(data.name) || excluded(data.full_name)
|
79
|
-
Repo.new data.to_h, client,
|
74
|
+
Repo.new data.to_h, client, @options.subset(:format, :git_config)
|
80
75
|
end
|
81
76
|
end
|
82
77
|
|
83
78
|
def excluded(string)
|
84
|
-
|
79
|
+
@options[:exclude].any? { |x| string.match(x) }
|
85
80
|
end
|
86
81
|
end
|
87
82
|
end
|
data/lib/spaarti/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spaarti
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Les Aker
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-02-
|
11
|
+
date: 2015-02-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: octokit
|