electric_monk 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/electric_monk.rb +55 -53
- data/lib/electric_monk/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5fdfdaae4c92e5e8022a74520096288cb223d15a
|
4
|
+
data.tar.gz: '05250191c08281ba24c7ed36ab47741d3bcbebbf'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e0aa2604ed8edf53aaf82013f52c58f23ce54379f7930c902ef3f10b03d0d52c476b76eceb47ef75f1f0e66f01c1b35600507665533b9b34cb9c4faf126ae0b6
|
7
|
+
data.tar.gz: e099cbc0b6a154aa1b7bf54397179bf9b50ee3af11b7ffe759081daa05622a64c9ba8091c440681bbf7a144926efd6745781ae64f4aab67c23642a3818673f69
|
data/lib/electric_monk.rb
CHANGED
@@ -6,22 +6,34 @@ require "singleton"
|
|
6
6
|
module ElectricMonk
|
7
7
|
class CLI
|
8
8
|
attr_reader :config
|
9
|
+
attr_reader :reporter
|
9
10
|
|
10
11
|
def initialize(config_path:, reporter: Reporter.instance)
|
11
|
-
@
|
12
|
+
@reporter = reporter
|
13
|
+
@config = Config.new(config_path)
|
12
14
|
end
|
13
15
|
|
14
16
|
def run
|
15
17
|
config.projects.each do |project|
|
16
|
-
project.
|
18
|
+
reporter.start(project.name)
|
19
|
+
|
20
|
+
unless project.exists?
|
21
|
+
reporter.update_progress("Cloning #{project.name}")
|
22
|
+
project.clone_project
|
23
|
+
end
|
24
|
+
|
25
|
+
if project.valid?
|
26
|
+
reporter.fail(project.failures)
|
27
|
+
else
|
28
|
+
reporter.succeed(project.name)
|
29
|
+
end
|
17
30
|
end
|
18
31
|
end
|
19
32
|
end
|
20
33
|
|
21
34
|
class Config
|
22
|
-
def initialize(path
|
35
|
+
def initialize(path)
|
23
36
|
@config = TomlRB.load_file(path)
|
24
|
-
@reporter = reporter
|
25
37
|
end
|
26
38
|
|
27
39
|
def root
|
@@ -33,8 +45,7 @@ module ElectricMonk
|
|
33
45
|
Project.new(
|
34
46
|
root: root,
|
35
47
|
name: name,
|
36
|
-
origin: attributes.fetch("origin")
|
37
|
-
reporter: @reporter
|
48
|
+
origin: attributes.fetch("origin")
|
38
49
|
)
|
39
50
|
end
|
40
51
|
end
|
@@ -44,35 +55,32 @@ module ElectricMonk
|
|
44
55
|
attr_reader :root
|
45
56
|
attr_reader :name
|
46
57
|
attr_reader :origin
|
47
|
-
attr_reader :
|
58
|
+
attr_reader :failures
|
48
59
|
|
49
|
-
def initialize(root:, name:, origin
|
60
|
+
def initialize(root:, name:, origin:)
|
50
61
|
@root = root
|
51
62
|
@name = name
|
52
63
|
@origin = origin
|
53
|
-
@reporter = reporter
|
54
64
|
end
|
55
65
|
|
56
|
-
def
|
57
|
-
if
|
58
|
-
if
|
59
|
-
|
60
|
-
reporter.warn("#{name}: #{dirty_files} dirty files")
|
61
|
-
elsif unpushed_commits?
|
62
|
-
reporter.warn("#{name}: #{unpushed_commits} unpushed commits")
|
63
|
-
else
|
64
|
-
reporter.info(name)
|
65
|
-
end
|
66
|
-
else
|
67
|
-
reporter.warn("#{name}: Wrong remote '#{current_remote}'")
|
66
|
+
def valid?
|
67
|
+
if remote_correct?
|
68
|
+
if dirty_files? || unpushed_commits?
|
69
|
+
@failures = "#{name}: #{dirty_files} dirty files and #{unpushed_commits} unpushed commits"
|
68
70
|
end
|
69
71
|
else
|
70
|
-
|
71
|
-
clone_project
|
72
|
-
end
|
72
|
+
@failures = "#{name}: Wrong remote '#{current_remote}'"
|
73
73
|
end
|
74
74
|
end
|
75
75
|
|
76
|
+
def exists?
|
77
|
+
File.exist?(path)
|
78
|
+
end
|
79
|
+
|
80
|
+
def clone_project
|
81
|
+
execute("git clone #{origin} #{name}", chdir: root)
|
82
|
+
end
|
83
|
+
|
76
84
|
private
|
77
85
|
|
78
86
|
def dirty_files?
|
@@ -95,18 +103,10 @@ module ElectricMonk
|
|
95
103
|
execute("git remote get-url origin", chdir: path)
|
96
104
|
end
|
97
105
|
|
98
|
-
def clone_project
|
99
|
-
execute("git clone #{origin} #{name}", chdir: root)
|
100
|
-
end
|
101
|
-
|
102
106
|
def remote_correct?
|
103
107
|
origin == current_remote
|
104
108
|
end
|
105
109
|
|
106
|
-
def exists?
|
107
|
-
File.exist?(path)
|
108
|
-
end
|
109
|
-
|
110
110
|
def path
|
111
111
|
File.join(root, name)
|
112
112
|
end
|
@@ -119,32 +119,34 @@ module ElectricMonk
|
|
119
119
|
class Reporter
|
120
120
|
include Singleton
|
121
121
|
|
122
|
-
def
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
def warn(msg)
|
127
|
-
puts "✗ #{msg}"
|
128
|
-
end
|
122
|
+
def start(task_name)
|
123
|
+
@task_name = task_name
|
124
|
+
@final_message = nil
|
129
125
|
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
while show_spinner do
|
136
|
-
print "#{chars.next} #{waiting_msg}"
|
126
|
+
@spinner = Thread.new do
|
127
|
+
chars = %w[⠋ ⠙ ⠹ ⠸ ⠼ ⠴ ⠦ ⠧ ⠇ ⠏].cycle
|
128
|
+
until @final_message do
|
129
|
+
current_task_name = @task_name
|
130
|
+
print "#{chars.next} #{current_task_name}"
|
137
131
|
sleep 0.1
|
138
|
-
print "\b" * (
|
132
|
+
print "\b \b" * (current_task_name.length + 2)
|
139
133
|
end
|
140
|
-
|
141
|
-
info(done_msg + padding)
|
134
|
+
puts @final_message
|
142
135
|
end
|
136
|
+
end
|
137
|
+
|
138
|
+
def update_progress(task_name)
|
139
|
+
@task_name = task_name
|
140
|
+
end
|
141
|
+
|
142
|
+
def succeed(msg)
|
143
|
+
@final_message = "✓ #{msg}"
|
144
|
+
@spinner.join
|
145
|
+
end
|
143
146
|
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
}
|
147
|
+
def fail(msg)
|
148
|
+
@final_message = "✗ #{msg}"
|
149
|
+
@spinner.join
|
148
150
|
end
|
149
151
|
end
|
150
152
|
end
|