Class: Dpl::Providers::Releases
Constant Summary
collapse
- URL =
'https://api.github.com/repos/%s/releases/%s'
- OCTOKIT_OPTS =
%i(
repo
name
body
prerelease
release_number
tag_name
target_commitish
)
- TIMEOUTS =
{
timeout: 180,
open_timeout: 180
}
Transliterate::APPROXIMATIONS
Dpl::Provider::FOLDS, Dpl::Provider::STAGES
Instance Attribute Summary
#key_name, #repo_name
Instance Method Summary
collapse
Methods included from Github
#normalize_filename
#transliterate
#before_finish, #before_init, #before_install, #before_prepare, #before_setup, #chmod, #cleanup, #cmd, #compact, #err, #error, #escape, examples, #expand, #finish?, #fold, #fold?, #info, #initialize, install_deps, install_deps?, #mkdir_p, move_files, #msg, #mv, #only, #open, #opt_for, #opt_key, #opts_for, #print, #quote, #read, #remove_dpl_dir, #rm_rf, #run, #run_cmd, #run_cmds, #run_stage, #run_stage?, #script, #setup_dpl_dir, #setup_git_config, #setup_git_http_user_agent, #setup_git_ssh, #setup_ssh_key, #shell, #sq, #ssh_keygen, #symbolize, #try_ssh_access, #uncleanup, unmove_files, validate_runtimes, #wait_for_ssh_access, #warn
#apt, #apt?, #cmds, #description, #env, #errs, #full_name, #gem, #gem?, #keep, #move, #msgs, #needs, #needs?, #node_js, #npm, #npm?, #opt, #path, #pip, #pip?, #python, #ruby_pre?, #ruby_version, #runtimes, #status, #strs, #summary, #user_agent, #vars
Methods included from Squiggle
#sq
Methods included from Env
included, #opts
Methods included from ConfigFile
included, #opts
#interpolate, #obfuscate, #vars
Methods included from Memoize
included
Constructor Details
This class inherits a constructor from Dpl::Provider
Instance Method Details
#api ⇒ Object
200
201
202
|
# File 'lib/dpl/providers/releases.rb', line 200
def api
@api ||= Octokit::Client.new(**creds, auto_paginate: true, connection_options: { request: TIMEOUTS })
end
|
#asset(name) ⇒ Object
180
181
182
|
# File 'lib/dpl/providers/releases.rb', line 180
def asset(name)
api.release_assets(url).detect { |asset| asset.name == name }
end
|
#content_type(file) ⇒ Object
132
133
134
135
136
|
# File 'lib/dpl/providers/releases.rb', line 132
def content_type(file)
type = MIME::Types.type_for(file).first
type ||= 'application/octet-stream'
type.to_s
end
|
#create_release ⇒ Object
153
154
155
156
157
|
# File 'lib/dpl/providers/releases.rb', line 153
def create_release
api.create_release(slug, local_tag, octokit_opts.merge(draft: true))
rescue Octokit::NotFound
error :insufficient_perm
end
|
#creds ⇒ Object
204
205
206
|
# File 'lib/dpl/providers/releases.rb', line 204
def creds
username && password ? { login: username, password: password } : { access_token: token }
end
|
#delete(asset, file) ⇒ Object
107
108
109
110
|
# File 'lib/dpl/providers/releases.rb', line 107
def delete(asset, file)
info :overwrite_existing, file
api.delete_release_asset(asset.url)
end
|
#deploy ⇒ Object
89
90
91
92
|
# File 'lib/dpl/providers/releases.rb', line 89
def deploy
upload_files
api.update_release(url, octokit_opts)
end
|
#env_tag ⇒ Object
163
164
165
166
|
# File 'lib/dpl/providers/releases.rb', line 163
def env_tag
tag = ENV['TRAVIS_TAG']
tag unless tag.to_s.empty?
end
|
#exists?(file) ⇒ Boolean
214
215
216
217
218
|
# File 'lib/dpl/providers/releases.rb', line 214
def exists?(file)
return true if File.exists?(file)
error :missing_file, file
false
end
|
#file?(file) ⇒ Boolean
220
221
222
223
224
|
# File 'lib/dpl/providers/releases.rb', line 220
def file?(file)
return true if File.file?(file)
warn :not_a_file, file
false
end
|
#files ⇒ Object
208
209
210
211
212
|
# File 'lib/dpl/providers/releases.rb', line 208
def files
files = file_glob? ? Dir.glob("{#{file.join(',')}}").uniq : file
files = files.select { |file| exists?(file) }
files.select { |file| file?(file) }
end
|
#local_tag ⇒ Object
159
160
161
|
# File 'lib/dpl/providers/releases.rb', line 159
def local_tag
env_tag || git_tag
end
|
#login ⇒ Object
83
84
85
86
87
|
# File 'lib/dpl/providers/releases.rb', line 83
def login
user.login
info :login, user.login
error :insufficient_scopes unless sufficient_scopes?
end
|
#octokit_opts ⇒ Object
112
113
114
115
116
117
|
# File 'lib/dpl/providers/releases.rb', line 112
def octokit_opts
opts = with_tag(self.opts.dup)
opts = with_target_commitish(opts)
opts = opts.select { |key, _| OCTOKIT_OPTS.include?(key) }
compact(opts.merge(body: release_notes, draft: draft?))
end
|
#release ⇒ Object
149
150
151
|
# File 'lib/dpl/providers/releases.rb', line 149
def release
releases.detect { |release| release.tag_name == local_tag }
end
|
#release_notes ⇒ Object
184
185
186
|
# File 'lib/dpl/providers/releases.rb', line 184
def release_notes
super || release_notes_file || nil
end
|
#release_notes_file ⇒ Object
188
189
190
|
# File 'lib/dpl/providers/releases.rb', line 188
def release_notes_file
release_notes_file? && exists?(super) && read(super)
end
|
#releases ⇒ Object
196
197
198
|
# File 'lib/dpl/providers/releases.rb', line 196
def releases
@releases ||= api.releases(slug)
end
|
#same_repo? ⇒ Boolean
176
177
178
|
# File 'lib/dpl/providers/releases.rb', line 176
def same_repo?
slug == repo_slug
end
|
#slug ⇒ Object
172
173
174
|
# File 'lib/dpl/providers/releases.rb', line 172
def slug
repo || repo_slug
end
|
#sufficient_scopes? ⇒ Boolean
168
169
170
|
# File 'lib/dpl/providers/releases.rb', line 168
def sufficient_scopes?
api.scopes.include?('public_repo') || api.scopes.include?('repo')
end
|
#upload_file(path) ⇒ Object
98
99
100
101
102
103
104
105
|
# File 'lib/dpl/providers/releases.rb', line 98
def upload_file(path)
file = normalize_filename(path)
asset = asset(file)
return info :skip_existing, file if asset && !overwrite?
delete(asset, file) if asset
info :upload_file, file
api.upload_asset(url, path, name: file, content_type: content_type(path))
end
|
#upload_files ⇒ Object
94
95
96
|
# File 'lib/dpl/providers/releases.rb', line 94
def upload_files
files.each { |file| upload_file(file) }
end
|
#url ⇒ Object
138
139
140
141
142
143
144
145
146
|
# File 'lib/dpl/providers/releases.rb', line 138
def url
if release_number?
URL % [slug, release_number]
elsif release
release.rels[:self].href
else
create_release.rels[:self].href
end
end
|
#user ⇒ Object
192
193
194
|
# File 'lib/dpl/providers/releases.rb', line 192
def user
@user ||= api.user
end
|
#validate ⇒ Object
77
78
79
80
81
|
# File 'lib/dpl/providers/releases.rb', line 77
def validate
info :deploy
shell :git_fetch_tags if env_tag.nil?
info :local_tag
end
|
#with_tag(opts) ⇒ Object
120
121
122
123
124
|
# File 'lib/dpl/providers/releases.rb', line 120
def with_tag(opts)
return opts if tag_name? || draft?
info :set_tag_name, local_tag
opts.merge(tag_name: local_tag)
end
|
#with_target_commitish(opts) ⇒ Object
126
127
128
129
130
|
# File 'lib/dpl/providers/releases.rb', line 126
def with_target_commitish(opts)
return opts if target_commitish? || !same_repo?
info :set_target_commitish, git_sha
opts.merge(target_commitish: git_sha)
end
|