spectre-git 0.2.1 → 2.0.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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/spectre/git.rb +170 -179
  3. metadata +27 -17
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d095a2bea71ef37d5836a116e5c76cadbe5284a7a41ca760fbd0a0f4032e6f81
4
- data.tar.gz: 30c03a76df3cb252d8faff721ef6b7efbba0cd37f2181531c83086f730a53345
3
+ metadata.gz: 601d03616fada342e6d886e5d257be8b6909d7e0b29a3b5d413cf6164b5a605c
4
+ data.tar.gz: 7c2a0892ef5543f0191ff351bedc62d16c9d92daf38c5a0445fecaf28683a850
5
5
  SHA512:
6
- metadata.gz: 0f48d279ed4d9a41a9a4f26e6fe216a982cb9202c7b4105aac5652a53e3e5b38979588d85a997a0debae018e79ffd473c2c861b7a809de775a5cc9566dd5548a
7
- data.tar.gz: 6339afdf9e290e9dc7da2b0729e43276a9f90a475b354260b438c9c788496f03d464297e2539ff3ef1a69e53e0b8adde088405c4c9ca4b2ede130bb3c26422b9
6
+ metadata.gz: 0e1d9ff166fcb1b3a95d98f2ff7c46f9bb95e201da4a4ae1f17b3a0bbfbec4c09b0b3c0c49b8660bb728a1a9360e51b489ed3b5c4d2386868a9d7d79d4f8615b
7
+ data.tar.gz: 4d5903bca250a0f7e86ef39e4ac24673bfcfb2794df7f51602e2554e56085c8595ebe6fa11e4d1fa325a0afa0069b789c4869a034fc9f8c95c64c7349024770d
data/lib/spectre/git.rb CHANGED
@@ -1,179 +1,170 @@
1
- require 'open3'
2
- require 'fileutils'
3
- require 'logger'
4
- require 'spectre'
5
-
6
-
7
- module Spectre
8
- module Git
9
- class GitAccess < Spectre::DslClass
10
- def initialize cfg, logger
11
- @__logger = logger
12
- @__cfg = cfg
13
- @__repo_path = nil
14
-
15
- url(@__cfg['url'])
16
- @__cfg['branch'] = 'master' unless @__cfg['branch']
17
- end
18
-
19
- def url git_url
20
- url_match = git_url.match /^(?<scheme>http(?:s)?):\/\/(?:(?<user>[^\/:]*):(?<pass>.*)@)?(?<url>.*\/(?<name>[^\/]*)\.git)$/
21
-
22
- raise "invalid git url: '#{git_url}'" unless url_match
23
-
24
- @__cfg['url_path'] = url_match[:url]
25
- @__cfg['scheme'] = url_match[:scheme]
26
- @__cfg['username'] = url_match[:user] unless @__cfg['username']
27
- @__cfg['password'] = url_match[:pass] unless @__cfg['password']
28
- @__cfg['name'] = url_match[:name] unless @__cfg['name']
29
- @__cfg['working_dir'] = './tmp' unless @__cfg['working_dir']
30
- end
31
-
32
- def username user
33
- @__cfg['username'] = user
34
- end
35
-
36
- def password pass
37
- @__cfg['password'] = pass
38
- end
39
-
40
- def working_dir path
41
- @__cfg['working_dir'] = path if path
42
- @__cfg['working_dir']
43
- end
44
-
45
- def cert file_path
46
- @__cfg['cert'] = file_path
47
- end
48
-
49
- def branch name
50
- @__cfg['branch'] = name
51
- end
52
-
53
- def clone
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)
81
- end
82
-
83
- def add path
84
- run("git add \"#{path}\"")
85
- end
86
-
87
- def add_all
88
- run("git add --all")
89
- end
90
-
91
- def tag name, message: nil
92
- run("git tag -a -m \"#{message}\"")
93
- end
94
-
95
- def commit message
96
- run("git commit -m \"#{message}\"")
97
- end
98
-
99
- def push
100
- run("git push")
101
- end
102
-
103
- def pull
104
- run("git pull")
105
- end
106
-
107
- def pull
108
- run("git pull")
109
- end
110
-
111
- def write_file path, content
112
- full_path = File.join(@__repo_path, path)
113
-
114
- file = File.open(full_path, 'w')
115
- file.write(content)
116
- file.close
117
-
118
- full_path
119
- end
120
-
121
- def read_file path
122
- full_path = File.join(@__repo_path, path)
123
- File.read(full_path)
124
- end
125
-
126
- def cleanup
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
142
- end
143
-
144
- private
145
-
146
- def get_url
147
- cred = @__cfg['username'] ? "#{@__cfg['username']}:#{@__cfg['password']}@" : ''
148
- "#{@__cfg['scheme']}://#{cred}#{@__cfg['url_path']}"
149
- end
150
- end
151
-
152
- class << self
153
- @@cfg = {}
154
- @@logger = ::Logger.new(STDOUT)
155
- @@last_access = nil
156
-
157
- def git name = nil, &block
158
- cfg = @@cfg[name] || {}
159
-
160
- cfg['url'] = name if not cfg['url']
161
-
162
- @@last_access = GitAccess.new(cfg, @@logger) if name
163
- @@last_access.instance_eval &block
164
- end
165
- end
166
-
167
- Spectre.register do |config|
168
- @@logger = ::Logger.new config['log_file'], progname: 'spectre/git'
169
-
170
- if config.key? 'git'
171
- config['git'].each do |name, cfg|
172
- @@cfg[name] = cfg
173
- end
174
- end
175
- end
176
-
177
- Spectre.delegate :git, to: self
178
- end
179
- end
1
+ require 'open3'
2
+ require 'fileutils'
3
+ require 'logger'
4
+
5
+ module Spectre
6
+ module Git
7
+ class GitAccess
8
+ include Spectre::Delegate if defined? Spectre::Delegate
9
+
10
+ def initialize cfg, logger
11
+ @__logger = logger
12
+ @__cfg = cfg
13
+ @__repo_path = nil
14
+
15
+ url(@__cfg['url'])
16
+ @__cfg['branch'] = 'master' unless @__cfg['branch']
17
+ end
18
+
19
+ def url git_url
20
+ url_match = git_url
21
+ .match(%r{^(?<scheme>http(?:s)?)://(?:(?<user>[^/:]*):(?<pass>.*)@)?(?<url>.*/(?<name>[^/]*)\.git)$})
22
+
23
+ raise "invalid git url: '#{git_url}'" unless url_match
24
+
25
+ @__cfg['url_path'] = url_match[:url]
26
+ @__cfg['scheme'] = url_match[:scheme]
27
+ @__cfg['username'] = url_match[:user] unless @__cfg['username']
28
+ @__cfg['password'] = url_match[:pass] unless @__cfg['password']
29
+ @__cfg['name'] = url_match[:name] unless @__cfg['name']
30
+ @__cfg['working_dir'] = './tmp' unless @__cfg['working_dir']
31
+ end
32
+
33
+ def username user
34
+ @__cfg['username'] = user
35
+ end
36
+
37
+ def password pass
38
+ @__cfg['password'] = pass
39
+ end
40
+
41
+ def working_dir path
42
+ @__cfg['working_dir'] = path if path
43
+ @__cfg['working_dir']
44
+ end
45
+
46
+ def cert file_path
47
+ @__cfg['cert'] = file_path
48
+ end
49
+
50
+ def branch name
51
+ @__cfg['branch'] = name
52
+ end
53
+
54
+ def clone
55
+ @__repo_path = File.absolute_path File.join(@__cfg['working_dir'], @__cfg['name'])
56
+
57
+ if File.exist? @__repo_path
58
+ FileUtils.rm_rf(@__repo_path)
59
+ @__logger.debug("repo path '#{@__repo_path}' removed")
60
+ end
61
+
62
+ FileUtils.mkpath(@__repo_path)
63
+ @__logger.debug("repo path '#{@__repo_path}' created")
64
+
65
+ clone_cmd = ['git', 'clone']
66
+ clone_cmd << '--branch'
67
+ clone_cmd << @__cfg['branch']
68
+
69
+ if @__cfg['cert']
70
+ clone_cmd << '--config'
71
+ clone_cmd << "http.sslCAInfo=#{@__cfg['cert']}"
72
+ end
73
+
74
+ clone_cmd << build_url
75
+ clone_cmd << @__repo_path
76
+
77
+ clone_cmd = clone_cmd.join(' ')
78
+
79
+ @__logger.info(clone_cmd.gsub(%r{:([^\:\@/]*)@}, ':*****@').to_s)
80
+
81
+ run(clone_cmd, log: false)
82
+ end
83
+
84
+ def add path
85
+ run("git add \"#{path}\"")
86
+ end
87
+
88
+ def add_all
89
+ run('git add --all')
90
+ end
91
+
92
+ def tag name, message: nil
93
+ run("git tag -a -m \"#{message}\" \"#{name}\"")
94
+ end
95
+
96
+ def commit message
97
+ run("git commit -m \"#{message}\"")
98
+ end
99
+
100
+ def push
101
+ run('git push')
102
+ end
103
+
104
+ def pull
105
+ run('git pull')
106
+ end
107
+
108
+ def write_file path, content
109
+ full_path = File.join(@__repo_path, path)
110
+
111
+ file = File.open(full_path, 'w')
112
+ file.write(content)
113
+ file.close
114
+
115
+ full_path
116
+ end
117
+
118
+ def read_file path
119
+ full_path = File.join(@__repo_path, path)
120
+ File.read(full_path)
121
+ end
122
+
123
+ def cleanup
124
+ FileUtils.rm_rf(@__repo_path)
125
+ end
126
+
127
+ def run cmd, log: true
128
+ _stdin, stdout, stderr, wait_thr = Open3.popen3(cmd, chdir: @__repo_path)
129
+
130
+ @__logger.info(cmd) if log
131
+
132
+ _output = stdout.gets(nil)
133
+ stdout.close
134
+
135
+ error = stderr.gets(nil)
136
+ stderr.close
137
+
138
+ raise error unless wait_thr.value.exitstatus.zero?
139
+ end
140
+
141
+ private
142
+
143
+ def build_url
144
+ cred = @__cfg['username'] ? "#{@__cfg['username']}:#{@__cfg['password']}@" : ''
145
+ "#{@__cfg['scheme']}://#{cred}#{@__cfg['url_path']}"
146
+ end
147
+ end
148
+
149
+ class Client
150
+ include Spectre::Delegate if defined? Spectre::Delegate
151
+
152
+ def initialize config, logger
153
+ @config = config['git'] || {}
154
+ @logger = logger
155
+ @last_access = nil
156
+ end
157
+
158
+ def git(name = nil, &)
159
+ config = @config[name] || {}
160
+
161
+ config['url'] = name unless config['url']
162
+
163
+ @last_access = GitAccess.new(config, @logger) if name
164
+ @last_access.instance_eval(&)
165
+ end
166
+ end
167
+ end
168
+
169
+ Engine.register(Git::Client, :git) if defined? Engine
170
+ end
metadata CHANGED
@@ -1,46 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spectre-git
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christian Neubauer
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2021-07-30 00:00:00.000000000 Z
10
+ date: 2025-03-21 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
- name: spectre-core
13
+ name: logger
15
14
  requirement: !ruby/object:Gem::Requirement
16
15
  requirements:
17
16
  - - ">="
18
17
  - !ruby/object:Gem::Version
19
- version: 1.8.4
18
+ version: '0'
20
19
  type: :runtime
21
20
  prerelease: false
22
21
  version_requirements: !ruby/object:Gem::Requirement
23
22
  requirements:
24
23
  - - ">="
25
24
  - !ruby/object:Gem::Version
26
- version: 1.8.4
25
+ version: '0'
26
+ - !ruby/object:Gem::Dependency
27
+ name: stringio
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
27
40
  description: Adds basic git commands to the spectre framework
28
41
  email:
29
- - me@christianneubauer.de
42
+ - christian.neubauer@ionos.com
30
43
  executables: []
31
44
  extensions: []
32
45
  extra_rdoc_files: []
33
46
  files:
34
47
  - lib/spectre/git.rb
35
- homepage: https://github.com/cneubauer/spectre-git
48
+ homepage: https://github.com/ionos-spectre/spectre-git
36
49
  licenses:
37
- - MIT
50
+ - GPL-3.0-or-later
38
51
  metadata:
39
- allowed_push_host: https://rubygems.org/
40
- homepage_uri: https://github.com/cneubauer/spectre-git
41
- source_code_uri: https://github.com/cneubauer/spectre-git
42
- changelog_uri: https://github.com/cneubauer/spectre-git/blob/master/CHANGELOG.md
43
- post_install_message:
52
+ homepage_uri: https://github.com/ionos-spectre/spectre-git
53
+ source_code_uri: https://github.com/ionos-spectre/spectre-git
54
+ changelog_uri: https://github.com/ionos-spectre/spectre-git/blob/master/CHANGELOG.md
44
55
  rdoc_options: []
45
56
  require_paths:
46
57
  - lib
@@ -48,15 +59,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
48
59
  requirements:
49
60
  - - ">="
50
61
  - !ruby/object:Gem::Version
51
- version: 2.5.0
62
+ version: '3.4'
52
63
  required_rubygems_version: !ruby/object:Gem::Requirement
53
64
  requirements:
54
65
  - - ">="
55
66
  - !ruby/object:Gem::Version
56
67
  version: '0'
57
68
  requirements: []
58
- rubygems_version: 3.0.8
59
- signing_key:
69
+ rubygems_version: 3.6.6
60
70
  specification_version: 4
61
71
  summary: Git module for spectre
62
72
  test_files: []