Repository: microsoft/onefuzz
File: src/ApiService/ApiService/onefuzzlib/notifications/GithubIssues.cs (C#)

Code before:
﻿using Octokit;

namespace Microsoft.OneFuzz.Service;

public interface IGithubIssues {
    Async.Task GithubIssue(GithubIssuesTemplate config, Container container, IReport reportable, Guid notificationId);
}

public class GithubIssues : NotificationsBase, IGithubIssues {

    public GithubIssues(ILogTracer logTracer, IOnefuzzContext context)
    : base(logTracer, context) { }

    public async Async.Task GithubIssue(GithubIssuesTemplate config, Container container, IReport reportable, Guid notificationId) {
        var filename = reportable.FileName();
        if (filename == null) {
            return;
        }

        if (reportable is RegressionReport) {
            _logTracer.Info($"github issue integration does not support regression reports. {container:Tag:Container} - {filename:Tag:Filename}");
            return;
        }

        var report = (Report)reportable;

        try {
            await Process(config, container, filename, report);
        } catch (ApiException e) {
            await LogFailedNotification(report, e, notificationId);
        }
    }

    public static async Async.Task<OneFuzzResultVoid> Validate(GithubIssuesTemplate config) {
        // Validate PAT is valid
        GitHubClient gh;
        if (config.Auth.Secret is SecretValue<GithubAuth> auth) {
            try {
                gh = GetGitHubClient(auth.Value.User, auth.Value.PersonalAccessToken);
                var _ = await gh.User.Get(auth.Value.User);
            } catch {

Review comment (refactor):
`filename` can't be null, it either has a value or throws so we could remove this check entirely

Code after:
﻿using Octokit;

namespace Microsoft.OneFuzz.Service;

public interface IGithubIssues {
    Async.Task GithubIssue(GithubIssuesTemplate config, Container container, IReport reportable, Guid notificationId);
}

public class GithubIssues : NotificationsBase, IGithubIssues {

    public GithubIssues(ILogTracer logTracer, IOnefuzzContext context)
    : base(logTracer, context) { }

    public async Async.Task GithubIssue(GithubIssuesTemplate config, Container container, IReport reportable, Guid notificationId) {
        var filename = reportable.FileName();

        if (reportable is RegressionReport) {
            _logTracer.Info($"github issue integration does not support regression reports. {container:Tag:Container} - {filename:Tag:Filename}");
            return;
        }

        var report = (Report)reportable;

        try {
            await Process(config, container, filename, report);
        } catch (ApiException e) {
            await LogFailedNotification(report, e, notificationId);
        }
    }

    public static async Async.Task<OneFuzzResultVoid> Validate(GithubIssuesTemplate config) {
        // Validate PAT is valid
        GitHubClient gh;
        if (config.Auth.Secret is SecretValue<GithubAuth> auth) {
            try {
                gh = GetGitHubClient(auth.Value.User, auth.Value.PersonalAccessToken);
                var _ = await gh.User.Get(auth.Value.User);
            } catch {
                return OneFuzzResultVoid.Error(ErrorCode.INVALID_CONFIGURATION, $"Failed to login to github.com with user {auth.Value.User} and the provided Personal Access Token");
            }
        } else {