Class: DPL::Provider::Releases
Instance Attribute Summary
#context, #options
Instance Method Summary
collapse
#cleanup, context, #create_key, #deploy, #error, experimental, #initialize, #log, new, npm_g, #option, pip, requires, #run, #setup_git_credentials, #setup_git_ssh, #sha, shell, #uncleanup
Constructor Details
This class inherits a constructor from DPL::Provider
Instance Method Details
#api ⇒ Object
13
14
15
16
17
18
19
|
# File 'lib/dpl/provider/releases.rb', line 13
def api
if options[:user] and options[:password]
@api ||= Octokit::Client.new(:login => options[:user], :password => options[:password])
else
@api ||= Octokit::Client.new(:access_token => option(:api_key))
end
end
|
#check_app ⇒ Object
37
38
39
40
|
# File 'lib/dpl/provider/releases.rb', line 37
def check_app
log "Deploying to repo: #{slug}"
log "Current tag is: #{get_tag}"
end
|
#check_auth ⇒ Object
46
47
48
49
50
51
52
53
54
|
# File 'lib/dpl/provider/releases.rb', line 46
def check_auth
setup_auth
unless api.scopes.include? 'public_repo' or api.scopes.include? 'repo'
raise Error, "Dpl does not have permission to upload assets. Make sure your token contains the repo or public_repo scope."
end
log "Logged in as #{user.name}"
end
|
#get_tag ⇒ Object
9
10
11
|
# File 'lib/dpl/provider/releases.rb', line 9
def get_tag
`git describe --tags --exact-match 2>/dev/null`.chomp
end
|
#needs_key? ⇒ Boolean
33
34
35
|
# File 'lib/dpl/provider/releases.rb', line 33
def needs_key?
false
end
|
#push_app ⇒ Object
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
# File 'lib/dpl/provider/releases.rb', line 56
def push_app
tag_matched = false
release_url = nil
releases.each do |release|
if release.tag_name == get_tag
release_url = release.rels[:self].href
tag_matched = true
end
end
if tag_matched == false
release_url = api.create_release(slug, get_tag).rels[:self].href
end
Array(options[:file]).each do |file|
already_exists = false
filename = Pathname.new(file).basename.to_s
api.release(release_url).rels[:assets].get.data.each do |existing_file|
if existing_file.name == filename
already_exists = true
end
end
if already_exists
log "#{filename} already exists, skipping."
else
api.upload_asset(release_url, file, {:name => filename, :content_type => MIME::Types.type_for(file).first.to_s})
end
end
end
|
#releases ⇒ Object
25
26
27
|
# File 'lib/dpl/provider/releases.rb', line 25
def releases
@releases ||= api.releases(slug)
end
|
#setup_auth ⇒ Object
42
43
44
|
# File 'lib/dpl/provider/releases.rb', line 42
def setup_auth
user.login
end
|
#slug ⇒ Object
21
22
23
|
# File 'lib/dpl/provider/releases.rb', line 21
def slug
options.fetch(:repo) { ENV['TRAVIS_REPO_SLUG'] }
end
|
#user ⇒ Object
29
30
31
|
# File 'lib/dpl/provider/releases.rb', line 29
def user
user ||= api.user
end
|