Skip to content

Commit 04cfc68

Browse files
authored
Merge pull request #420 from raafaelima/fix/github-token-required-at-github-helper
Make explicit the use of the parameter `GITHUB_TOKEN` when use `create_release`
2 parents 6d474fe + 6adfe25 commit 04cfc68

12 files changed

+324
-124
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66

77
### Breaking Changes
88

9-
_None_
9+
- Removed support for the deprecated `GHHELPER_ACCESS` in favor of `GITHUB_TOKEN` as the default environment variable to set the GitHub API token. [#420]
10+
- 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]
11+
- The Fastlane action `comment_on_pr` has the parameter `access_key:` replaced by `github_token:`. [#420]
1012

1113
### New Features
1214

lib/fastlane/plugin/wpmreleasetoolkit/actions/android/android_download_file_by_version.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ def self.run(params)
99
UI.user_error!("Can't find any reference for key #{params[:import_key]}") if version.nil?
1010
UI.message "Downloading #{params[:file_path]} from #{params[:repository]} at version #{version} to #{params[:download_folder]}"
1111

12-
Fastlane::Helper::GithubHelper.download_file_from_tag(
12+
github_helper = Fastlane::Helper::GithubHelper.new(github_token: params[:github_token])
13+
github_helper.download_file_from_tag(
1314
repository: params[:repository],
1415
tag: "#{params[:github_release_prefix]}#{version}",
1516
file_path: params[:file_path],
@@ -57,6 +58,7 @@ def self.available_options
5758
description: 'The prefix which is used in the GitHub release title',
5859
type: String,
5960
optional: true),
61+
Fastlane::Helper::GithubHelper.github_token_config_item,
6062
]
6163
end
6264

lib/fastlane/plugin/wpmreleasetoolkit/actions/common/close_milestone_action.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@ def self.run(params)
1010
repository = params[:repository]
1111
milestone_title = params[:milestone]
1212

13-
milestone = Fastlane::Helper::GithubHelper.get_milestone(repository, milestone_title)
13+
github_helper = Fastlane::Helper::GithubHelper.new(github_token: params[:github_token])
14+
milestone = github_helper.get_milestone(repository, milestone_title)
15+
1416
UI.user_error!("Milestone #{milestone_title} not found.") if milestone.nil?
1517

16-
Fastlane::Helper::GithubHelper.github_client().update_milestone(repository, milestone[:number], state: 'closed')
18+
github_helper.update_milestone(repository: repository, number: milestone[:number], options: { state: 'closed' })
1719
end
1820

1921
def self.description
@@ -45,6 +47,7 @@ def self.available_options
4547
description: 'The GitHub milestone',
4648
optional: false,
4749
type: String),
50+
Fastlane::Helper::GithubHelper.github_token_config_item,
4851
]
4952
end
5053

lib/fastlane/plugin/wpmreleasetoolkit/actions/common/comment_on_pr.rb

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ class CommentOnPrAction < Action
1010
def self.run(params)
1111
require_relative '../../helper/github_helper'
1212

13-
reuse_identifier = Fastlane::Helper::GithubHelper.comment_on_pr(
13+
github_helper = Fastlane::Helper::GithubHelper.new(github_token: params[:github_token])
14+
reuse_identifier = github_helper.comment_on_pr(
1415
project_slug: params[:project],
1516
pr_number: params[:pr_number],
1617
body: params[:body],
@@ -41,12 +42,7 @@ def self.details
4142

4243
def self.available_options
4344
[
44-
FastlaneCore::ConfigItem.new(
45-
key: :access_token,
46-
env_name: 'GITHUB_TOKEN',
47-
description: 'The GitHub token to use for posting the comment',
48-
type: String
49-
),
45+
Fastlane::Helper::GithubHelper.github_token_config_item,
5046
FastlaneCore::ConfigItem.new(
5147
key: :reuse_identifier,
5248
description: 'If provided, the reuse identifier can identify an existing comment to overwrite',

lib/fastlane/plugin/wpmreleasetoolkit/actions/common/create_new_milestone_action.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,16 @@ class CreateNewMilestoneAction < Action
99
def self.run(params)
1010
repository = params[:repository]
1111

12-
last_stone = Fastlane::Helper::GithubHelper.get_last_milestone(repository)
12+
github_helper = Fastlane::Helper::GithubHelper.new(github_token: params[:github_token])
13+
last_stone = github_helper.get_last_milestone(repository)
1314
UI.message("Last detected milestone: #{last_stone[:title]} due on #{last_stone[:due_on]}.")
1415
milestone_duedate = last_stone[:due_on]
1516
milestone_duration = params[:milestone_duration]
1617
newmilestone_duedate = (milestone_duedate.to_datetime.next_day(milestone_duration).to_time).utc
1718
newmilestone_number = Fastlane::Helper::Ios::VersionHelper.calc_next_release_version(last_stone[:title])
1819
number_of_days_from_code_freeze_to_release = params[:number_of_days_from_code_freeze_to_release]
1920
UI.message("Next milestone: #{newmilestone_number} due on #{newmilestone_duedate}.")
20-
Fastlane::Helper::GithubHelper.create_milestone(repository, newmilestone_number, newmilestone_duedate, milestone_duration, number_of_days_from_code_freeze_to_release, params[:need_appstore_submission])
21+
github_helper.create_milestone(repository, newmilestone_number, newmilestone_duedate, milestone_duration, number_of_days_from_code_freeze_to_release, params[:need_appstore_submission])
2122
end
2223

2324
def self.description
@@ -62,6 +63,7 @@ def self.available_options
6263
optional: true,
6364
is_string: false,
6465
default_value: 14),
66+
Fastlane::Helper::GithubHelper.github_token_config_item,
6567
]
6668
end
6769

lib/fastlane/plugin/wpmreleasetoolkit/actions/common/create_release_action.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ def self.run(params)
2121
UI.user_error!("Can't find file #{file_path}!") unless File.exist?(file_path)
2222
end
2323

24-
Fastlane::Helper::GithubHelper.create_release(
24+
github_helper = Fastlane::Helper::GithubHelper.new(github_token: params[:github_token])
25+
github_helper.create_release(
2526
repository: repository,
2627
version: version,
2728
target: params[:target],
@@ -82,6 +83,7 @@ def self.available_options
8283
optional: true,
8384
default_value: false,
8485
is_string: false),
86+
Fastlane::Helper::GithubHelper.github_token_config_item,
8587
]
8688
end
8789

lib/fastlane/plugin/wpmreleasetoolkit/actions/common/get_prs_list_action.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ def self.run(params)
1010
milestone = params[:milestone]
1111

1212
# Get commit list
13-
pr_list = Fastlane::Helper::GithubHelper.get_prs_for_milestone(repository, milestone)
13+
github_helper = Fastlane::Helper::GithubHelper.new(github_token: params[:github_token])
14+
pr_list = github_helper.get_prs_for_milestone(repository, milestone)
1415

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

lib/fastlane/plugin/wpmreleasetoolkit/actions/common/removebranchprotection_action.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@ class RemovebranchprotectionAction < Action
77
def self.run(params)
88
repository = params[:repository]
99
branch_name = params[:branch]
10-
branch_prot = {}
1110

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

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

2021
def self.description
@@ -46,6 +47,7 @@ def self.available_options
4647
description: 'The branch to unprotect',
4748
optional: false,
4849
type: String),
50+
Fastlane::Helper::GithubHelper.github_token_config_item,
4951
]
5052
end
5153

lib/fastlane/plugin/wpmreleasetoolkit/actions/common/setbranchprotection_action.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@ class SetbranchprotectionAction < Action
77
def self.run(params)
88
repository = params[:repository]
99
branch_name = params[:branch]
10-
branch_prot = {}
1110

11+
branch_prot = {}
1212
branch_url = "https://api.github.com/repos/#{repository}/branches/#{branch_name}"
1313
branch_prot[:restrictions] = { url: "#{branch_url}/protection/restrictions", users_url: "#{branch_url}/protection/restrictions/users", teams_url: "#{branch_url}/protection/restrictions/teams", users: [], teams: [] }
1414
branch_prot[:enforce_admins] = nil
1515
branch_prot[:required_pull_request_reviews] = { url: "#{branch_url}/protection/required_pull_request_reviews", dismiss_stale_reviews: false, require_code_owner_reviews: false }
16-
Fastlane::Helper::GithubHelper.github_client().protect_branch(repository, branch_name, branch_prot)
16+
17+
github_helper = Fastlane::Helper::GithubHelper.new(github_token: params[:github_token])
18+
github_helper.set_branch_protection(repository: repository, branch: branch_name, options: branch_prot)
1719
end
1820

1921
def self.description
@@ -45,6 +47,7 @@ def self.available_options
4547
description: 'The branch to protect',
4648
optional: false,
4749
type: String),
50+
Fastlane::Helper::GithubHelper.github_token_config_item,
4851
]
4952
end
5053

lib/fastlane/plugin/wpmreleasetoolkit/actions/common/setfrozentag_action.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ def self.run(params)
99
milestone_title = params[:milestone]
1010
freeze = params[:freeze]
1111

12-
milestone = Fastlane::Helper::GithubHelper.get_milestone(repository, milestone_title)
12+
github_helper = Fastlane::Helper::GithubHelper.new(github_token: params[:github_token])
13+
milestone = github_helper.get_milestone(repository, milestone_title)
14+
1315
UI.user_error!("Milestone #{milestone_title} not found.") if milestone.nil?
1416

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

2931
UI.message("New milestone: #{mile_title}")
30-
Fastlane::Helper::GithubHelper.github_client().update_milestone(repository, milestone[:number], title: mile_title)
32+
github_helper.update_milestone(repository: repository, number: milestone[:number], options: { title: mile_title })
3133
end
3234

3335
def self.is_frozen(milestone)
@@ -70,6 +72,7 @@ def self.available_options
7072
optional: false,
7173
default_value: true,
7274
is_string: false),
75+
Fastlane::Helper::GithubHelper.github_token_config_item,
7376
]
7477
end
7578

0 commit comments

Comments
 (0)