spectre-git 0.1.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 +7 -0
- data/lib/spectre/git.rb +129 -0
- metadata +76 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 52520773375730ae4578781f1e2b1ab55814570f670ef6bdd30d11a957b0fcb7
|
4
|
+
data.tar.gz: 28f6fb5e7f661a19cb23dcf8947e03051ebaae279d9d2b131062ae767478d7e4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 935fdcfdbfca65f4e66a67c6c47f86404a728fbb3008a2e06848ac5860ae4aa291936c34bff3c7e03f4aab23c4925dd1911bf757d57103fe94059796d199f671
|
7
|
+
data.tar.gz: 109449ee7d020524a834f18180e1f5091560a687f08c03cf8bb4cdec0760925649b4e094d348e780adbf2b9f76703dce811fedf91912cea8495f0d6bd34c8136
|
data/lib/spectre/git.rb
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require 'git'
|
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 = 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'] = url_match[:url]
|
25
|
+
@__cfg['scheme'] = url_match[:scheme]
|
26
|
+
@__cfg['username'] = url_match[:user]
|
27
|
+
@__cfg['password'] = url_match[:pass]
|
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 branch name
|
46
|
+
@__cfg['branch'] = name
|
47
|
+
end
|
48
|
+
|
49
|
+
def clone
|
50
|
+
@__cfg['working_dir'] = path = File.join(@__cfg['working_dir'], @__cfg['name'])
|
51
|
+
FileUtils.rm_rf(path)
|
52
|
+
@__repo = ::Git.clone(get_url, path, branch: @__cfg['branch'], log: @__logger)
|
53
|
+
end
|
54
|
+
|
55
|
+
def add path
|
56
|
+
@__repo.add(path)
|
57
|
+
end
|
58
|
+
|
59
|
+
def add_all
|
60
|
+
@__repo.add(all: true)
|
61
|
+
end
|
62
|
+
|
63
|
+
def add_tag name, annotate: false, message: nil
|
64
|
+
@__repo.add_tag(name, annotate: annotate, message: message)
|
65
|
+
end
|
66
|
+
|
67
|
+
def commit message
|
68
|
+
@__repo.commit(message)
|
69
|
+
end
|
70
|
+
|
71
|
+
def push
|
72
|
+
@__repo.push('origin', @__cfg['branch'])
|
73
|
+
end
|
74
|
+
|
75
|
+
def pull
|
76
|
+
@__repo.pull('origin', @__cfg['branch'])
|
77
|
+
end
|
78
|
+
|
79
|
+
def write_file path, content
|
80
|
+
full_path = File.join(@__cfg['working_dir'], path)
|
81
|
+
|
82
|
+
file = File.open(full_path, 'w')
|
83
|
+
file.write(content)
|
84
|
+
file.close
|
85
|
+
|
86
|
+
full_path
|
87
|
+
end
|
88
|
+
|
89
|
+
def read_file path
|
90
|
+
full_path = File.join(@__cfg['working_dir'], path)
|
91
|
+
File.read(full_path)
|
92
|
+
end
|
93
|
+
|
94
|
+
private
|
95
|
+
|
96
|
+
def get_url
|
97
|
+
cred = @__cfg['username'] ? "#{@__cfg['username']}:#{@__cfg['password']}@" : ''
|
98
|
+
"#{@__cfg['scheme']}://#{cred}#{@__cfg['url']}"
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
class << self
|
103
|
+
@@cfg = {}
|
104
|
+
@@logger = ::Logger.new(STDOUT)
|
105
|
+
@@last_access = nil
|
106
|
+
|
107
|
+
def git name, &block
|
108
|
+
cfg = @@cfg[name] || {}
|
109
|
+
|
110
|
+
cfg['url'] = name if not cfg['url']
|
111
|
+
|
112
|
+
@@last_access = GitAccess.new(cfg, @@logger) if name
|
113
|
+
@@last_access.instance_eval &block
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
Spectre.register do |config|
|
118
|
+
@@logger = ::Logger.new config['log_file'], progname: 'spectre/git'
|
119
|
+
|
120
|
+
if config.key? 'git'
|
121
|
+
config['git'].each do |name, cfg|
|
122
|
+
@@cfg[name] = cfg
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
Spectre.delegate :git, to: self
|
128
|
+
end
|
129
|
+
end
|
metadata
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: spectre-git
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Christian Neubauer
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-06-02 00:00:00.000000000 Z
|
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
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: spectre-core
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.8.4
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.8.4
|
41
|
+
description: Adds basic git commands to the spectre framework
|
42
|
+
email:
|
43
|
+
- me@christianneubauer.de
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- lib/spectre/git.rb
|
49
|
+
homepage: https://bitbucket.org/cneubaur/spectre-git
|
50
|
+
licenses:
|
51
|
+
- MIT
|
52
|
+
metadata:
|
53
|
+
allowed_push_host: https://rubygems.org/
|
54
|
+
homepage_uri: https://bitbucket.org/cneubaur/spectre-git
|
55
|
+
source_code_uri: https://bitbucket.org/cneubaur/spectre-git
|
56
|
+
changelog_uri: https://bitbucket.org/cneubaur/spectre-git/src/master/CHANGELOG.md
|
57
|
+
post_install_message:
|
58
|
+
rdoc_options: []
|
59
|
+
require_paths:
|
60
|
+
- lib
|
61
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: 2.5.0
|
66
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
requirements: []
|
72
|
+
rubygems_version: 3.0.8
|
73
|
+
signing_key:
|
74
|
+
specification_version: 4
|
75
|
+
summary: Git module for spectre
|
76
|
+
test_files: []
|