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

[pull] main from community:main #2

Merged
merged 6 commits into from
Mar 20, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/DISCUSSION_TEMPLATE/enterprise.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ body:
- type: dropdown
attributes:
label: Select Topic Area
description: What would you like to discuss?
name: "Topic"
description: "What would you like to discuss?"
options:
- Question
- Product Feedback
Expand Down
33 changes: 14 additions & 19 deletions .github/actions/comment
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ require_relative "../lib/github"
stale_label_id = "LA_kwDOEfmk4M8AAAABYVCU-g"
owner = "community"
repo = "community"
only_these_categories = ["Copilot"]

body =<<BODY
🕒 **Discussion Activity Reminder** 🕒
Expand All @@ -24,23 +23,19 @@ Note: This dormant notification will only apply to Discussions with the `Questio
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 |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)

sleep 1.2
discussions = Discussion.all(owner:, repo:)
puts "All: #{discussions.count}"

unlabelled = discussions.reject { |d| d.labelled }
puts "Unlabelled: #{unlabelled.count}"
unlabelled.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")}"
exit
end
discussion.add_label(label_id: stale_label_id)

sleep 10
end
6 changes: 6 additions & 0 deletions .github/lib/categories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ def self.all(owner: nil, repo: nil)
}
}
}
rateLimit {
limit
cost
remaining
resetAt
}
}
QUERY

Expand Down
84 changes: 42 additions & 42 deletions .github/lib/discussions.rb
Original file line number Diff line number Diff line change
@@ -1,69 +1,69 @@
# frozen_string_literal: true

require "active_support"
require "active_support/core_ext/date_and_time/calculations"
require "active_support/core_ext/numeric/time"

Discussion = Struct.new(
:id,
:url,
:title
:title,
:labelled
) do
def self.all(owner: nil, repo: nil, category: nil)
return [] if owner.nil? || repo.nil? || category.nil?
def self.all(owner: nil, repo: nil)
return [] if owner.nil? || repo.nil?

cutoff_date = Time.now.advance(days: -60).to_date.to_s
searchquery = "repo:#{owner}/#{repo} is:unanswered is:open is:unlocked updated:<#{cutoff_date} category:Copilot category:Accessibility category:\\\"Projects and Issues\\\" label:Question"

query = <<~QUERY
{
repository(owner: "#{owner}", name: "#{repo}"){
discussions(
first: 100,
after: "%ENDCURSOR%"
#{"answered: false," if category.answerable}
categoryId: "#{category.id}"
orderBy: { field: CREATED_AT, direction: ASC }
) {
nodes {
id
url
title
closed
locked
updatedAt
comments(last: 1) {
totalCount
nodes {
createdAt
}
}
labels(first: 100) {
nodes {
name
}
search(
first: 100
after: "%ENDCURSOR%"
query: "#{searchquery}"
type: DISCUSSION
) {
discussionCount
...Results
pageInfo {
hasNextPage
endCursor
}
}
rateLimit {
limit
cost
remaining
resetAt
}
}
fragment Results on SearchResultItemConnection {
nodes {
... on Discussion {
id
url
title
labels(first: 10) {
nodes {
name
}
}
pageInfo {
hasNextPage
endCursor
}
}
}
}
QUERY

cutoff_date = Time.now.advance(days: -60)
GitHub.new.post(graphql: query).map! { |r| r.dig('discussions', 'nodes') }
GitHub.new.post(graphql: query)
.map! { |r| r.dig('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") }
.select { |r| r.dig("labels", "nodes").map { |l| l["name"] }.include?("stale") }
.map do |c|
labelled = c.dig("labels", "nodes").map { |l| l["name"] }.include?("inactive")
Discussion.new(
c["id"],
c["url"],
c["title"]
c["title"],
labelled
)
end
end
Expand Down
16 changes: 10 additions & 6 deletions .github/lib/github.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ def initialize
headers: {
Authorization: "bearer #{ENV['GITHUB_TOKEN']}"
}
)
) do |f|
f.response :raise_error
end
end

def post(graphql:)
Expand All @@ -25,19 +27,21 @@ def post(graphql:)
query = end_cursor.nil? ? graphql.sub(/after.*\n/, "") : graphql.sub("%ENDCURSOR%", end_cursor)

response = @conn.post("/graphql") do |req|
req.options.timeout = 10
req.body = { query: }.to_json
end
unless response.status == 200
puts "#{response.reason_phrase}: #{JSON.parse(response.body).dig("message")}"
exit

if rate_limit = JSON.parse(response.body).dig("data", "rateLimit")
puts "Rate limit: limit - #{rate_limit["limit"]}, cost - #{rate_limit["cost"]}, remaining - #{rate_limit["remaining"]}, resetAt - #{rate_limit["resetAt"]}"
end

node = JSON.parse(response.body).dig("data", "repository")
node = JSON.parse(response.body).dig("data", "search") if node.nil?
nodes << node

break unless node.dig("discussions", "pageInfo", "hasNextPage")
break unless node&.dig("pageInfo", "hasNextPage")

end_cursor = node.dig("discussions", "pageInfo", "endCursor")
end_cursor = node.dig("pageInfo", "endCursor")
end

nodes.flatten
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/comment-on-dormant-discussions.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
name: Comment on dormant discussions

on: workflow_dispatch
on:
workflow_dispatch:
schedule:
# At minute 23 past every 2nd hour
- cron: '23 */2 * * *'

jobs:
build:
Expand Down
Loading