public async Task Report_SkipsCreationIfThereIsAlreadyOpenIssue() { var report = new ValidationReport { Owner = "owner", RepositoryName = "repo", Results = new ValidationResult[] { new ValidationResult("Rule", "how to fix", false, null) } }; var issue = CreateIssue(CreateIssueTitle("Rule"), ItemState.Open); _mockIssuesClient.GetAllForRepository(report.Owner, report.RepositoryName, Arg.Any <RepositoryIssueRequest>()).Returns(Task.FromResult((IReadOnlyList <Issue>) new List <Issue>() { issue })); await _reporter.Report(new ValidationReport[] { report }); await _mockIssuesClient.DidNotReceive().Create(Arg.Any <string>(), Arg.Any <string>(), Arg.Any <NewIssue>()); await _mockIssuesClient.DidNotReceive().Update(Arg.Any <string>(), Arg.Any <string>(), Arg.Any <int>(), Arg.Any <IssueUpdate>()); }
private async Task CreateIssues(IEnumerable <PortingInfo> rulesToPort) { var existingIssues = await _issuesClient.GetAllForRepository( _options.RepoOwner, _options.RepoName, new RepositoryIssueRequest { Filter = IssueFilter.All, // Get issues whether or not they're assigned to me. State = ItemState.All // Get issues whether they're open or closed. }); foreach (var ruleToPort in rulesToPort) { string title = MakeIssueTitle(ruleToPort); var matchingIssues = existingIssues.Where(issue => issue.Title == title); int numMatchingIssues = matchingIssues.Count(); if (numMatchingIssues == 0) { _log.InfoFormat(Resources.InfoFilingNewIssue, ruleToPort.Id); Issue issue = FileIssueAsync(ruleToPort, title).Result; // If the issue we just filed has already been dealt with, one way // or another, then immediately close it. UpdateIssueAsync will do that. if (ruleToPort.Disposition == Disposition.Cut || ruleToPort.Disposition == Disposition.Ported) { await UpdateIssueAsync(ruleToPort, issue); } } else if (numMatchingIssues == 1) { Issue existingIssue = matchingIssues.First(); int issueNumber = existingIssue.Number; _log.InfoFormat(Resources.InfoUpdatingExistingIssue, issueNumber, ruleToPort.Id); await UpdateIssueAsync(ruleToPort, existingIssue); } else if (numMatchingIssues > 1) { _log.WarnFormat( Resources.WarningMultipleIssuesExist, ruleToPort.Id, string.Join(", ", matchingIssues.Select(i => i.Number.ToString()).ToArray())); } if (_options.Delay > 0 && !_options.DryRun) { _log.DebugFormat(Resources.DebugDelaying, _options.Delay); Thread.Sleep(_options.Delay); } } }
public (List <KeyValuePair <DateTime, int> >, string) GetAllIssues(string repoUrl) { if (issuesclient == null) { Setup(); } repoUrl = Regex.Replace(repoUrl, ".*github.com/", ""); string user = Regex.Split(repoUrl, "/")[0]; string repo = Regex.Split(repoUrl, "/")[1]; var allissues = issuesclient.GetAllForRepository(user, repo, getAll).GetAwaiter().GetResult(); Dictionary <DateTime, int> dict = new Dictionary <DateTime, int>(); foreach (Issue issue in allissues) { DateTime created = new DateTime(issue.CreatedAt.Year, issue.CreatedAt.Month, issue.CreatedAt.Day, 0, 0, 0); DateTimeOffset closedOffset = issue.ClosedAt ?? DateTimeOffset.Now.AddDays(1); DateTime closed = new DateTime(closedOffset.Year, closedOffset.Month, closedOffset.Day, 0, 0, 0); Console.WriteLine("New issue"); while (created < closed) { if (dict.ContainsKey(created)) { dict.TryGetValue(created, out int value); dict.Remove(created); dict.Add(created, ++value); } else { dict.Add(created, 1); } created = created.AddDays(1); } } var myList = dict.ToList(); myList.Sort((pair1, pair2) => pair1.Key.CompareTo(pair2.Key)); DateTime first = myList.ElementAt(0).Key; while (first <= DateTime.Now) { if (!dict.ContainsKey(first)) { myList.Add(new KeyValuePair <DateTime, int>(first, 0)); } first = first.AddDays(1); } myList.Sort((pair1, pair2) => pair1.Key.CompareTo(pair2.Key)); return(myList, repo); }
public Issue GetIssueWithName(string repositorName, string ownerName, string issueName) { IReadOnlyList <Issue> issues = issuesClient.GetAllForRepository(ownerName, repositorName).GetAwaiter().GetResult(); return(issues.FirstOrDefault(i => { if (i.Title.Equals(issueName)) { return true; } else { return false; } })); }
private bool DoesIssueExist(string issueTitle) { var repositoryIssueRequest = new RepositoryIssueRequest { State = ItemStateFilter.All }; foreach (var label in _issueLabels) { repositoryIssueRequest.Labels.Add(label); } var task = _issuesClient.GetAllForRepository(_gitHubRepoInfo.Owner, _gitHubRepoInfo.Name, repositoryIssueRequest); task.Wait(); var issues = task.Result; if (issues == null) { return(false); //Not sure what happened, let's just upload the report. } return(issues.Any(i => i.Title == issueTitle)); }
public async Task CanCreateRetrieveAndCloseIssue() { var newIssue = new NewIssue("a test issue") { Body = "A new unassigned issue" }; var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue); try { Assert.NotNull(issue); var retrieved = await _issuesClient.Get(_context.RepositoryOwner, _context.RepositoryName, issue.Number); var all = await _issuesClient.GetAllForRepository(_context.RepositoryOwner, _context.RepositoryName); Assert.NotNull(retrieved); Assert.True(all.Any(i => i.Number == retrieved.Number)); } finally { var closed = _issuesClient.Update(_context.RepositoryOwner, _context.RepositoryName, issue.Number, new IssueUpdate { State = ItemState.Closed }) .Result; Assert.NotNull(closed); } }
public async Task ReturnsPageOfIssuesForARepository() { var options = new ApiOptions { PageSize = 5, PageCount = 1 }; var issues = await _issuesClient.GetAllForRepository("libgit2", "libgit2sharp", options); Assert.Equal(5, issues.Count); }