mirror of
https://github.com/collinbarrett/FilterLists.git
synced 2026-03-11 09:04:27 +00:00
add logging of GitHub API errors
This commit is contained in:
parent
1a41cf6a62
commit
1ae2fe66c0
1 changed files with 34 additions and 7 deletions
|
|
@ -1,6 +1,7 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using FilterLists.Agent.AppSettings;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Octokit;
|
||||
|
||||
|
|
@ -19,10 +20,12 @@ public class AgentGitHubClient : IAgentGitHubClient
|
|||
{
|
||||
private readonly GitHubClient _gitHubClient;
|
||||
private readonly GitHub _gitHubOptions;
|
||||
private readonly ILogger<AgentGitHubClient> _logger;
|
||||
|
||||
public AgentGitHubClient(IOptions<GitHub> gitHubOptions)
|
||||
public AgentGitHubClient(IOptions<GitHub> gitHubOptions, ILogger<AgentGitHubClient> logger)
|
||||
{
|
||||
_gitHubOptions = gitHubOptions.Value;
|
||||
_logger = logger;
|
||||
_gitHubClient = new GitHubClient(new ProductHeaderValue(_gitHubOptions.ProductHeaderValue))
|
||||
{
|
||||
Credentials = new Credentials(_gitHubOptions.PersonalAccessToken)
|
||||
|
|
@ -31,20 +34,44 @@ public AgentGitHubClient(IOptions<GitHub> gitHubOptions)
|
|||
|
||||
public async Task<IReadOnlyList<Issue>> GetAllIssues(RepositoryIssueRequest repositoryIssueRequest)
|
||||
{
|
||||
return await _gitHubClient.Issue.GetAllForRepository(_gitHubOptions.RepositoryOwner,
|
||||
_gitHubOptions.Repository, repositoryIssueRequest);
|
||||
try
|
||||
{
|
||||
return await _gitHubClient.Issue.GetAllForRepository(_gitHubOptions.RepositoryOwner,
|
||||
_gitHubOptions.Repository, repositoryIssueRequest);
|
||||
}
|
||||
catch (ApiException ex)
|
||||
{
|
||||
_logger.LogError(ex, "Failed getting all Issues from the GitHub API.");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<Issue> CreateIssue(NewIssue newIssue)
|
||||
{
|
||||
return await _gitHubClient.Issue.Create(_gitHubOptions.RepositoryOwner, _gitHubOptions.Repository,
|
||||
newIssue);
|
||||
try
|
||||
{
|
||||
return await _gitHubClient.Issue.Create(_gitHubOptions.RepositoryOwner, _gitHubOptions.Repository,
|
||||
newIssue);
|
||||
}
|
||||
catch (ApiException ex)
|
||||
{
|
||||
_logger.LogError(ex, "Failed creating Issue with the GitHub API.");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<Issue> UpdateIssue(int issueNumber, IssueUpdate updateIssue)
|
||||
{
|
||||
return await _gitHubClient.Issue.Update(_gitHubOptions.RepositoryOwner, _gitHubOptions.Repository,
|
||||
issueNumber, updateIssue);
|
||||
try
|
||||
{
|
||||
return await _gitHubClient.Issue.Update(_gitHubOptions.RepositoryOwner, _gitHubOptions.Repository,
|
||||
issueNumber, updateIssue);
|
||||
}
|
||||
catch (ApiException ex)
|
||||
{
|
||||
_logger.LogError(ex, "Failed updating Issue with the GitHub API.");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue