Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop close issue #655

Merged
merged 1 commit into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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