Uh oh!
There was an error while loading. Please reload this page.
This repository was archived by the owner on Jun 5, 2025. It is now read-only.
- Notifications
You must be signed in to change notification settings - Fork 4
Add Windows toast notifications for new reviews for the logged in developer's pull requests.#337
Merged
David Bennett (dkbennett)
merged 5 commits into
main
from
user/dkbennett/reviewnotificationFeb 5, 2024
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
184010e
Add review to datastore and notifications
dkbennett b44045d
Add toast for new reviews
dkbennett 18a9581
Update toast to align with specification
dkbennett 2b66686
Add stale filtering, notifications that are usurped by newer notifica…
dkbennett 8ac62eb
Fix for comment state being unrecognized
dkbennett File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
| @@ -16,6 +16,7 @@ public partial class GitHubDataManager : IGitHubDataManager, IDisposable | ||
| private static readonly TimeSpan NotificationRetentionTime = TimeSpan.FromDays(7); | ||
| private static readonly TimeSpan SearchRetentionTime = TimeSpan.FromDays(7); | ||
| private static readonly TimeSpan PullRequestStaleTime = TimeSpan.FromDays(1); | ||
| private static readonly TimeSpan ReviewStaleTime = TimeSpan.FromDays(7); | ||
| // It is possible different widgets have queries which touch the same pull requests. | ||
| // We want to keep this window large enough that we don't delete data being used by | ||
| @@ -438,6 +439,27 @@ private async Task UpdatePullRequestsForLoggedInDeveloperIdsAsync(DataStoreOpera | ||
| CommitCombinedStatus.GetOrCreate(DataStore, commitCombinedStatus); | ||
| CreatePullRequestStatus(dsPullRequest); | ||
| // Review information for this pull request. | ||
| // We will only get review data for the logged-in Developer's pull requests. | ||
| try | ||
| { | ||
| var octoReviews = await devId.GitHubClient.PullRequest.Review.GetAll(repoName[0], repoName[1], octoPull.Number); | ||
| foreach (var octoReview in octoReviews) | ||
| { | ||
| ProcessReview(dsPullRequest, octoReview); | ||
| } | ||
| } | ||
| catch (Exception e) | ||
| { | ||
| // Octokit can sometimes fail unexpectedly or have bugs. Should that occur here, we | ||
| // will not stop processing all pull requests and instead skip over getting the PR | ||
| // review information for this particular pull request. | ||
| Log.Logger()?.ReportError($"Error updating Reviews for Pull Request #{octoPull.Number}: {e.Message}"); | ||
| // Put the full stack trace in debug if this occurs to reduce log spam. | ||
| Log.Logger()?.ReportDebug($"Error updating Reviews for Pull Request #{octoPull.Number}.", e); | ||
| } | ||
| } | ||
| Log.Logger()?.ReportDebug(Name, $"Updated developer pull requests for {repoFullName}."); | ||
| @@ -514,6 +536,36 @@ private async Task UpdatePullRequestsAsync(Repository repository, Octokit.GitHub | ||
| PullRequest.DeleteLastObservedBefore(DataStore, repository.Id, DateTime.UtcNow - LastObservedDeleteSpan); | ||
| } | ||
| private void ProcessReview(PullRequest pullRequest, Octokit.PullRequestReview octoReview) | ||
| { | ||
| // Skip reviews that are stale. | ||
| if ((DateTime.Now - octoReview.SubmittedAt) > ReviewStaleTime) | ||
| { | ||
| return; | ||
| } | ||
| // For creating review notifications, must first determine if the review has changed. | ||
| var existingReview = Review.GetByInternalId(DataStore, octoReview.Id); | ||
| // Add/update the review record. | ||
| var newReview = Review.GetOrCreateByOctokitReview(DataStore, octoReview, pullRequest.Id); | ||
| // Ignore comments or pending state. | ||
dkbennett marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| if (string.IsNullOrEmpty(newReview.State) || newReview.State == "Commented") | ||
| { | ||
| Log.Logger()?.ReportDebug(Name, "Notifications", $"Ignoring review for {pullRequest}. State: {newReview.State}"); | ||
| return; | ||
| } | ||
| // Create a new notification if the state is different or the review did not exist. | ||
| if (existingReview == null || (existingReview.State != newReview.State)) | ||
| { | ||
| // We assume that the logged in developer created this pull request. | ||
| Log.Logger()?.ReportInfo(Name, "Notifications", $"Creating NewReview Notification for {pullRequest}. State: {newReview.State}"); | ||
| Notification.Create(DataStore, newReview, NotificationType.NewReview); | ||
| } | ||
| } | ||
| private void CreatePullRequestStatus(PullRequest pullRequest) | ||
| { | ||
| // Get the previous status for comparison. | ||
| @@ -525,15 +577,13 @@ private void CreatePullRequestStatus(PullRequest pullRequest) | ||
| if (ShouldCreateCheckFailureNotification(curStatus, prevStatus)) | ||
| { | ||
| Log.Logger()?.ReportInfo(Name, "Notifications", $"Creating CheckRunFailure Notification for {curStatus}"); | ||
| var notification = Notification.Create(curStatus, NotificationType.CheckRunFailed); | ||
| Notification.Add(DataStore, notification); | ||
| Notification.Create(DataStore, curStatus, NotificationType.CheckRunFailed); | ||
| } | ||
| if (ShouldCreateCheckSucceededNotification(curStatus, prevStatus)) | ||
| { | ||
| Log.Logger()?.ReportDebug(Name, "Notifications", $"Creating CheckRunSuccess Notification for {curStatus}"); | ||
| var notification = Notification.Create(curStatus, NotificationType.CheckRunSucceeded); | ||
| Notification.Add(DataStore, notification); | ||
| Notification.Create(DataStore, curStatus, NotificationType.CheckRunSucceeded); | ||
| } | ||
| } | ||
| @@ -662,6 +712,7 @@ private void PruneObsoleteData() | ||
| Notification.DeleteBefore(DataStore, DateTime.Now - NotificationRetentionTime); | ||
| Search.DeleteBefore(DataStore, DateTime.Now - SearchRetentionTime); | ||
| SearchIssue.DeleteUnreferenced(DataStore); | ||
| Review.DeleteUnreferenced(DataStore); | ||
| } | ||
| // Sets a last-updated in the MetaData. | ||
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -317,6 +317,26 @@ public PullRequestStatus? PullRequestStatus | ||
| } | ||
| } | ||
| /// <summary> | ||
| /// Gets all reviews associated with this pull request. | ||
| /// </summary> | ||
| [Write(false)] | ||
| [Computed] | ||
| public IEnumerable<Review> Reviews | ||
| { | ||
| get | ||
| { | ||
| if (DataStore == null) | ||
dkbennett marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| { | ||
| return Enumerable.Empty<Review>(); | ||
| } | ||
| else | ||
| { | ||
| return Review.GetAllForPullRequest(DataStore, this) ?? Enumerable.Empty<Review>(); | ||
| } | ||
| } | ||
| } | ||
| public override string ToString() => $"{Number}: {Title}"; | ||
| // Create pull request from OctoKit pull request data | ||
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.