forked from community/community
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
introduces new automations for managing incident-based discussions
- Loading branch information
1 parent
00cb405
commit b241588
Showing
14 changed files
with
526 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/usr/bin/env ruby | ||
# frozen_string_literal: true | ||
|
||
require_relative "../lib/github" | ||
require_relative "../lib/discussion" | ||
require "active_support" | ||
require "active_support/core_ext/date_and_time/calculations" | ||
require "active_support/core_ext/numeric/time" | ||
|
||
# this action checks for any open incident discussions older than 2 days, returns an array of discussion IDs | ||
|
||
discussions = Discussion.find_open_incident_discussions(owner: "community", repo: "community") | ||
|
||
discussions.keep_if { |d| Time.parse(d["createdAt"]) < 2.days.ago }.map! { |d| d["id"] } | ||
|
||
`echo "DISCUSSION_IDS"=#{discussions} >> $GITHUB_OUTPUT` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#!/usr/bin/env ruby | ||
# frozen_string_literal: true | ||
|
||
require_relative "../lib/github" | ||
require_relative "../lib/discussion" | ||
|
||
# This script finds the incident discussion, ensures an answer has been marked, and then closes the discussion. | ||
|
||
discussion_ids = ENV["DISCUSSION_IDS"] | ||
|
||
discussion_ids = discussion_ids.delete("[]")&.split(", ") | ||
|
||
if discussion_ids.length == 0 | ||
puts "No discussion IDs provided, exiting" | ||
exit | ||
end | ||
|
||
discussion_ids.each do |d_id| | ||
# if a public summary has not been provided, find the most recent incident comment and mark it as the answer | ||
unless Discussion.is_answered?(id: d_id) | ||
comment_id = Discussion.find_most_recent_incident_comment_id(id: d_id, actor_login: "github-actions") | ||
|
||
unless comment_id.nil? | ||
Discussion.mark_comment_as_answer(comment_id:) | ||
end | ||
|
||
body = "![A dark background with two security-themed abstract shapes positioned in the top left and bottom right corners. In the center of the image, bold white text reads \\\"Incident Resolved\\\" with a white Octocat logo.](https://github.com/community/incident-discussion-bot/blob/main/.github/src/incident_resolved.png?raw=true) \n #{Discussion.find_by_id(id: d_id)["body"]}" | ||
Discussion.update_discussion(id: d_id, body:) | ||
end | ||
|
||
Discussion.close_as_resolved(id: d_id) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#!/usr/bin/env ruby | ||
# frozen_string_literal: true | ||
|
||
require_relative "../lib/github" | ||
require_relative "../lib/discussion" | ||
require "active_support/core_ext/date_time" | ||
|
||
# This script takes context from a received webhook and creates a new discussion in the correct discussion category | ||
|
||
repo_id = "MDEwOlJlcG9zaXRvcnkzMDE1NzMzNDQ=" | ||
announcements_category_id = "DIC_kwDOEfmk4M4CQbR2" | ||
incident_label_id = "LA_kwDOEfmk4M8AAAABpaZlTA" | ||
|
||
date = Time.now.strftime("%Y-%m-%d") | ||
|
||
# we need to take the provided input and generate a new post | ||
title = "[#{date}] Incident Thread" | ||
|
||
body = <<~BODY | ||
## :exclamation: An incident has been declared: | ||
**#{ENV['PUBLIC_TITLE']}** | ||
_Subscribe to this Discussion for updates on this incident. Please upvote or emoji react instead of commenting +1 on the Discussion to avoid overwhelming the thread. Any account guidance specific to this incident will be shared in thread and on the [Incident Status Page](#{ENV['INCIDENT_URL']})._ | ||
BODY | ||
|
||
# we need to create a new discussion in the correct category with the correct label | ||
begin | ||
Discussion.create_incident_discussion( | ||
repo_id:, | ||
title:, | ||
body:, | ||
category_id: announcements_category_id, | ||
labels: [incident_label_id] | ||
) | ||
rescue => ArgumentError | ||
puts "ERROR: One or more arguments missing. #{ArgumentError.message}" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/usr/bin/env ruby | ||
# frozen_string_literal: true | ||
|
||
require_relative "../lib/github" | ||
require_relative "../lib/discussion" | ||
|
||
# This script takes the public incident summary, adds it as a comment to the incident, and then marks that comment as the answer. | ||
|
||
# first, we must identify the correct incident to update, in the case where there are multiple open incident discussions. | ||
open_discussions = Discussion.find_open_incident_discussions(owner: "community", repo: "community") | ||
selected_incident = open_discussions.keep_if { |d| d["body"].include?("#{ENV["INCIDENT_SLUG"]}") }.first | ||
|
||
# add the summary as a comment to the discussion | ||
summary = "### Incident Summary \n #{ENV["INCIDENT_PUBLIC_SUMMARY"]}" | ||
comment_id = Discussion.add_comment_with_id(id: selected_incident["id"], body: summary) | ||
|
||
# mark this new comment as the answer | ||
Discussion.mark_comment_as_answer(comment_id:) | ||
|
||
# update the post body to include the resolved picture | ||
updated_body = "![A dark background with two security-themed abstract shapes positioned in the top left and bottom right corners. In the center of the image, bold white text reads \"Incident Resolved\" with a white Octocat logo.](https://github.com/community/incident-discussion-bot/blob/main/.github/src/incident_resolved.png?raw=true) \n \n #{selected_incident["body"]}" | ||
Discussion.update_discussion(id: selected_incident["id"], body: updated_body) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/usr/bin/env ruby | ||
# frozen_string_literal: true | ||
|
||
require_relative "../lib/github" | ||
require_relative "../lib/discussion" | ||
|
||
# This script takes the context from the latest update dispatch event and updates the active incident discussion | ||
|
||
# first, we must identify the correct incident to update, in the case where there are multiple open incident discussions. | ||
open_discussions = Discussion.find_open_incident_discussions(owner: "community", repo: "community") | ||
selected_incident = open_discussions.keep_if { |d| d["body"].include?("#{ENV["INCIDENT_SLUG"]}") }.first["id"] | ||
|
||
# next, we need to update the discussion with the new information | ||
body = "### Update \n #{ENV["INCIDENT_MESSAGE"]}" | ||
|
||
Discussion.add_comment_with_id(id: selected_incident, body:) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.