Skip to content

Commit 48dc856

Browse files
committed
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
1 parent 9369d0d commit 48dc856

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,18 @@ def self.run(params)
88
repository = params[:repository]
99
branch_name = params[:branch]
1010

11-
branch_prot = {}
1211
branch_url = "https://api.github.com/repos/#{repository}/branches/#{branch_name}"
13-
branch_prot[:restrictions] = { url: "#{branch_url}/protection/restrictions", users_url: "#{branch_url}/protection/restrictions/users", teams_url: "#{branch_url}/protection/restrictions/teams", users: [], teams: [] }
14-
branch_prot[:enforce_admins] = nil
15-
branch_prot[:required_pull_request_reviews] = { url: "#{branch_url}/protection/required_pull_request_reviews", dismiss_stale_reviews: false, require_code_owner_reviews: false }
12+
restrictions = { url: "#{branch_url}/protection/restrictions", users_url: "#{branch_url}/protection/restrictions/users", teams_url: "#{branch_url}/protection/restrictions/teams", users: [], teams: [] }
13+
required_pull_request_reviews = { url: "#{branch_url}/protection/required_pull_request_reviews", dismiss_stale_reviews: false, require_code_owner_reviews: false }
1614

1715
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)
16+
github_helper.set_branch_protection(
17+
repository: repository,
18+
branch: branch_name,
19+
restrictions: restrictions,
20+
enforce_admins: nil,
21+
required_pull_request_reviews: required_pull_request_reviews
22+
)
1923
end
2024

2125
def self.description

lib/fastlane/plugin/wpmreleasetoolkit/helper/github_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ def remove_branch_protection(repository:, branch:, **options)
211211
# @param options [Hash] A customizable set of options.
212212
# @see https://docs.github.com/en/rest/branches/branch-protection#update-branch-protection
213213
#
214-
def set_branch_protection(repository:, branch:, options:)
214+
def set_branch_protection(repository:, branch:, **options)
215215
client.protect_branch(repository, branch, options)
216216
end
217217

0 commit comments

Comments
 (0)