From 408c922c41320d493c1670720d013081fcf748df Mon Sep 17 00:00:00 2001 From: Felipe G Date: Tue, 9 Jan 2024 14:08:38 -0800 Subject: [PATCH] Adding try-catch around Octokit API crashing method (#305) Co-authored-by: Felipe da Conceicao Guimaraes --- .../DataManager/GitHubDataManager.cs | 51 ++++++++++++------- 1 file changed, 33 insertions(+), 18 deletions(-) diff --git a/src/GitHubExtension/DataManager/GitHubDataManager.cs b/src/GitHubExtension/DataManager/GitHubDataManager.cs index 63d10d12..9fea42d9 100644 --- a/src/GitHubExtension/DataManager/GitHubDataManager.cs +++ b/src/GitHubExtension/DataManager/GitHubDataManager.cs @@ -402,18 +402,25 @@ private async Task UpdatePullRequestsForLoggedInDeveloperIdsAsync(DataStoreOpera CheckRun.GetOrCreateByOctokitCheckRun(DataStore, run); } - CheckSuite.DeleteAllForPullRequest(DataStore, dsPullRequest); - var octoCheckSuiteResponse = await devId.GitHubClient.Check.Suite.GetAllForReference(repoName[0], repoName[1], dsPullRequest.HeadSha); - foreach (var suite in octoCheckSuiteResponse.CheckSuites) + try { - // Skip Dependabot, as it is not part of a pull request's blocking suites. - if (suite.App.Id == CheckSuiteIdDependabot) + CheckSuite.DeleteAllForPullRequest(DataStore, dsPullRequest); + var octoCheckSuiteResponse = await devId.GitHubClient.Check.Suite.GetAllForReference(repoName[0], repoName[1], dsPullRequest.HeadSha); + foreach (var suite in octoCheckSuiteResponse.CheckSuites) { - continue; + // Skip Dependabot, as it is not part of a pull request's blocking suites. + if (suite.App.Id == CheckSuiteIdDependabot) + { + continue; + } + + Log.Logger()?.ReportDebug($"Suite: {suite.App.Name} - {suite.App.Id} - {suite.App.Owner.Login} Conclusion: {suite.Conclusion} Status: {suite.Status}"); + CheckSuite.GetOrCreateByOctokitCheckSuite(DataStore, suite); } - - Log.Logger()?.ReportDebug($"Suite: {suite.App.Name} - {suite.App.Id} - {suite.App.Owner.Login} Conclusion: {suite.Conclusion} Status: {suite.Status}"); - CheckSuite.GetOrCreateByOctokitCheckSuite(DataStore, suite); + } + catch (Exception e) + { + Log.Logger()?.ReportError($"Check suite error for Pull Request #{octoPull.Number}: " + e.Message); } var commitCombinedStatus = await devId.GitHubClient.Repository.Status.GetCombined(dsRepository.InternalId, dsPullRequest.HeadSha); @@ -459,18 +466,26 @@ private async Task UpdatePullRequestsAsync(Repository repository, Octokit.GitHub CheckRun.GetOrCreateByOctokitCheckRun(DataStore, run); } - CheckSuite.DeleteAllForPullRequest(DataStore, dsPullRequest); - var octoCheckSuiteResponse = await client.Check.Suite.GetAllForReference(repository.InternalId, dsPullRequest.HeadSha); - foreach (var suite in octoCheckSuiteResponse.CheckSuites) + try { - // Skip Dependabot, as it is not part of a pull request's blocking suites. - if (suite.App.Id == CheckSuiteIdDependabot) + CheckSuite.DeleteAllForPullRequest(DataStore, dsPullRequest); + var octoCheckSuiteResponse = await client.Check.Suite.GetAllForReference(repository.InternalId, dsPullRequest.HeadSha); + + foreach (var suite in octoCheckSuiteResponse.CheckSuites) { - continue; - } + // Skip Dependabot, as it is not part of a pull request's blocking suites. + if (suite.App.Id == CheckSuiteIdDependabot) + { + continue; + } - Log.Logger()?.ReportDebug($"Suite: {suite.App.Name} - {suite.App.Id} - {suite.App.Owner.Login} Conclusion: {suite.Conclusion} Status: {suite.Status}"); - CheckSuite.GetOrCreateByOctokitCheckSuite(DataStore, suite); + Log.Logger()?.ReportDebug($"Suite: {suite.App.Name} - {suite.App.Id} - {suite.App.Owner.Login} Conclusion: {suite.Conclusion} Status: {suite.Status}"); + CheckSuite.GetOrCreateByOctokitCheckSuite(DataStore, suite); + } + } + catch (Exception e) + { + Log.Logger()?.ReportError($"Check suite error for Pull Request #{pull.Number}: " + e.Message); } var commitCombinedStatus = await client.Repository.Status.GetCombined(repository.InternalId, dsPullRequest.HeadSha);