Skip to content

Instantly share code, notes, and snippets.

@gaussbeam
Created March 29, 2019 02:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gaussbeam/606fdbec2457bda2e7496adbee2dc577 to your computer and use it in GitHub Desktop.
Save gaussbeam/606fdbec2457bda2e7496adbee2dc577 to your computer and use it in GitHub Desktop.
module Fastlane
module Actions
class GetMilestoneAction < Action
def self.run(params)
UI.message("Getting milestone on GitHub (#{params[:server_url]}/#{params[:url]} | Title: #{params[:title]}, state:#{params[:state]})")
GithubApiAction.run(
server_url: params[:server_url],
api_token: params[:api_token],
http_method: "GET",
path: "repos/#{params[:url]}/milestones?state=#{params[:state]}"
) do |result|
json = result[:json]
json.each do |current|
next unless current['title'] == params[:title]
UI.message("Milestone named '#{params[:title]}'(state: #{params[:state]}) already exists.")
return current
end
end
UI.important("Milestone named '#{params[:title]}'(state: #{params[:state]}) on '#{params[:url]}' does not exist.")
return nil
end
#####################################################
# @!group Documentation
#####################################################
def self.description
"Returns milestone on GitHub"
end
def self.available_options
[
FastlaneCore::ConfigItem.new(key: :url,
env_name: "FL_GET_GITHUB_RELEASE_URL",
description: "The path to your repo, e.g. 'KrauseFx/fastlane'",
verify_block: proc do |value|
UI.user_error!("Please only pass the path, e.g. 'KrauseFx/fastlane'") if value.include?("github.com")
UI.user_error!("Please only pass the path, e.g. 'KrauseFx/fastlane'") if value.split('/').count != 2
end),
FastlaneCore::ConfigItem.new(key: :server_url,
env_name: "FL_GITHUB_RELEASE_SERVER_URL",
description: "The server url. e.g. 'https://your.github.server/api/v3' (Default: 'https://api.github.com')",
default_value: "https://api.github.com",
optional: true,
verify_block: proc do |value|
UI.user_error!("Please include the protocol in the server url, e.g. https://your.github.server") unless value.include?("//")
end),
FastlaneCore::ConfigItem.new(key: :title,
description: "Title of milestone to check"),
FastlaneCore::ConfigItem.new(key: :state,
description: "State of milestone to check(Choose from 'open', 'closed', 'all'. Default: 'open')",
default_value: "open",
verify_block: proc do |value|
states = ["open", "closed", "all"]
UI.user_error!("Invalid state") unless states.include?(value)
end),
FastlaneCore::ConfigItem.new(key: :api_token,
env_name: "FL_GITHUB_RELEASE_API_TOKEN",
sensitive: true,
description: "GitHub Personal Token (required for private repositories)")
]
end
def self.is_supported?(platform)
true # All platform
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment