From ca8e5a379990e2920b79d5060da8bef6a9b50474 Mon Sep 17 00:00:00 2001 From: takakura Date: Mon, 8 Jul 2024 19:20:15 +0900 Subject: [PATCH 1/3] Prevent checks from being applied when the same numbers are included in a forward match --- lib/git/pr/release/util.rb | 2 +- spec/git/pr/release_spec.rb | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/git/pr/release/util.rb b/lib/git/pr/release/util.rb index 8ae61ae..fbd58c8 100644 --- a/lib/git/pr/release/util.rb +++ b/lib/git/pr/release/util.rb @@ -157,7 +157,7 @@ def merge_pr_body(old_body, new_body) merged_body = pr_body_lines.join("\n") check_status.each { |issue_number, check_value| say "Update pull-request checkbox \##{issue_number} to #{check_value}.", :trace - merged_body.gsub! /^- \[ \] \##{issue_number}/, "- [#{check_value}] \##{issue_number}" + merged_body.gsub! /^- \[ \] \##{issue_number}\s/, "- [#{check_value}] \##{issue_number}\s" } merged_body diff --git a/spec/git/pr/release_spec.rb b/spec/git/pr/release_spec.rb index 5978eef..9b9a679 100644 --- a/spec/git/pr/release_spec.rb +++ b/spec/git/pr/release_spec.rb @@ -63,12 +63,14 @@ - [ ] #3 Provides a creating release pull-request object for template @hakobe - [ ] #4 use user who create PR if there is no assignee @hakobe - [ ] #6 Support two factor auth @ninjinkun + - [ ] #30 Extract logic from bin/git-pr-release @banyan NEW_BODY expect(actual).to eq <<~MARKDOWN.chomp - [x] #3 Provides a creating release pull-request object for template @hakobe - [ ] #4 use user who create PR if there is no assignee @hakobe - [ ] #6 Support two factor auth @ninjinkun + - [ ] #30 Extract logic from bin/git-pr-release @banyan MARKDOWN } end From 9bbb54bb5fa376e0a1d286fd7352330acfa1e297 Mon Sep 17 00:00:00 2001 From: takakura Date: Tue, 9 Jul 2024 00:00:13 +0900 Subject: [PATCH 2/3] Extract as a new test --- spec/git/pr/release_spec.rb | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/spec/git/pr/release_spec.rb b/spec/git/pr/release_spec.rb index 9b9a679..31a5a0d 100644 --- a/spec/git/pr/release_spec.rb +++ b/spec/git/pr/release_spec.rb @@ -63,14 +63,12 @@ - [ ] #3 Provides a creating release pull-request object for template @hakobe - [ ] #4 use user who create PR if there is no assignee @hakobe - [ ] #6 Support two factor auth @ninjinkun - - [ ] #30 Extract logic from bin/git-pr-release @banyan NEW_BODY expect(actual).to eq <<~MARKDOWN.chomp - [x] #3 Provides a creating release pull-request object for template @hakobe - [ ] #4 use user who create PR if there is no assignee @hakobe - [ ] #6 Support two factor auth @ninjinkun - - [ ] #30 Extract logic from bin/git-pr-release @banyan MARKDOWN } end @@ -92,6 +90,26 @@ MARKDOWN } end + context "new pr added when the same numbers are included in a forward match" do + it { + actual = merge_pr_body(<<~OLD_BODY, <<~NEW_BODY) + - [x] #3 Provides a creating release pull-request object for template @hakobe + - [ ] #6 Support two factor auth @ninjinkun + OLD_BODY + - [ ] #3 Provides a creating release pull-request object for template @hakobe + - [ ] #4 use user who create PR if there is no assignee @hakobe + - [ ] #6 Support two factor auth @ninjinkun + - [ ] #30 Extract logic from bin/git-pr-release @banyan + NEW_BODY + + expect(actual).to eq <<~MARKDOWN.chomp + - [x] #3 Provides a creating release pull-request object for template @hakobe + - [ ] #4 use user who create PR if there is no assignee @hakobe + - [ ] #6 Support two factor auth @ninjinkun + - [ ] #30 Extract logic from bin/git-pr-release @banyan + MARKDOWN + } + end end describe "#host_and_repository_and_scheme" do From 5bf18fd6df08defcd51d9de7a36b071a96d8db40 Mon Sep 17 00:00:00 2001 From: takakura <31662623+secobaka@users.noreply.github.com> Date: Tue, 9 Jul 2024 10:16:25 +0900 Subject: [PATCH 3/3] Update lib/git/pr/release/util.rb Co-authored-by: Takafumi ONAKA --- lib/git/pr/release/util.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/git/pr/release/util.rb b/lib/git/pr/release/util.rb index fbd58c8..8689715 100644 --- a/lib/git/pr/release/util.rb +++ b/lib/git/pr/release/util.rb @@ -157,7 +157,7 @@ def merge_pr_body(old_body, new_body) merged_body = pr_body_lines.join("\n") check_status.each { |issue_number, check_value| say "Update pull-request checkbox \##{issue_number} to #{check_value}.", :trace - merged_body.gsub! /^- \[ \] \##{issue_number}\s/, "- [#{check_value}] \##{issue_number}\s" + merged_body.gsub! /^- \[ \] \##{issue_number}\b/, "- [#{check_value}] \##{issue_number}" } merged_body