Skip to content

Commit 62eb6eb

Browse files
committed
Add api_url ConfigItem to create_release_backmerge_pull_request
1 parent 4561a32 commit 62eb6eb

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

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

+9-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class CreateReleaseBackmergePullRequestAction < Action
99
DEFAULT_BRANCH = 'trunk'
1010

1111
def self.run(params)
12+
api_url = params[:api_url]
1213
token = params[:github_token]
1314
repository = params[:repository]
1415
source_branch = params[:source_branch]
@@ -41,6 +42,7 @@ def self.run(params)
4142
Fastlane::Helper::GitHelper.checkout_and_pull(source_branch)
4243

4344
create_backmerge_pr(
45+
api_url: api_url,
4446
token: token,
4547
repository: repository,
4648
title: "Merge #{source_branch} into #{target_branch}",
@@ -76,6 +78,7 @@ def self.determine_target_branches(source_release_version:, default_branch:)
7678

7779
# Creates a backmerge pull request using the `create_pull_request` Fastlane Action.
7880
#
81+
# @param api_url [String] the GitHub API URL to use for creating the pull request
7982
# @param token [String] the GitHub token for authentication.
8083
# @param repository [String] the repository where the pull request will be created.
8184
# @param title [String] the title of the pull request.
@@ -90,7 +93,7 @@ def self.determine_target_branches(source_release_version:, default_branch:)
9093
#
9194
# @return [String] The URL of the created Pull Request, or `nil` if no PR was created.
9295
#
93-
def self.create_backmerge_pr(token:, repository:, title:, head_branch:, base_branch:, labels:, milestone:, reviewers:, team_reviewers:, intermediate_branch_created_callback:)
96+
def self.create_backmerge_pr(api_url:, token:, repository:, title:, head_branch:, base_branch:, labels:, milestone:, reviewers:, team_reviewers:, intermediate_branch_created_callback:) # rubocop:disable Metrics/ParameterLists
9497
# Do an early pre-check to see if the PR would be valid, but only if no callback (as a callback might add new commits on intermediate branch)
9598
if intermediate_branch_created_callback.nil? && !can_merge?(head_branch, into: base_branch)
9699
UI.error("Nothing to merge from #{head_branch} into #{base_branch}. Skipping PR creation.")
@@ -136,6 +139,7 @@ def self.create_backmerge_pr(token:, repository:, title:, head_branch:, base_bra
136139
BODY
137140

138141
other_action.create_pull_request(
142+
api_url: api_url,
139143
api_token: token,
140144
repo: repository,
141145
title: title,
@@ -192,6 +196,10 @@ def self.details
192196

193197
def self.available_options
194198
[
199+
FastlaneCore::ConfigItem.new(key: :api_url,
200+
description: 'The GitHub API URL to use for creating the pull request. Primarily used when working with GitHub Enterprise instances.',
201+
optional: true,
202+
type: String),
195203
FastlaneCore::ConfigItem.new(key: :repository,
196204
env_name: 'GHHELPER_REPOSITORY',
197205
description: 'The remote path of the GH repository on which we work',

spec/create_release_backmerge_pull_request_spec.rb

+28-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def stub_git_release_branches(branches)
4141
end
4242
end
4343

44-
def stub_expected_pull_requests(expected_backmerge_branches:, source_branch:, labels: [], milestone_number: nil, reviewers: nil, team_reviewers: nil, branch_exists_on_remote: false, nothing_to_merge_between: [])
44+
def stub_expected_pull_requests(expected_backmerge_branches:, source_branch:, labels: [], milestone_number: nil, reviewers: nil, team_reviewers: nil, branch_exists_on_remote: false, nothing_to_merge_between: [], api_url: nil)
4545
expected_backmerge_branches.map do |target_branch|
4646
expected_intermediate_branch = "merge/#{source_branch.gsub('/', '-')}-into-#{target_branch.gsub('/', '-')}"
4747

@@ -70,7 +70,8 @@ def stub_expected_pull_requests(expected_backmerge_branches:, source_branch:, la
7070
labels: labels,
7171
milestone: milestone_number,
7272
reviewers: reviewers,
73-
team_reviewers: team_reviewers
73+
team_reviewers: team_reviewers,
74+
api_url: api_url
7475
).and_return(mock_pr_url(target_branch))
7576

7677
expected_intermediate_branch
@@ -294,6 +295,31 @@ def stub_expected_pull_requests(expected_backmerge_branches:, source_branch:, la
294295
end
295296
end
296297

298+
context 'when providing an api_url' do
299+
it 'creates a backmerge PR using the provided api_url' do
300+
stub_git_release_branches([])
301+
302+
source_branch = 'release/30.6'
303+
api_url = 'https://github.company.com/api/v3'
304+
305+
stub_expected_pull_requests(
306+
expected_backmerge_branches: [default_branch],
307+
source_branch: source_branch,
308+
api_url: api_url
309+
)
310+
311+
result = run_described_fastlane_action(
312+
github_token: test_token,
313+
repository: test_repo,
314+
source_branch: source_branch,
315+
default_branch: default_branch,
316+
api_url: api_url
317+
)
318+
319+
expect(result).to eq([mock_pr_url(default_branch)])
320+
end
321+
end
322+
297323
context 'when there is nothing to merge' do
298324
context 'when no callback is provided' do
299325
it 'detects it should not create a pull request before even creating the intermediate branch' do

0 commit comments

Comments
 (0)