spectre-git 0.1.1 → 0.2.0
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/lib/spectre/git.rb +63 -17
- metadata +2 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 43429a3308a69bf57e10cc825c1ec52263c12a54965a6b2574c7fd9f3cfef396
|
4
|
+
data.tar.gz: cfe8b65f89eebaa202b63f4e18fd209c69de68fdde886d0d7cc42cec4e23b54c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d4e10d58912256192d3eda3c2435d571c879c20c4a573ae6d2022b1b7c8f94e37634aa5c885237783d0cdf6a98b0c2f76b94ffac9156f71e8e3450ee33ddcab7
|
7
|
+
data.tar.gz: 806344e64f6fff644fb76629af41437af7ba5055ee0c3c0f893dd6b11209bd72a5a84557c0e7cc9111997c310c4378d7f448a1d8bdb500ea8eb1a9bad875cedf
|
data/lib/spectre/git.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
+
require 'open3'
|
1
2
|
require 'fileutils'
|
2
|
-
require 'git'
|
3
3
|
require 'logger'
|
4
4
|
require 'spectre'
|
5
5
|
|
@@ -10,7 +10,7 @@ module Spectre
|
|
10
10
|
def initialize cfg, logger
|
11
11
|
@__logger = logger
|
12
12
|
@__cfg = cfg
|
13
|
-
@
|
13
|
+
@__repo_path = nil
|
14
14
|
|
15
15
|
url(@__cfg['url'])
|
16
16
|
@__cfg['branch'] = 'master' unless @__cfg['branch']
|
@@ -23,8 +23,8 @@ module Spectre
|
|
23
23
|
|
24
24
|
@__cfg['url'] = url_match[:url]
|
25
25
|
@__cfg['scheme'] = url_match[:scheme]
|
26
|
-
@__cfg['username'] = url_match[:user]
|
27
|
-
@__cfg['password'] = url_match[:pass]
|
26
|
+
@__cfg['username'] = url_match[:user] unless @__cfg['username']
|
27
|
+
@__cfg['password'] = url_match[:pass] unless @__cfg['password']
|
28
28
|
@__cfg['name'] = url_match[:name] unless @__cfg['name']
|
29
29
|
@__cfg['working_dir'] = './tmp' unless @__cfg['working_dir']
|
30
30
|
end
|
@@ -42,42 +42,74 @@ module Spectre
|
|
42
42
|
@__cfg['working_dir']
|
43
43
|
end
|
44
44
|
|
45
|
+
def cert file_path
|
46
|
+
@__cfg['cert'] = file_path
|
47
|
+
end
|
48
|
+
|
45
49
|
def branch name
|
46
50
|
@__cfg['branch'] = name
|
47
51
|
end
|
48
52
|
|
49
53
|
def clone
|
50
|
-
@
|
51
|
-
|
52
|
-
|
54
|
+
@__repo_path = File.absolute_path File.join(@__cfg['working_dir'], @__cfg['name'])
|
55
|
+
|
56
|
+
if File.exist? @__repo_path
|
57
|
+
FileUtils.rm_rf(@__repo_path)
|
58
|
+
@__logger.debug("repo path '#{@__repo_path}' removed")
|
59
|
+
end
|
60
|
+
|
61
|
+
FileUtils.mkpath(@__repo_path)
|
62
|
+
@__logger.debug("repo path '#{@__repo_path}' created")
|
63
|
+
|
64
|
+
clone_cmd = ['git', 'clone']
|
65
|
+
clone_cmd << '--branch'
|
66
|
+
clone_cmd << @__cfg['branch']
|
67
|
+
|
68
|
+
if @__cfg['cert']
|
69
|
+
clone_cmd << '--config'
|
70
|
+
clone_cmd << "http.sslCAInfo=#{@__cfg['cert']}"
|
71
|
+
end
|
72
|
+
|
73
|
+
clone_cmd << get_url
|
74
|
+
clone_cmd << @__repo_path
|
75
|
+
|
76
|
+
clone_cmd = clone_cmd.join(' ')
|
77
|
+
|
78
|
+
@__logger.info("#{clone_cmd.gsub /:([^\:\@\/\/]*)@/, ':*****@'}")
|
79
|
+
|
80
|
+
run(clone_cmd, log: false)
|
53
81
|
end
|
54
82
|
|
55
83
|
def add path
|
56
|
-
|
84
|
+
run("git add \"#{path}\"")
|
57
85
|
end
|
58
86
|
|
59
87
|
def add_all
|
60
|
-
|
88
|
+
run("git add --all")
|
61
89
|
end
|
62
90
|
|
63
|
-
def
|
64
|
-
|
91
|
+
def tag name, message: nil
|
92
|
+
run("git tag -a -m \"#{message}\"")
|
65
93
|
end
|
66
94
|
|
67
95
|
def commit message
|
68
|
-
|
96
|
+
run("git commit -m \"#{message}\"")
|
69
97
|
end
|
70
98
|
|
71
99
|
def push
|
72
|
-
|
100
|
+
run("git push")
|
73
101
|
end
|
74
102
|
|
75
103
|
def pull
|
76
|
-
|
104
|
+
run("git pull")
|
105
|
+
end
|
106
|
+
|
107
|
+
def pull
|
108
|
+
run("git pull")
|
77
109
|
end
|
78
110
|
|
79
111
|
def write_file path, content
|
80
|
-
full_path = File.join(@
|
112
|
+
full_path = File.join(@__repo_path, path)
|
81
113
|
|
82
114
|
file = File.open(full_path, 'w')
|
83
115
|
file.write(content)
|
@@ -87,12 +119,26 @@ module Spectre
|
|
87
119
|
end
|
88
120
|
|
89
121
|
def read_file path
|
90
|
-
full_path = File.join(@
|
122
|
+
full_path = File.join(@__repo_path, path)
|
91
123
|
File.read(full_path)
|
92
124
|
end
|
93
125
|
|
94
126
|
def cleanup
|
95
|
-
FileUtils.rm_rf(@
|
127
|
+
FileUtils.rm_rf(@__repo_path)
|
128
|
+
end
|
129
|
+
|
130
|
+
def run cmd, log: true
|
131
|
+
stdin, stdout, stderr, wait_thr = Open3.popen3(cmd, chdir: @__repo_path)
|
132
|
+
|
133
|
+
@__logger.info(cmd) if log
|
134
|
+
|
135
|
+
output = stdout.gets(nil)
|
136
|
+
stdout.close
|
137
|
+
|
138
|
+
error = stderr.gets(nil)
|
139
|
+
stderr.close
|
140
|
+
|
141
|
+
raise error unless wait_thr.value.exitstatus == 0
|
96
142
|
end
|
97
143
|
|
98
144
|
private
|
metadata
CHANGED
@@ -1,29 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spectre-git
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christian Neubauer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-06-
|
11
|
+
date: 2021-06-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: git
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - ">="
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: 1.8.0
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - ">="
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: 1.8.0
|
27
13
|
- !ruby/object:Gem::Dependency
|
28
14
|
name: spectre-core
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|