From 1542e020bf78b97f8b3c3a6ac410ae4a078f582f Mon Sep 17 00:00:00 2001 From: Rafael Lima Date: Thu, 3 Nov 2022 14:34:03 +0000 Subject: [PATCH 1/3] GithubHelper: Add Hash-Conversion operator to update_milestone The change was done to make the method signature cleaner to call --- .../wpmreleasetoolkit/actions/common/close_milestone_action.rb | 2 +- .../wpmreleasetoolkit/actions/common/setfrozentag_action.rb | 2 +- lib/fastlane/plugin/wpmreleasetoolkit/helper/github_helper.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/close_milestone_action.rb b/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/close_milestone_action.rb index f85d18dcd..72cbecfa6 100644 --- a/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/close_milestone_action.rb +++ b/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/close_milestone_action.rb @@ -15,7 +15,7 @@ def self.run(params) UI.user_error!("Milestone #{milestone_title} not found.") if milestone.nil? - github_helper.update_milestone(repository: repository, number: milestone[:number], options: { state: 'closed' }) + github_helper.update_milestone(repository: repository, number: milestone[:number], state: 'closed') end def self.description diff --git a/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/setfrozentag_action.rb b/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/setfrozentag_action.rb index 780ffede1..55d6f8a89 100644 --- a/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/setfrozentag_action.rb +++ b/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/setfrozentag_action.rb @@ -29,7 +29,7 @@ def self.run(params) end UI.message("New milestone: #{mile_title}") - github_helper.update_milestone(repository: repository, number: milestone[:number], options: { title: mile_title }) + github_helper.update_milestone(repository: repository, number: milestone[:number], title: mile_title) end def self.is_frozen(milestone) diff --git a/lib/fastlane/plugin/wpmreleasetoolkit/helper/github_helper.rb b/lib/fastlane/plugin/wpmreleasetoolkit/helper/github_helper.rb index e8d35e754..d7c2f951e 100644 --- a/lib/fastlane/plugin/wpmreleasetoolkit/helper/github_helper.rb +++ b/lib/fastlane/plugin/wpmreleasetoolkit/helper/github_helper.rb @@ -189,7 +189,7 @@ def comment_on_pr(project_slug:, pr_number:, body:, reuse_identifier: SecureRand # @return [Milestone] A single milestone object # @see http://developer.github.com/v3/issues/milestones/#update-a-milestone # - def update_milestone(repository:, number:, options:) + def update_milestone(repository:, number:, **options) client.update_milestone(repository, number, options) end From 9369d0d6ff7e695854c0905f639142dd0f5ed60f Mon Sep 17 00:00:00 2001 From: Rafael Lima Date: Thu, 3 Nov 2022 14:34:16 +0000 Subject: [PATCH 2/3] GithubHelper: Add Hash-Conversion operator to remove_branch_protection The change was done to make the method signature cleaner to use the options parameter as named parameters --- .../common/removebranchprotection_action.rb | 14 +++++++++----- .../wpmreleasetoolkit/helper/github_helper.rb | 2 +- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/removebranchprotection_action.rb b/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/removebranchprotection_action.rb index 9d33e5083..bfc01e61b 100644 --- a/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/removebranchprotection_action.rb +++ b/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/removebranchprotection_action.rb @@ -8,14 +8,18 @@ def self.run(params) repository = params[:repository] branch_name = params[:branch] - 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 } + restrictions = { url: "#{branch_url}/protection/restrictions", users_url: "#{branch_url}/protection/restrictions/users", teams_url: "#{branch_url}/protection/restrictions/teams", users: [], teams: [] } + required_pull_request_reviews = { url: "#{branch_url}/protection/required_pull_request_reviews", dismiss_stale_reviews: false, require_code_owner_reviews: false } github_helper = Fastlane::Helper::GithubHelper.new(github_token: params[:github_token]) - github_helper.remove_branch_protection(repository: repository, branch: branch_name, options: branch_prot) + github_helper.remove_branch_protection( + repository: repository, + branch: branch_name, + restrictions: restrictions, + enforce_admins: nil, + required_pull_request_reviews: required_pull_request_reviews + ) end def self.description diff --git a/lib/fastlane/plugin/wpmreleasetoolkit/helper/github_helper.rb b/lib/fastlane/plugin/wpmreleasetoolkit/helper/github_helper.rb index d7c2f951e..6df40bf34 100644 --- a/lib/fastlane/plugin/wpmreleasetoolkit/helper/github_helper.rb +++ b/lib/fastlane/plugin/wpmreleasetoolkit/helper/github_helper.rb @@ -200,7 +200,7 @@ def update_milestone(repository:, number:, **options) # @param [Hash] options A customizable set of options. # @see https://docs.github.com/en/rest/branches/branch-protection#update-branch-protection # - def remove_branch_protection(repository:, branch:, options:) + def remove_branch_protection(repository:, branch:, **options) client.unprotect_branch(repository, branch, options) end From 48dc856563d5d245dbcddab003f61840999f7cc2 Mon Sep 17 00:00:00 2001 From: Rafael Lima Date: Thu, 3 Nov 2022 14:34:31 +0000 Subject: [PATCH 3/3] GithubHelper: Add Hash-Conversion operator to set_branch_protection The change was done to make the method signature cleaner to use the options parameter as named parameters --- .../actions/common/setbranchprotection_action.rb | 14 +++++++++----- .../wpmreleasetoolkit/helper/github_helper.rb | 2 +- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/setbranchprotection_action.rb b/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/setbranchprotection_action.rb index 41a11e5bd..a4acfdc66 100644 --- a/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/setbranchprotection_action.rb +++ b/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/setbranchprotection_action.rb @@ -8,14 +8,18 @@ def self.run(params) repository = params[:repository] branch_name = params[:branch] - 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 } + restrictions = { url: "#{branch_url}/protection/restrictions", users_url: "#{branch_url}/protection/restrictions/users", teams_url: "#{branch_url}/protection/restrictions/teams", users: [], teams: [] } + required_pull_request_reviews = { url: "#{branch_url}/protection/required_pull_request_reviews", dismiss_stale_reviews: false, require_code_owner_reviews: false } github_helper = Fastlane::Helper::GithubHelper.new(github_token: params[:github_token]) - github_helper.set_branch_protection(repository: repository, branch: branch_name, options: branch_prot) + github_helper.set_branch_protection( + repository: repository, + branch: branch_name, + restrictions: restrictions, + enforce_admins: nil, + required_pull_request_reviews: required_pull_request_reviews + ) end def self.description diff --git a/lib/fastlane/plugin/wpmreleasetoolkit/helper/github_helper.rb b/lib/fastlane/plugin/wpmreleasetoolkit/helper/github_helper.rb index 6df40bf34..74dab2f35 100644 --- a/lib/fastlane/plugin/wpmreleasetoolkit/helper/github_helper.rb +++ b/lib/fastlane/plugin/wpmreleasetoolkit/helper/github_helper.rb @@ -211,7 +211,7 @@ def remove_branch_protection(repository:, branch:, **options) # @param options [Hash] A customizable set of options. # @see https://docs.github.com/en/rest/branches/branch-protection#update-branch-protection # - def set_branch_protection(repository:, branch:, options:) + def set_branch_protection(repository:, branch:, **options) client.protect_branch(repository, branch, options) end