From ab139b3e96402d52b4e8cc9a56382ce8d422bfed Mon Sep 17 00:00:00 2001 From: Keenan Brock Date: Thu, 9 Nov 2023 08:59:02 -0500 Subject: [PATCH] No longer close issues We still want to mark issues as stale. And we want to do it every 3 months But we no longer want to close them after an additional 3 months. Instead, we will comment over and over --- app/workers/stale_issue_marker.rb | 37 +++---------------------- spec/workers/stale_issue_marker_spec.rb | 16 ++--------- 2 files changed, 7 insertions(+), 46 deletions(-) diff --git a/app/workers/stale_issue_marker.rb b/app/workers/stale_issue_marker.rb index 20d9cbd1..06d8422c 100644 --- a/app/workers/stale_issue_marker.rb +++ b/app/workers/stale_issue_marker.rb @@ -29,13 +29,12 @@ def pinned_labels # Triage logic: # - # - Stale after 3 month of no activity - # - Close after stale and inactive for 3 more months - # - Stale and unmergeable should be closed (assume abandoned, can still be re-opened) + # After 3 month of no activity: + # - add stale tag (if it is no there) + # - add comment # def process_stale_issues handle_newly_stale_issues - handle_stale_and_unmergable_prs end def handle_newly_stale_issues @@ -44,23 +43,10 @@ def handle_newly_stale_issues query << unpinned_query_filter GithubService.search_issues(query, SEARCH_SORTING).each do |issue| - if issue.stale? || issue.unmergeable? - comment_and_close(issue) - else - comment_as_stale(issue) - end + comment_as_stale(issue) end end - def handle_stale_and_unmergable_prs - query = "is:open archived:false is:pr" - query << %( label:"#{stale_label}" label:"#{unmergeable_label}") - query << enabled_repos_query_filter - query << unpinned_query_filter - - GithubService.search_issues(query, SEARCH_SORTING).each { |issue| comment_and_close(issue) } - end - def stale_date @stale_date ||= 3.months.ago end @@ -115,19 +101,4 @@ def comment_as_stale(issue) logger.info("[#{Time.now.utc}] - Marking issue #{issue.fq_repo_name}##{issue.number} as stale") issue.add_comment(message) end - - def comment_and_close(issue) - mark_as_stale(issue) - - message = "This #{issue.type} has been automatically closed because it " \ - "has not been updated for at least 3 months.\n\n" - message << "Feel free to reopen this #{issue.type} if " - message << "these changes are still valid.\n\n" if issue.pull_request? - message << "this issue is still valid.\n\n" unless issue.pull_request? - message << COMMENT_FOOTER - - logger.info("[#{Time.now.utc}] - Closing stale #{issue.type} #{issue.fq_repo_name}##{issue.number}") - GithubService.close_issue(issue.fq_repo_name, issue.number) - issue.add_comment(message) - end end diff --git a/spec/workers/stale_issue_marker_spec.rb b/spec/workers/stale_issue_marker_spec.rb index 9c510da8..5f25404e 100644 --- a/spec/workers/stale_issue_marker_spec.rb +++ b/spec/workers/stale_issue_marker_spec.rb @@ -65,7 +65,6 @@ def labels(label_names) let(:all_issues) { issues + [stale_and_unmergable_pr] } let(:search_query) { "#{issue_filter} #{update_filter} #{repo_filter} #{pinned_filter}" } - let(:unmergeable_query) { "#{issue_filter} is:pr #{labels_filter} #{repo_filter} #{pinned_filter}" } let(:issue_filter) { "is:open archived:false" } let(:update_filter) { "updated:<#{stale_date.strftime('%Y-%m-%d')}" } let(:repo_filter) { %(repo:"#{fq_repo_name}") } @@ -77,10 +76,7 @@ def labels(label_names) allow(subject).to receive(:stale_date).and_return(stale_date) allow(GithubService).to receive(:search_issues) .with(search_query, :sort => :updated, :direction => :asc) - .and_return(issues) - allow(GithubService).to receive(:search_issues) - .with(unmergeable_query, :sort => :updated, :direction => :asc) - .and_return([stale_and_unmergable_pr]) + .and_return(all_issues) allow(GithubService).to receive(:valid_label?).with(fq_repo_name, "stale").and_return(true) allow(Sidekiq).to receive(:logger).and_return(double(:info => nil)) allow(subject).to receive(:first_unique_worker?).and_return(true) @@ -90,7 +86,7 @@ def labels(label_names) subject.perform end - it "closes stale PRs and marks stale issues, respecting pins and commenting accordingly" do + it "marks stale issues, respecting pins and commenting accordingly" do all_issues.each do |issue| if [already_stale_issue, stale_and_unmergable_pr].include?(issue) expect(issue).to_not receive(:add_labels) @@ -98,13 +94,7 @@ def labels(label_names) expect(issue).to receive(:add_labels).with(["stale"]) end - if [already_stale_issue, stale_and_unmergable_pr, old_unmergable_pr].include?(issue) - expect(issue).to receive(:add_comment).with(/This (pull request|issue).*closed/) - expect(GithubService).to receive(:close_issue).with(fq_repo_name, issue.number) - else - expect(issue).to receive(:add_comment).with(/This (pull request|issue).*marked as stale/) - expect(GithubService).to_not receive(:close_issue).with(issue.number) - end + expect(issue).to receive(:add_comment).with(/This (pull request|issue).*marked as stale/) end end end