private static async Task <IList <(string, Reminder)> > FindNewReminders( CallbackModel.CommitModel[] commits, CallbackModel requestObject, GitHubClient installationClient) { var reminderFiles = CommitParser.GetReminders(commits); var results = new List <(string, Reminder)>(reminderFiles.Length); // potentially lower but never higher than number of files foreach (string newFile in reminderFiles) { var reminderParser = GetReminderParser(newFile); if (reminderParser == null) { // unsupported file type continue; } var content = await installationClient.Repository.Content.GetAllContentsByRef( requestObject.Repository.Id, newFile, requestObject.Ref); var reminder = reminderParser.Parse(content.First().Content); results.Add((newFile, reminder)); } return(results); }
private static async Task DeleteRemovedReminders(IDocumentClient documentClient, ILogger log, CallbackModel requestObject, GitHubClient client) { var deletedReminders = CommitParser.GetDeletedReminders(requestObject.Commits); foreach (var deletedReminder in deletedReminders) { var reminderParser = GetReminderParser(deletedReminder); if (reminderParser == null) { // unsupported file type continue; } try { var documentId = BuildDocumentId(requestObject, deletedReminder); var documentUri = UriFactory.CreateDocumentUri("annoydb", "reminders", documentId); await documentClient.DeleteDocumentAsync(documentUri, new RequestOptions() { PartitionKey = new PartitionKey(documentId) }); await CreateCommitComment(client, requestObject, $"Deleted reminder '{deletedReminder}'"); } catch (Exception e) { log.LogError(e, "Failed to delete reminder"); await CreateCommitComment( client, requestObject, $"Failed to delete reminder {deletedReminder}: {string.Join(Environment.NewLine, e.Message, e.StackTrace)}"); throw; } } }