Exemplo n.º 1
0
        public async Task <bool> AddComment(Models.Issue issue, Comment comment)
        {
            try
            {
                using (var client = CreateHttpClient())
                {
                    var json     = JsonConvert.SerializeObject(new { body = comment.Body });
                    var response = await client
                                   .PostAsync(issue.CommentsUrl,
                                              new StringContent(json, Encoding.UTF8, "application/json"));

                    return(response.IsSuccessStatusCode);
                }
            }
            catch (Exception)
            {
                return(false);
            }
        }
Exemplo n.º 2
0
        public async Task LoadIssues()
        {
            foreach (var repository in Repositories)
            {
                var issues = await Client.Issue.GetAllForRepository(repository.Id,
                                                                    new RepositoryIssueRequest()
                {
                    State = ItemStateFilter.All
                });

                foreach (var issue in issues)
                {
                    if (issue.PullRequest != null)
                    {
                        continue;
                    }

                    var newIssue = new Models.Issue()
                    {
                        Id         = issue.Id,
                        Body       = issue.Body,
                        CreatedAt  = issue.CreatedAt,
                        Number     = issue.Number,
                        State      = (Models.ItemState)issue.State,
                        Repository = new Models.Repository()
                        {
                            Id              = repository.Id,
                            FullName        = repository.FullName,
                            Name            = repository.Name,
                            HasIssues       = repository.HasIssues,
                            Language        = repository.Language,
                            OpenIssuesCount = repository.OpenIssuesCount
                        },
                        User = new Models.User()
                        {
                            Username  = issue.User.Login,
                            AvatarUrl = issue.User.AvatarUrl
                        },
                        Title       = issue.Title,
                        UpdatedAt   = issue.UpdatedAt,
                        CommentsUrl = issue.CommentsUrl,
                        Url         = issue.Url
                    };
                    if (issue.Comments > 0)
                    {
                        var comments = await Client.Issue.Comment.GetAllForIssue(repository.Id, issue.Number);

                        var list = comments.Select(comment => new Comment()
                        {
                            Id        = comment.Id,
                            Body      = comment.Body.Replace("strong", "Bold"),
                            CreatedAt = comment.CreatedAt,
                            User      = new Models.User()
                            {
                                Username  = comment.User.Login,
                                AvatarUrl = comment.User.AvatarUrl
                            }
                        }).ToList();
                        newIssue.Comments = list;
                    }
                    repository.Issues.Add(newIssue);
                }
            }
        }