Skip to content

Commit

Permalink
No longer close issues
Browse files Browse the repository at this point in the history
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
  • Loading branch information
kbrock committed Nov 14, 2023
1 parent 9f363f9 commit ab139b3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 46 deletions.
37 changes: 4 additions & 33 deletions app/workers/stale_issue_marker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
16 changes: 3 additions & 13 deletions spec/workers/stale_issue_marker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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}") }
Expand All @@ -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)
Expand All @@ -90,21 +86,15 @@ 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)
else
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

0 comments on commit ab139b3

Please sign in to comment.