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

Add the comment text that will be used to comment on stale discussions #69778

Merged
merged 16 commits into from
Mar 6, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
41 changes: 30 additions & 11 deletions .github/actions/comment
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,41 @@ require_relative "../lib/github"
stale_label_id = "LA_kwDOEfmk4M8AAAABYVCU-g"
owner = "community"
repo = "community"
only_these_categories = ["Copilot", "Projects and Issues", "Accessibility"]

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

only_these_categories = ["Copilot"]

body =<<BODY
🕒 **Discussion Activity Reminder** 🕒

This Discussion has been labeled as dormant by an automated system for having no activity in the last 60 days. Please consider one the following actions:

1️⃣ Close as Out of Date: If the topic is no longer relevant, close the Discussion as `out of date` at the bottom of the page.

2️⃣ Provide More Information: Share additional details or context — or let the community know if you've found a solution on your own.

3️⃣ Mark a Reply as Answer: If your question has been answered by a reply, mark the most helpful reply as the solution.

Note: This dormant notification will only apply to Discussions with the `Question` label. To learn more, see our [recent announcement](https://github.com/orgs/community/discussions/70478).

Thank you for helping bring this Discussion to a resolution! 💬
BODY

categories = Category.all(owner:, repo:).select { |c| only_these_categories.include?(c.name) }

categories.map do |category|
category.discussions = Discussion.all(owner:, repo:, category:)
end

categories.each do |c|
puts "#{c.name} has #{c.discussions.count} eligible discussion(s)"
end
categories.each do |category|
category.discussions.each do |discussion|
puts "#{discussion.url},#{discussion.title}"
result = discussion.add_comment(body: body)
if errors = result.dig("errors")
puts "#{errors.dig(0, "type")}: #{errors.dig(0, "message")}"
sleep 1.2
next
end
#discussion.add_label(label_id: stale_label_id)

# for initial testing, don't modify any discussions
#categories.each do |category|
# category.discussions.each do |discussion|
# discussion.add_comment(body: "This is automated")
# discussion.add_label(label_id: stale_label_id)
# end
#end
sleep 1.2
end
end
12 changes: 10 additions & 2 deletions .github/lib/discussions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

Discussion = Struct.new(
:id,
:url,
:title
) do
def self.all(owner: nil, repo: nil, category: nil)
return [] if owner.nil? || repo.nil? || category.nil?
Expand All @@ -21,6 +23,8 @@ def self.all(owner: nil, repo: nil, category: nil)
) {
nodes {
id
url
title
closed
locked
updatedAt
Expand Down Expand Up @@ -49,13 +53,17 @@ def self.all(owner: nil, repo: nil, category: nil)
GitHub.new.post(graphql: query).map! { |r| r.dig('discussions', 'nodes') }
.flatten
.reject { |r| Date.parse(r["updatedAt"]).after?(cutoff_date) }
.select { |r| r.dig("labels", "nodes").map { |l| l["name"] }.include?("Question") }
.reject { |r| r["closed"] }
.reject { |r| r["locked"] }
.reject { |r| r.dig("comments", "totalCount") > 0 && Date.parse(r.dig("comments", "nodes", 0, "createdAt")).after?(cutoff_date) }
.reject { |r| r.dig("labels", "nodes").map { |l| l["name"] }.include?("stale") }
#.reject { |r| r.dig("labels", "nodes").map { |l| l["name"] }.include?("stale") }
.select { |r| r.dig("labels", "nodes").map { |l| l["name"] }.include?("stale") }
.map do |c|
Discussion.new(
c["id"]
c["id"],
c["url"],
c["title"]
)
end
end
Expand Down
4 changes: 4 additions & 0 deletions .github/lib/github.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ def post(graphql:)
response = @conn.post("/graphql") do |req|
req.body = { query: }.to_json
end
unless response.status == 200
puts "#{response.reason_phrase}: #{JSON.parse(response.body).dig("message")}"
exit
end

node = JSON.parse(response.body).dig("data", "repository")
nodes << node
Expand Down