public static SimpleIssueViewModel ToViewModel(this SimpleIssue i) => new SimpleIssueViewModel
 {
     Id          = i.Id,
     User        = i.User,
     IssueTS     = i.IssueTS,
     IssueType   = i.IssueType,
     Category    = i.Category,
     LongDescr   = i.LongDescr,
     SolveDescr  = i.SolveDescr,
     IssueStatus = i.IssueStatus
 };
Exemple #2
0
    public async Task <List <SimpleIssue> > GetPullRequestsAsIssuesAsync(string owner, string repo, string tag, bool openOnly = true)
    {
        // create the github client
        GitHubClient client = new GitHubClient(new ProductHeaderValue(AppInfo.GITHUB_CLIENT_HEADER));
        var          basic  = new Credentials(AppInfo.Token);

        client.Credentials = basic;

        // create the request parameters
        // using the tag to search for
        RepositoryIssueRequest issueRequest = new();

        issueRequest.State = openOnly ? ItemStateFilter.Open : ItemStateFilter.All;
        issueRequest.Labels.Add(tag);

        // fetch all open pull requests
        var found = await client.Issue.GetAllForRepository(owner, repo, issueRequest);

        List <SimpleIssue> issues = new();

        foreach (var pr in found)
        {
            if (pr.PullRequest != null)
            {
                var labels = new List <Label>();
                foreach (var label in pr.Labels)
                {
                    labels.Add(new Label()
                    {
                        Color = label.Color, Name = label.Name
                    });
                }

                var issue = new SimpleIssue()
                {
                    Number = pr.Number,
                    Title  = pr.Title,
                    User   = new User()
                    {
                        Login = pr.User.Login
                    },
                    CreatedAt = pr.CreatedAt,
                    State     = new State()
                    {
                        StringValue = pr.State.StringValue
                    },
                    PullRequest = new PullRequest()
                    {
                        HtmlUrl = pr.PullRequest.HtmlUrl
                    },
                    Labels = labels,
                    Repo   = repo,
                    Org    = owner
                };
                if (pr.Milestone != null)
                {
                    if (pr.Milestone.Title != null)
                    {
                        issue.Milestone = new Milestone()
                        {
                            Title = pr.Milestone.Title
                        }
                    }
                    ;
                }

                issues.Add(issue);
            }
        }

        // get some rate limit info
        var apiInfo   = client.GetLastApiInfo();
        var rateLimit = apiInfo?.RateLimit;

        REQUESTS_PER_HOUR = rateLimit?.Limit;
        REQUESTS_LEFT     = rateLimit?.Remaining;
        LIMIT_RESET       = rateLimit?.Reset.Humanize();

        return(issues);
    }