Class: DangerMailmap::SuggestionFormatter
- Inherits:
-
Object
- Object
- DangerMailmap::SuggestionFormatter
- Defined in:
- lib/danger_mailmap/suggestion_formatter.rb
Overview
A class to format suggestion to fix warnings.
Instance Method Summary collapse
-
#filter_branch_script(emails) ⇒ Object
rubocop:disable Metrics/MethodLength.
-
#initialize(request_source, git_working_dir) ⇒ SuggestionFormatter
constructor
A new instance of SuggestionFormatter.
- #mailmap_script(path, emails) ⇒ Object
- #suggestion(path, emails) ⇒ Object
Constructor Details
#initialize(request_source, git_working_dir) ⇒ SuggestionFormatter
Returns a new instance of SuggestionFormatter.
13 14 15 16 |
# File 'lib/danger_mailmap/suggestion_formatter.rb', line 13 def initialize(request_source, git_working_dir) @request_source = request_source @git_working_dir = git_working_dir end |
Instance Method Details
#filter_branch_script(emails) ⇒ Object
rubocop:disable Metrics/MethodLength
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/danger_mailmap/suggestion_formatter.rb', line 56 def filter_branch_script(emails) # rubocop:disable Metrics/MethodLength base = @request_source.base_branch || '"${BASE_COMMIT_HERE}"' head = @request_source.head_branch || 'HEAD' script = +"git filter-branch --env-filter '\n" emails.each do |email| script << indent(4, <<~SHELL) if [ "$GIT_AUTHOR_EMAIL" = "#{email}" ]; then GIT_AUTHOR_EMAIL="[email protected]" GIT_AUTHOR_NAME="Correct Name" fi if [ "$GIT_COMMITTER_EMAIL" = "#{email}" ]; then GIT_COMMITTER_EMAIL="[email protected]" GIT_COMMITTER_NAME="Correct Name" fi SHELL end script << "' --tag-name-filter cat #{base}...#{head}" end |
#mailmap_script(path, emails) ⇒ Object
51 52 53 54 |
# File 'lib/danger_mailmap/suggestion_formatter.rb', line 51 def mailmap_script(path, emails) path = git_relative_path(path) emails.map { |email| "echo 'Correct Name <#{email}>' >> #{path}" }.join("\n") end |
#suggestion(path, emails) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/danger_mailmap/suggestion_formatter.rb', line 18 def suggestion(path, emails) <<~MARKDOWN <blockquote> <details><summary>If it is the first time for you to contribute to this repository, add your name and email to mailmap.</summary> ```sh #{mailmap_script(path, emails)} ``` </details> <details><summary>If you want to use another name and email, rewrite commits and push them.</summary> ```sh #{filter_branch_script(emails)} ``` </details> <details><summary>If you did not tell your name and email to Git, configure Git.</summary> ```sh git config --global user.email '[email protected]' git config --global user.name 'Correct Name' ``` </details> Visit [#{HOW_TO_FIX_URL}](#{HOW_TO_FIX_URL}) for more information. </blockquote> MARKDOWN end |