Class: DPL::Provider::Releases
Instance Attribute Summary
#context, #options
Instance Method Summary
collapse
apt_get, #cleanup, #commit_msg, context, #create_key, #deploy, #detect_encoding?, #encoding_for, #error, experimental, #initialize, #log, new, npm_g, #option, pip, requires, #run, #setup_git_credentials, #setup_git_ssh, #sha, shell, #uncleanup, #user_agent, #warn
Constructor Details
This class inherits a constructor from DPL::Provider
Instance Method Details
#api ⇒ Object
26
27
28
29
30
31
32
|
# File 'lib/dpl/provider/releases.rb', line 26
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
60
61
62
63
64
65
|
# File 'lib/dpl/provider/releases.rb', line 60
def check_app
log "Deploying to repo: #{slug}"
context.shell 'git fetch --tags' if travis_tag.nil?
log "Current tag is: #{get_tag}"
end
|
#check_auth ⇒ Object
71
72
73
74
75
76
77
78
79
|
# File 'lib/dpl/provider/releases.rb', line 71
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
|
#files ⇒ Object
46
47
48
49
50
51
52
53
54
|
# File 'lib/dpl/provider/releases.rb', line 46
def files
if options[:file_glob]
Array(options[:file]).map do |glob|
Dir.glob(glob)
end.flatten
else
Array(options[:file])
end
end
|
#get_tag ⇒ Object
18
19
20
21
22
23
24
|
# File 'lib/dpl/provider/releases.rb', line 18
def get_tag
if travis_tag.nil?
@tag ||= `git describe --tags --exact-match 2>/dev/null`.chomp
else
@tag ||= travis_tag
end
end
|
#needs_key? ⇒ Boolean
56
57
58
|
# File 'lib/dpl/provider/releases.rb', line 56
def needs_key?
false
end
|
#push_app ⇒ Object
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
# File 'lib/dpl/provider/releases.rb', line 81
def push_app
tag_matched = false
release_url = nil
if options[:release_number]
tag_matched = true
release_url = "https://api.github.com/repos/" + slug + "/releases/" + options[:release_number]
else
releases.each do |release|
if release.tag_name == get_tag
release_url = release.rels[:self].href
tag_matched = true
end
end
end
if tag_matched == false
release_url = api.create_release(slug, get_tag, options).rels[:self].href
end
files.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
content_type = MIME::Types.type_for(file).first.to_s
if content_type.empty?
content_type = "application/octet-stream"
end
api.upload_asset(release_url, file, {:name => filename, :content_type => content_type})
end
end
end
|
#releases ⇒ Object
38
39
40
|
# File 'lib/dpl/provider/releases.rb', line 38
def releases
@releases ||= api.releases(slug)
end
|
#setup_auth ⇒ Object
67
68
69
|
# File 'lib/dpl/provider/releases.rb', line 67
def setup_auth
user.login
end
|
#slug ⇒ Object
34
35
36
|
# File 'lib/dpl/provider/releases.rb', line 34
def slug
options.fetch(:repo) { context.env['TRAVIS_REPO_SLUG'] }
end
|
#travis_tag ⇒ Object
9
10
11
12
13
14
15
16
|
# File 'lib/dpl/provider/releases.rb', line 9
def travis_tag
if context.env.fetch('TRAVIS_TAG','') == ''
nil
else
context.env['TRAVIS_TAG']
end
end
|
#user ⇒ Object
42
43
44
|
# File 'lib/dpl/provider/releases.rb', line 42
def user
@user ||= api.user
end
|