Skip to content

Commit

Permalink
Adding try-catch around Octokit API crashing method (#305)
Browse files Browse the repository at this point in the history
Co-authored-by: Felipe da Conceicao Guimaraes <[email protected]>
  • Loading branch information
guimafelipe and Felipe da Conceicao Guimaraes authored Jan 9, 2024
1 parent 956d46c commit 408c922
Showing 1 changed file with 33 additions and 18 deletions.
51 changes: 33 additions & 18 deletions src/GitHubExtension/DataManager/GitHubDataManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 408c922

Please sign in to comment.