Last active
February 16, 2021 03:56
-
-
Save marty-suzuki/d4fe1ccb9e5e0cf9dd47c33a6b8d05a5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Pod::Spec.new do |spec| | |
module PrivateRepository | |
class Spec | |
attr_reader :version | |
attr_reader :homepage | |
attr_reader :source | |
def initialize(owner, name, version, source) | |
@version = version | |
@homepage = "https://github.com/#{owner}/#{name}" | |
@source = source | |
end | |
end | |
class SpecLoader | |
def initialize(owner, name, version, token) | |
@owner = owner | |
@name = name | |
@version = version | |
if !token.nil? && !token.empty? | |
@authorizationToken = "Authorization: token #{token}" | |
else | |
@authorizationToken = nil | |
end | |
end | |
def loadPrivateSpec | |
tagResponse = loadTag | |
assetURL = getAssetURL(tagResponse) | |
headers = ["Accept: application/octet-stream"] | |
if [email protected]? | |
headers.push(@authorizationToken) | |
end | |
source = { | |
:http => assetURL, | |
:headers => headers, | |
:type => "zip" | |
} | |
return PrivateRepository::Spec.new(@owner, @name, @version, source) | |
end | |
private | |
def loadTag | |
requestURL = "https://api.github.com/repos/#{@owner}/#{@name}/releases/tags/#{@version}" | |
cmdElements = ["curl"] | |
if [email protected]? | |
cmdElements.push("-sL") | |
cmdElements.push("-H \"#{@authorizationToken}\"") | |
else | |
cmdElements.push("-nsL") | |
end | |
cmdElements.push(requestURL) | |
cmd = cmdElements.join(" ") | |
response = %x[#{cmd}] | |
if response.nil? | |
puts "Failed Request: #{requestURL}" | |
exit! | |
else | |
return response | |
end | |
end | |
def getAssetURL(tagResponse) | |
tag_hash = JSON.load(tagResponse) | |
asset = tag_hash["assets"]&.first | |
assetURL = asset && asset["url"] | |
if assetURL.nil? | |
puts "Can't get asset URL." | |
exit! | |
else | |
return assetURL | |
end | |
end | |
end | |
end | |
privateSpecLoader = PrivateRepository::SpecLoader.new("OWNER_NAME", "REPOSITORY", ENV["VERSION"], ENV["GITHUB_ACCESS_TOKEN"]) | |
privateSpec = privateSpecLoader.loadPrivateSpec | |
spec.name = 'POD_NAME' | |
spec.version = privateSpec.version | |
spec.homepage = privateSpec.homepage | |
spec.authors = 'AUTHOR_NAME' | |
spec.license = 'LICENSE' | |
spec.summary = 'SUMMARY' | |
spec.source = privateSpec.source | |
spec.vendored_frameworks = 'FRAMEWORK_NAME' | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment