cyclid 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/cyclid/controllers/organizations/job.rb +2 -0
- data/app/cyclid/job/runner.rb +12 -3
- data/app/cyclid/plugins/source.rb +1 -1
- data/app/cyclid/plugins/source/git.rb +76 -17
- data/app/db.rb +6 -6
- data/lib/cyclid/version.rb +6 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eff5a90aeccc36b649701ec2ec970f4dc1c11e9d
|
4
|
+
data.tar.gz: 103987b807c2b04930a68d96787d64cb3864b359
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 802e3bce3fdd10e988997c282f635dda5cb81715bf6e0c6755bfc32ef1ef5491a424caa8d0cd1b03fee9befe18a5cd825e5ad053725b726070322e5d03dc19f4
|
7
|
+
data.tar.gz: 2562e60cf0591decaba4bb01ac515072695b3834cfd3c18c6589794655ea9cf0451d575bbbc006ae3f160d5a9e2fc6504ad2fa2b7c209fe528d9e54943518fda
|
@@ -233,6 +233,8 @@ module Cyclid
|
|
233
233
|
hash = {}
|
234
234
|
hash[:job_id] = job_record.id
|
235
235
|
hash[:status] = job_record.status
|
236
|
+
hash[:started] = job_record.started if job_record.started
|
237
|
+
hash[:ended] = job_record.ended if job_record.ended
|
236
238
|
|
237
239
|
return hash.to_json
|
238
240
|
end
|
data/app/cyclid/job/runner.rb
CHANGED
@@ -237,13 +237,22 @@ module Cyclid
|
|
237
237
|
# Find and create a suitable source plugin instance for each source and have it check out
|
238
238
|
# the given source using the transport.
|
239
239
|
def checkout_sources(transport, ctx, sources)
|
240
|
+
# Group each entry by type
|
241
|
+
groups = {}
|
240
242
|
sources.each do |job_source|
|
241
243
|
raise 'no type given in source definition' unless job_source.key? :type
|
242
244
|
|
243
|
-
|
244
|
-
|
245
|
+
type = job_source[:type]
|
246
|
+
groups[type] = [] unless groups.key? type
|
247
|
+
groups[type] << job_source
|
248
|
+
end
|
249
|
+
|
250
|
+
# Find the appropriate plugin for each type and pass it the list of repositories
|
251
|
+
groups.each do |group, group_sources|
|
252
|
+
plugin = Cyclid.plugins.find(group, Cyclid::API::Plugins::Source)
|
253
|
+
raise "can't find a plugin for #{group} source" if plugin.nil?
|
245
254
|
|
246
|
-
success =
|
255
|
+
success = plugin.new.checkout(transport, ctx, group_sources)
|
247
256
|
raise 'failed to check out source' unless success
|
248
257
|
end
|
249
258
|
end
|
@@ -23,41 +23,100 @@ module Cyclid
|
|
23
23
|
class Git < Source
|
24
24
|
# Run commands via. the transport to check out a given Git remote
|
25
25
|
# repository
|
26
|
-
def checkout(transport, ctx,
|
27
|
-
|
26
|
+
def checkout(transport, ctx, sources = [])
|
27
|
+
normalized_sources = normalize_and_dedup(sources)
|
28
|
+
normalized_sources.each do |source|
|
29
|
+
source.symbolize_keys!
|
28
30
|
|
29
|
-
|
30
|
-
|
31
|
+
raise 'invalid git source definition' \
|
32
|
+
unless source.key? :url
|
31
33
|
|
32
|
-
|
33
|
-
|
34
|
+
# Add any context data (which could include secrets)
|
35
|
+
source = source.interpolate(ctx)
|
34
36
|
|
35
|
-
|
37
|
+
url = URI(source[:url])
|
36
38
|
|
37
|
-
|
38
|
-
|
39
|
-
|
39
|
+
# If the source includes an OAuth token, add it to the URL as the
|
40
|
+
# username
|
41
|
+
url.user = source[:token] if source.key? :token
|
40
42
|
|
41
|
-
|
42
|
-
|
43
|
+
success = transport.exec "git clone #{url}"
|
44
|
+
return false unless success
|
45
|
+
|
46
|
+
# If a branch was given, check it out
|
47
|
+
next unless source.key? :branch
|
43
48
|
|
44
|
-
# If a branch was given, check it out
|
45
|
-
if source.key? :branch
|
46
49
|
branch = source[:branch]
|
47
50
|
|
48
51
|
match = url.path.match(%r{^.*\/(\w*)})
|
49
52
|
source_dir = "#{ctx[:workspace]}/#{match[1]}"
|
50
53
|
|
51
54
|
success = transport.exec("git fetch origin #{branch}:#{branch}", source_dir)
|
52
|
-
|
53
|
-
|
55
|
+
return false unless success
|
56
|
+
|
57
|
+
success = transport.exec("git checkout #{branch}", source_dir)
|
58
|
+
return false unless success
|
54
59
|
end
|
55
60
|
|
56
|
-
return
|
61
|
+
return true
|
57
62
|
end
|
58
63
|
|
59
64
|
# Register this plugin
|
60
65
|
register_plugin 'git'
|
66
|
+
|
67
|
+
private
|
68
|
+
|
69
|
+
# Remove any duplicate source definitions:
|
70
|
+
#
|
71
|
+
# 1. Normalize the source URLs
|
72
|
+
# 2. Find all of the definitions for a given URL and merge them
|
73
|
+
def normalize_and_dedup(sources)
|
74
|
+
normalized_sources = normalize(sources)
|
75
|
+
Cyclid.logger.debug "normalized_sources=#{normalized_sources}"
|
76
|
+
deduped_sources = dedup(normalized_sources)
|
77
|
+
Cyclid.logger.debug("deduped_sources=#{deduped_sources}")
|
78
|
+
|
79
|
+
return deduped_sources
|
80
|
+
end
|
81
|
+
|
82
|
+
# Standardise the Git URLs. Git urls can be of the form:
|
83
|
+
#
|
84
|
+
# git://github.com/user/project.git#commit-ish
|
85
|
+
# git+ssh://user@hostname:project.git#commit-ish
|
86
|
+
# git+ssh://user@hostname/project.git#commit-ish
|
87
|
+
# git+http://user@hostname/project/blah.git#commit-ish
|
88
|
+
# git+https://user@hostname/project/blah.git#commit-ish
|
89
|
+
#
|
90
|
+
# 1. We won't support SSH; HTTP(s) only
|
91
|
+
# 2. Extract the user and treat it as the token parameter
|
92
|
+
# 3. Extract the fragment and treat it as the branch parameter
|
93
|
+
#
|
94
|
+
# So:
|
95
|
+
#
|
96
|
+
# http[s]://[user@]hostname/project/blah.git[#commit-ish]
|
97
|
+
#
|
98
|
+
def normalize(sources)
|
99
|
+
normalized = sources.map do |source|
|
100
|
+
uri = URI.parse(source[:url])
|
101
|
+
next unless uri.scheme =~ /\Ahttps?\z/
|
102
|
+
|
103
|
+
s = {}
|
104
|
+
s[:url] = "#{uri.scheme}://#{uri.host}#{uri.path.gsub(/.git$/, '')}"
|
105
|
+
s[:token] = uri.user if uri.user
|
106
|
+
s[:branch] = uri.fragment if uri.fragment
|
107
|
+
source.merge(s)
|
108
|
+
end
|
109
|
+
normalized.compact
|
110
|
+
end
|
111
|
+
|
112
|
+
# Merge any duplicate source definitions
|
113
|
+
def dedup(sources)
|
114
|
+
merged = sources.map do |source|
|
115
|
+
all = sources.select { |el| el[:url] == source[:url] }
|
116
|
+
all.inject(&:merge)
|
117
|
+
end
|
118
|
+
merged.uniq
|
119
|
+
end
|
61
120
|
end
|
62
121
|
end
|
63
122
|
end
|
data/app/db.rb
CHANGED
@@ -19,20 +19,20 @@ require 'logger'
|
|
19
19
|
begin
|
20
20
|
case ENV['RACK_ENV']
|
21
21
|
when 'development'
|
22
|
-
database = if defined?
|
23
|
-
Cyclid.config.database
|
24
|
-
else
|
22
|
+
database = if defined? Rake
|
25
23
|
'sqlite3:development.db'
|
24
|
+
else
|
25
|
+
Cyclid.config.database
|
26
26
|
end
|
27
27
|
|
28
28
|
ActiveRecord::Base.establish_connection(
|
29
29
|
database
|
30
30
|
)
|
31
31
|
|
32
|
-
ActiveRecord::Base.logger = if defined?
|
33
|
-
Cyclid.logger
|
34
|
-
else
|
32
|
+
ActiveRecord::Base.logger = if defined? Rake
|
35
33
|
Logger.new(STDERR)
|
34
|
+
else
|
35
|
+
Cyclid.logger
|
36
36
|
end
|
37
37
|
when 'production'
|
38
38
|
ActiveRecord::Base.establish_connection(
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cyclid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kristian Van Der Vliet
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-10-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: oj
|
@@ -380,6 +380,7 @@ files:
|
|
380
380
|
- bin/cyclid-db-init
|
381
381
|
- db/schema.rb
|
382
382
|
- lib/cyclid/app.rb
|
383
|
+
- lib/cyclid/version.rb
|
383
384
|
homepage: https://cyclid.io
|
384
385
|
licenses:
|
385
386
|
- Apache-2.0
|