From 4a248d9e505f0fee4101dbd6aac0c0388c938684 Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Wed, 25 Sep 2024 12:07:17 +1000 Subject: [PATCH 1/2] Add a `:git_graph_type` parameter to the backmerge PR action --- ...e_release_backmerge_pull_request_action.rb | 45 ++++++++++++++----- 1 file changed, 35 insertions(+), 10 deletions(-) diff --git a/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/create_release_backmerge_pull_request_action.rb b/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/create_release_backmerge_pull_request_action.rb index da2cd6a2a..aa2300fe6 100644 --- a/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/create_release_backmerge_pull_request_action.rb +++ b/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/create_release_backmerge_pull_request_action.rb @@ -6,6 +6,9 @@ module Actions class CreateReleaseBackmergePullRequestAction < Action DEFAULT_BRANCH = 'trunk'.freeze + GIT_GRAPH_TYPES = %i[mermaid ascii both none].freeze + GIT_GRAPH_TYPES_STRING = GIT_GRAPH_TYPES.map { |t| ":#{t}" }.join(', ').freeze + def self.run(params) token = params[:github_token] repository = params[:repository] @@ -48,7 +51,8 @@ def self.run(params) milestone: target_milestone&.number, reviewers: reviewers, team_reviewers: team_reviewers, - intermediate_branch_created_callback: intermediate_branch_created_callback + intermediate_branch_created_callback: intermediate_branch_created_callback, + git_graph_type: params[:git_graph_type] ) end.compact end @@ -88,7 +92,7 @@ def self.determine_target_branches(source_release_version:, default_branch:) # # @return [String] The URL of the created Pull Request, or `nil` if no PR was created. # - def self.create_backmerge_pr(token:, repository:, title:, head_branch:, base_branch:, labels:, milestone:, reviewers:, team_reviewers:, intermediate_branch_created_callback:) + def self.create_backmerge_pr(token:, repository:, title:, head_branch:, base_branch:, labels:, milestone:, reviewers:, team_reviewers:, intermediate_branch_created_callback:, git_graph_type:) intermediate_branch = "merge/#{head_branch.gsub('/', '-')}-into-#{base_branch.gsub('/', '-')}" if Fastlane::Helper::GitHelper.branch_exists_on_remote?(branch_name: intermediate_branch) @@ -149,19 +153,32 @@ def self.create_backmerge_pr(token:, repository:, title:, head_branch:, base_bra ``` GRAPH + git_graph = case git_graph_type + when :both + <<~GRAPH + #{meramid_git_graph} + +
+ Expand to see an ASCII representation of the Git graph above + + #{ascii_git_graph} + GRAPH + when :mermaid + meramid_git_graph + when :ascii + ascii_git_graph + when :none + '' + else + UI.user_error!("Unsupported Git graph type '#{params[:git_graph_type]}'") + end + pr_body = <<~BODY Merging `#{head_branch}` into `#{base_branch}`. Via intermediate branch `#{intermediate_branch}`, to help fix conflicts if any: - #{meramid_git_graph} - -
- Expand to see an ASCII representation of the Git graph above - - #{ascii_git_graph} - -
+ #{git_graph} BODY other_action.create_pull_request( @@ -244,6 +261,14 @@ def self.available_options description: 'Callback to allow for the caller to perform operations on the intermediate branch before pushing. The call back receives two parameters: the base (target) branch for the PR and the intermediate branch name', optional: true, type: Proc), + FastlaneCore::ConfigItem.new(key: :git_graph_type, + description: "The type of Git graph to show. Possible values: #{GIT_GRAPH_TYPES_STRING}", + optional: true, + type: Symbol, + default_value: :both, + verify_block: proc do |value| + UI.user_error!("Unsupported Git graph type '#{value}'. Supported values are: #{GIT_GRAPH_TYPES_STRING}.") unless GIT_GRAPH_TYPES.include?(value) + end), Fastlane::Helper::GithubHelper.github_token_config_item, ] end From f8dcf1b6d878b72dd45fe915f8d16edd3f1a37a6 Mon Sep 17 00:00:00 2001 From: Ian Maia Date: Wed, 2 Oct 2024 17:56:26 +0200 Subject: [PATCH 2/2] Disable Metrics/ParameterLists for `create_backmerge_pr` method --- .../common/create_release_backmerge_pull_request_action.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/create_release_backmerge_pull_request_action.rb b/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/create_release_backmerge_pull_request_action.rb index aa2300fe6..0b8ce6c19 100644 --- a/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/create_release_backmerge_pull_request_action.rb +++ b/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/create_release_backmerge_pull_request_action.rb @@ -92,7 +92,7 @@ def self.determine_target_branches(source_release_version:, default_branch:) # # @return [String] The URL of the created Pull Request, or `nil` if no PR was created. # - def self.create_backmerge_pr(token:, repository:, title:, head_branch:, base_branch:, labels:, milestone:, reviewers:, team_reviewers:, intermediate_branch_created_callback:, git_graph_type:) + def self.create_backmerge_pr(token:, repository:, title:, head_branch:, base_branch:, labels:, milestone:, reviewers:, team_reviewers:, intermediate_branch_created_callback:, git_graph_type:) # rubocop:disable Metrics/ParameterLists intermediate_branch = "merge/#{head_branch.gsub('/', '-')}-into-#{base_branch.gsub('/', '-')}" if Fastlane::Helper::GitHelper.branch_exists_on_remote?(branch_name: intermediate_branch)