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
].freeze
- TIMEOUTS =
{
timeout: 180,
open_timeout: 180
}.freeze
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
206
207
208
|
# File 'lib/dpl/providers/releases.rb', line 206
def api
@api ||= Octokit::Client.new(**creds, auto_paginate: true, connection_options: { request: TIMEOUTS })
end
|
#asset(name) ⇒ Object
186
187
188
|
# File 'lib/dpl/providers/releases.rb', line 186
def asset(name)
api.release_assets(url).detect { |asset| asset.name == name }
end
|
#content_type(file) ⇒ Object
138
139
140
141
142
|
# File 'lib/dpl/providers/releases.rb', line 138
def content_type(file)
type = MIME::Types.type_for(file).first
type ||= 'application/octet-stream'
type.to_s
end
|
#create_release ⇒ Object
159
160
161
162
163
|
# File 'lib/dpl/providers/releases.rb', line 159
def create_release
api.create_release(slug, local_tag, octokit_opts.merge(draft: true))
rescue Octokit::NotFound
error :insufficient_perm
end
|
#creds ⇒ Object
210
211
212
|
# File 'lib/dpl/providers/releases.rb', line 210
def creds
username && password ? { login: username, password: } : { access_token: token }
end
|
#delete(asset, file) ⇒ Object
111
112
113
114
|
# File 'lib/dpl/providers/releases.rb', line 111
def delete(asset, file)
info :overwrite_existing, file
api.delete_release_asset(asset.url)
end
|
#deploy ⇒ Object
92
93
94
95
|
# File 'lib/dpl/providers/releases.rb', line 92
def deploy
upload_files
api.update_release(url, octokit_opts)
end
|
#env_tag ⇒ Object
169
170
171
172
|
# File 'lib/dpl/providers/releases.rb', line 169
def env_tag
tag = ENV['TRAVIS_TAG']
tag unless tag.to_s.empty?
end
|
#exists?(file) ⇒ Boolean
220
221
222
223
224
225
|
# File 'lib/dpl/providers/releases.rb', line 220
def exists?(file)
return true if File.exist?(file)
error :missing_file, file
false
end
|
#file?(file) ⇒ Boolean
227
228
229
230
231
232
|
# File 'lib/dpl/providers/releases.rb', line 227
def file?(file)
return true if File.file?(file)
warn :not_a_file, file
false
end
|
#files ⇒ Object
214
215
216
217
218
|
# File 'lib/dpl/providers/releases.rb', line 214
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
165
166
167
|
# File 'lib/dpl/providers/releases.rb', line 165
def local_tag
env_tag || git_tag
end
|
#login ⇒ Object
86
87
88
89
90
|
# File 'lib/dpl/providers/releases.rb', line 86
def login
user.login
info :login, user.login
error :insufficient_scopes unless sufficient_scopes?
end
|
#octokit_opts ⇒ Object
116
117
118
119
120
121
|
# File 'lib/dpl/providers/releases.rb', line 116
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
155
156
157
|
# File 'lib/dpl/providers/releases.rb', line 155
def release
releases.detect { |release| release.tag_name == local_tag }
end
|
#release_notes ⇒ Object
190
191
192
|
# File 'lib/dpl/providers/releases.rb', line 190
def release_notes
super || release_notes_file || nil
end
|
#release_notes_file ⇒ Object
194
195
196
|
# File 'lib/dpl/providers/releases.rb', line 194
def release_notes_file
release_notes_file? && exists?(super) && read(super)
end
|
#releases ⇒ Object
202
203
204
|
# File 'lib/dpl/providers/releases.rb', line 202
def releases
@releases ||= api.releases(slug)
end
|
#same_repo? ⇒ Boolean
182
183
184
|
# File 'lib/dpl/providers/releases.rb', line 182
def same_repo?
slug == repo_slug
end
|
#slug ⇒ Object
178
179
180
|
# File 'lib/dpl/providers/releases.rb', line 178
def slug
repo || repo_slug
end
|
#sufficient_scopes? ⇒ Boolean
174
175
176
|
# File 'lib/dpl/providers/releases.rb', line 174
def sufficient_scopes?
api.scopes.include?('public_repo') || api.scopes.include?('repo')
end
|
#upload_file(path) ⇒ Object
101
102
103
104
105
106
107
108
109
|
# File 'lib/dpl/providers/releases.rb', line 101
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
97
98
99
|
# File 'lib/dpl/providers/releases.rb', line 97
def upload_files
files.each { |file| upload_file(file) }
end
|
#url ⇒ Object
144
145
146
147
148
149
150
151
152
|
# File 'lib/dpl/providers/releases.rb', line 144
def url
if release_number?
format(URL, slug, release_number)
elsif release
release.rels[:self].href
else
create_release.rels[:self].href
end
end
|
#user ⇒ Object
198
199
200
|
# File 'lib/dpl/providers/releases.rb', line 198
def user
@user ||= api.user
end
|
#validate ⇒ Object
80
81
82
83
84
|
# File 'lib/dpl/providers/releases.rb', line 80
def validate
info :deploy
shell :git_fetch_tags if env_tag.nil?
info :local_tag
end
|
#with_tag(opts) ⇒ Object
124
125
126
127
128
129
|
# File 'lib/dpl/providers/releases.rb', line 124
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
131
132
133
134
135
136
|
# File 'lib/dpl/providers/releases.rb', line 131
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
|