Skip to content

Commit

Permalink
Merge pull request #420 from raafaelima/fix/github-token-required-at-…
Browse files Browse the repository at this point in the history
…github-helper

Make explicit the use of the parameter `GITHUB_TOKEN` when use `create_release`
  • Loading branch information
AliSoftware authored Nov 3, 2022
2 parents 6d474fe + 6adfe25 commit 04cfc68
Show file tree
Hide file tree
Showing 12 changed files with 324 additions and 124 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

### Breaking Changes

_None_
- Removed support for the deprecated `GHHELPER_ACCESS` in favor of `GITHUB_TOKEN` as the default environment variable to set the GitHub API token. [#420]
- The `github_token:` parameter (aka `ConfigItem`)–or using the corresponding `GITHUB_TOKEN` env var to provide it a value–is now mandatory for all Fastlane actions that use the GitHub API. [#420]
- The Fastlane action `comment_on_pr` has the parameter `access_key:` replaced by `github_token:`. [#420]

### New Features

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ def self.run(params)
UI.user_error!("Can't find any reference for key #{params[:import_key]}") if version.nil?
UI.message "Downloading #{params[:file_path]} from #{params[:repository]} at version #{version} to #{params[:download_folder]}"

Fastlane::Helper::GithubHelper.download_file_from_tag(
github_helper = Fastlane::Helper::GithubHelper.new(github_token: params[:github_token])
github_helper.download_file_from_tag(
repository: params[:repository],
tag: "#{params[:github_release_prefix]}#{version}",
file_path: params[:file_path],
Expand Down Expand Up @@ -57,6 +58,7 @@ def self.available_options
description: 'The prefix which is used in the GitHub release title',
type: String,
optional: true),
Fastlane::Helper::GithubHelper.github_token_config_item,
]
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ def self.run(params)
repository = params[:repository]
milestone_title = params[:milestone]

milestone = Fastlane::Helper::GithubHelper.get_milestone(repository, milestone_title)
github_helper = Fastlane::Helper::GithubHelper.new(github_token: params[:github_token])
milestone = github_helper.get_milestone(repository, milestone_title)

UI.user_error!("Milestone #{milestone_title} not found.") if milestone.nil?

Fastlane::Helper::GithubHelper.github_client().update_milestone(repository, milestone[:number], state: 'closed')
github_helper.update_milestone(repository: repository, number: milestone[:number], options: { state: 'closed' })
end

def self.description
Expand Down Expand Up @@ -45,6 +47,7 @@ def self.available_options
description: 'The GitHub milestone',
optional: false,
type: String),
Fastlane::Helper::GithubHelper.github_token_config_item,
]
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ class CommentOnPrAction < Action
def self.run(params)
require_relative '../../helper/github_helper'

reuse_identifier = Fastlane::Helper::GithubHelper.comment_on_pr(
github_helper = Fastlane::Helper::GithubHelper.new(github_token: params[:github_token])
reuse_identifier = github_helper.comment_on_pr(
project_slug: params[:project],
pr_number: params[:pr_number],
body: params[:body],
Expand Down Expand Up @@ -41,12 +42,7 @@ def self.details

def self.available_options
[
FastlaneCore::ConfigItem.new(
key: :access_token,
env_name: 'GITHUB_TOKEN',
description: 'The GitHub token to use for posting the comment',
type: String
),
Fastlane::Helper::GithubHelper.github_token_config_item,
FastlaneCore::ConfigItem.new(
key: :reuse_identifier,
description: 'If provided, the reuse identifier can identify an existing comment to overwrite',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@ class CreateNewMilestoneAction < Action
def self.run(params)
repository = params[:repository]

last_stone = Fastlane::Helper::GithubHelper.get_last_milestone(repository)
github_helper = Fastlane::Helper::GithubHelper.new(github_token: params[:github_token])
last_stone = github_helper.get_last_milestone(repository)
UI.message("Last detected milestone: #{last_stone[:title]} due on #{last_stone[:due_on]}.")
milestone_duedate = last_stone[:due_on]
milestone_duration = params[:milestone_duration]
newmilestone_duedate = (milestone_duedate.to_datetime.next_day(milestone_duration).to_time).utc
newmilestone_number = Fastlane::Helper::Ios::VersionHelper.calc_next_release_version(last_stone[:title])
number_of_days_from_code_freeze_to_release = params[:number_of_days_from_code_freeze_to_release]
UI.message("Next milestone: #{newmilestone_number} due on #{newmilestone_duedate}.")
Fastlane::Helper::GithubHelper.create_milestone(repository, newmilestone_number, newmilestone_duedate, milestone_duration, number_of_days_from_code_freeze_to_release, params[:need_appstore_submission])
github_helper.create_milestone(repository, newmilestone_number, newmilestone_duedate, milestone_duration, number_of_days_from_code_freeze_to_release, params[:need_appstore_submission])
end

def self.description
Expand Down Expand Up @@ -62,6 +63,7 @@ def self.available_options
optional: true,
is_string: false,
default_value: 14),
Fastlane::Helper::GithubHelper.github_token_config_item,
]
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ def self.run(params)
UI.user_error!("Can't find file #{file_path}!") unless File.exist?(file_path)
end

Fastlane::Helper::GithubHelper.create_release(
github_helper = Fastlane::Helper::GithubHelper.new(github_token: params[:github_token])
github_helper.create_release(
repository: repository,
version: version,
target: params[:target],
Expand Down Expand Up @@ -82,6 +83,7 @@ def self.available_options
optional: true,
default_value: false,
is_string: false),
Fastlane::Helper::GithubHelper.github_token_config_item,
]
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ def self.run(params)
milestone = params[:milestone]

# Get commit list
pr_list = Fastlane::Helper::GithubHelper.get_prs_for_milestone(repository, milestone)
github_helper = Fastlane::Helper::GithubHelper.new(github_token: params[:github_token])
pr_list = github_helper.get_prs_for_milestone(repository, milestone)

File.open(report_path, 'w') do |file|
pr_list.each do |data|
Expand Down Expand Up @@ -53,6 +54,7 @@ def self.available_options
description: 'The name of the milestone we want to fetch the list of PRs for (e.g.: `16.9`)',
optional: false,
is_string: true),
Fastlane::Helper::GithubHelper.github_token_config_item,
]
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ class RemovebranchprotectionAction < Action
def self.run(params)
repository = params[:repository]
branch_name = params[:branch]
branch_prot = {}

branch_prot = {}
branch_url = "https://api.github.com/repos/#{repository}/branches/#{branch_name}"
branch_prot[:restrictions] = { url: "#{branch_url}/protection/restrictions", users_url: "#{branch_url}/protection/restrictions/users", teams_url: "#{branch_url}/protection/restrictions/teams", users: [], teams: [] }
branch_prot[:enforce_admins] = nil
branch_prot[:required_pull_request_reviews] = { url: "#{branch_url}/protection/required_pull_request_reviews", dismiss_stale_reviews: false, require_code_owner_reviews: false }

Fastlane::Helper::GithubHelper.github_client().unprotect_branch(repository, branch_name, branch_prot)
github_helper = Fastlane::Helper::GithubHelper.new(github_token: params[:github_token])
github_helper.remove_branch_protection(repository: repository, branch: branch_name, options: branch_prot)
end

def self.description
Expand Down Expand Up @@ -46,6 +47,7 @@ def self.available_options
description: 'The branch to unprotect',
optional: false,
type: String),
Fastlane::Helper::GithubHelper.github_token_config_item,
]
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ class SetbranchprotectionAction < Action
def self.run(params)
repository = params[:repository]
branch_name = params[:branch]
branch_prot = {}

branch_prot = {}
branch_url = "https://api.github.com/repos/#{repository}/branches/#{branch_name}"
branch_prot[:restrictions] = { url: "#{branch_url}/protection/restrictions", users_url: "#{branch_url}/protection/restrictions/users", teams_url: "#{branch_url}/protection/restrictions/teams", users: [], teams: [] }
branch_prot[:enforce_admins] = nil
branch_prot[:required_pull_request_reviews] = { url: "#{branch_url}/protection/required_pull_request_reviews", dismiss_stale_reviews: false, require_code_owner_reviews: false }
Fastlane::Helper::GithubHelper.github_client().protect_branch(repository, branch_name, branch_prot)

github_helper = Fastlane::Helper::GithubHelper.new(github_token: params[:github_token])
github_helper.set_branch_protection(repository: repository, branch: branch_name, options: branch_prot)
end

def self.description
Expand Down Expand Up @@ -45,6 +47,7 @@ def self.available_options
description: 'The branch to protect',
optional: false,
type: String),
Fastlane::Helper::GithubHelper.github_token_config_item,
]
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ def self.run(params)
milestone_title = params[:milestone]
freeze = params[:freeze]

milestone = Fastlane::Helper::GithubHelper.get_milestone(repository, milestone_title)
github_helper = Fastlane::Helper::GithubHelper.new(github_token: params[:github_token])
milestone = github_helper.get_milestone(repository, milestone_title)

UI.user_error!("Milestone #{milestone_title} not found.") if milestone.nil?

mile_title = milestone[:title]
Expand All @@ -27,7 +29,7 @@ def self.run(params)
end

UI.message("New milestone: #{mile_title}")
Fastlane::Helper::GithubHelper.github_client().update_milestone(repository, milestone[:number], title: mile_title)
github_helper.update_milestone(repository: repository, number: milestone[:number], options: { title: mile_title })
end

def self.is_frozen(milestone)
Expand Down Expand Up @@ -70,6 +72,7 @@ def self.available_options
optional: false,
default_value: true,
is_string: false),
Fastlane::Helper::GithubHelper.github_token_config_item,
]
end

Expand Down
Loading

0 comments on commit 04cfc68

Please sign in to comment.