Class: Fastlane::Actions::NextPrNumberAction
- Inherits:
-
Action
- Object
- Action
- Fastlane::Actions::NextPrNumberAction
- Defined in:
- lib/fastlane/plugin/stream_actions/actions/next_pr_number.rb
Documentation collapse
Class Method Summary collapse
Class Method Details
.available_options ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/fastlane/plugin/stream_actions/actions/next_pr_number.rb', line 34 def self. [ FastlaneCore::ConfigItem.new( key: :github_repo, env_name: 'GITHUB_REPOSITORY', description: 'GitHub repo name' ) ] end |
.description ⇒ Object
30 31 32 |
# File 'lib/fastlane/plugin/stream_actions/actions/next_pr_number.rb', line 30 def self.description 'Get next pull request number' end |
.is_supported?(platform) ⇒ Boolean
44 45 46 |
# File 'lib/fastlane/plugin/stream_actions/actions/next_pr_number.rb', line 44 def self.is_supported?(platform) [:ios].include?(platform) end |
.run(params) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/fastlane/plugin/stream_actions/actions/next_pr_number.rb', line 4 def self.run(params) uri = URI('https://api.github.com/repos') uri.path += "/#{params[:github_repo]}/issues" uri.query = URI.encode_www_form('state' => 'all', 'sort' => 'created', 'direction' => 'desc', 'per_page' => 1) http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true request = Net::HTTP::Get.new(uri.request_uri) token = ENV.fetch('GITHUB_TOKEN') { nil } token = ENV.fetch('GH_TOKEN') { nil } if token.to_s.empty? request['Authorization'] = "Bearer #{token}" unless token.to_s.empty? response = http.request(request) UI.user_error!("GitHub API request failed: #{response.code} #{response.} — body: #{response.body}") if response.code != '200' list = JSON.parse(response.body) max_num = list.empty? ? 0 : list[0]['number'].to_i next_num = max_num + 1 UI.important("Next pull request number: #{next_num}") next_num end |