public async Task EnsuresArgumentsNotNull() { var client = new ObservableIssuesClient(Substitute.For<IGitHubClient>()); var options = new ApiOptions(); var request = new RepositoryIssueRequest(); await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository(null, "name").ToTask()); await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository(null, "name", options).ToTask()); await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository(null, "name", request).ToTask()); await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository(null, "name", request, options).ToTask()); await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForRepository("", "name").ToTask()); await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForRepository("", "name", options).ToTask()); await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForRepository("", "name", request).ToTask()); await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForRepository("", "name", request, options).ToTask()); await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository("owner", null).ToTask()); await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository("owner", null, options).ToTask()); await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository("owner", null, request).ToTask()); await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository("owner", null, request, options).ToTask()); await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForRepository("owner", "").ToTask()); await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForRepository("owner", "", options).ToTask()); await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForRepository("owner", "", request).ToTask()); await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForRepository("owner", "", request, options).ToTask()); await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository("owner", "name", (ApiOptions)null).ToTask()); await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository("owner", "name", (RepositoryIssueRequest)null).ToTask()); await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository("owner", "name", null, options).ToTask()); await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository("owner", "name", request, null).ToTask()); }
public void EnsuresNonNullArguments() { var client = new ObservableIssuesClient(Substitute.For<IGitHubClient>()); var options = new ApiOptions(); var request = new RepositoryIssueRequest(); Assert.Throws<ArgumentNullException>(() => client.GetAllForRepository(null, "name")); Assert.Throws<ArgumentNullException>(() => client.GetAllForRepository("owner", null)); Assert.Throws<ArgumentNullException>(() => client.GetAllForRepository(null, "name", options)); Assert.Throws<ArgumentNullException>(() => client.GetAllForRepository("owner", null, options)); Assert.Throws<ArgumentNullException>(() => client.GetAllForRepository("owner", "name", (ApiOptions)null)); Assert.Throws<ArgumentNullException>(() => client.GetAllForRepository(null, "name", request)); Assert.Throws<ArgumentNullException>(() => client.GetAllForRepository("owner", null, request)); Assert.Throws<ArgumentNullException>(() => client.GetAllForRepository("owner", "name", (RepositoryIssueRequest)null)); Assert.Throws<ArgumentNullException>(() => client.GetAllForRepository(null, "name", request, options)); Assert.Throws<ArgumentNullException>(() => client.GetAllForRepository("owner", null, request, options)); Assert.Throws<ArgumentNullException>(() => client.GetAllForRepository("owner", "name", null, options)); Assert.Throws<ArgumentNullException>(() => client.GetAllForRepository("owner", "name", request, null)); Assert.Throws<ArgumentNullException>(() => client.GetAllForRepository(1, (ApiOptions)null)); Assert.Throws<ArgumentNullException>(() => client.GetAllForRepository(1, (RepositoryIssueRequest)null)); Assert.Throws<ArgumentNullException>(() => client.GetAllForRepository(1, null, options)); Assert.Throws<ArgumentNullException>(() => client.GetAllForRepository(1, request, null)); Assert.Throws<ArgumentException>(() => client.GetAllForRepository("", "name")); Assert.Throws<ArgumentException>(() => client.GetAllForRepository("owner", "")); Assert.Throws<ArgumentException>(() => client.GetAllForRepository("", "name", options)); Assert.Throws<ArgumentException>(() => client.GetAllForRepository("owner", "", options)); Assert.Throws<ArgumentException>(() => client.GetAllForRepository("", "name", request)); Assert.Throws<ArgumentException>(() => client.GetAllForRepository("owner", "", request)); Assert.Throws<ArgumentException>(() => client.GetAllForRepository("", "name", request, options)); Assert.Throws<ArgumentException>(() => client.GetAllForRepository("owner", "", request, options)); }
async Task<IEnumerable<InvolvedIssue>> GetInvolvedIssuesForRepo(Repository repo, string username) { var mentionedFilter = new RepositoryIssueRequest { State = ItemState.Open, Mentioned = username }; var assigneeFilter = new RepositoryIssueRequest { State = ItemState.Open, Assignee = username }; var creatorFilter = new RepositoryIssueRequest { State = ItemState.Open, Creator = username }; var mentionedQuery = Task.Run( async () => await client.Issue.GetAllForRepository("Particular", repo.Name, mentionedFilter)); var assigneeQuery = Task.Run( async () => await client.Issue.GetAllForRepository("Particular", repo.Name, assigneeFilter)); var creatorQuery = Task.Run( async () => await client.Issue.GetAllForRepository("Particular", repo.Name, creatorFilter)); await Task.WhenAll(mentionedQuery, assigneeQuery, creatorQuery); return mentionedQuery.Result .Where(issue => ExtractTeam(issue.Body).ToArray() .Contains(username, StringComparer.InvariantCultureIgnoreCase)) .Concat( assigneeQuery.Result) .Concat( creatorQuery.Result .Where(issue => issue.PullRequest != null)) .GroupBy(issue => issue.Url) .Select(g => g.First()) .Select(issue => new InvolvedIssue { Issue = issue, Repo = repo }); }
public async Task<IReadOnlyList<Issue>> GetClosedIssues() { var request = new RepositoryIssueRequest(); request.State = ItemState.Closed; request.SortProperty = IssueSort.Created; request.SortDirection = SortDirection.Ascending; try { return await _github.Issue.GetAllForRepository(_organization, _repository, request); } catch (Exception ex) { Console.WriteLine("Failed to get issues for repository, {0}", ex.Message); } return new List<Issue>(); }
public async Task<ActionResult> Area(string areaLabel = "") { var client = CreateClient(); var request = new RepositoryIssueRequest(); request.Labels.Add(areaLabel); request.State = ItemState.Open; request.Milestone = "4"; var issues = await client.Issue.GetAllForRepository("dotnet", "roslyn", request); var model = new IssuesViewModel(); foreach (var issue in issues) { var name = issue?.Assignee?.Login ?? "unassigned"; model.Issues.Add(new IssueData() { Id = issue.Number, User = name }); } return View(model); }
internal static async Task Go() { var items = File.ReadAllText(@"c:\users\jaredpar\jenkins.txt").Trim().Split(':'); var credentials = new Credentials(items[1]); var client = new GitHubClient(new ProductHeaderValue("jaredpar-api-test")); client.Connection.Credentials = credentials; var request = new RepositoryIssueRequest(); request.Labels.Add("Area-Compilers"); request.State = ItemState.Open; request.Milestone = "4"; var issues = await client.Issue.GetAllForRepository("dotnet", "roslyn", request); foreach (var issue in issues) { var name = issue.User.Name ?? "unassigned"; Console.WriteLine(issue.Url); } }
public static async Task<IEnumerable<Issue>> AllIssuesForMilestone(this GitHubClient gitHubClient, Milestone milestone) { var closedIssueRequest = new RepositoryIssueRequest { Milestone = milestone.Number.ToString(CultureInfo.InvariantCulture), State = ItemState.Closed }; var openIssueRequest = new RepositoryIssueRequest { Milestone = milestone.Number.ToString(CultureInfo.InvariantCulture), State = ItemState.Open }; var parts = milestone.Url.AbsolutePath.Split('/'); var user = parts[2]; var repository = parts[3]; var closedIssues = await gitHubClient.Issue.GetForRepository(user, repository, closedIssueRequest); var openIssues = await gitHubClient.Issue.GetForRepository(user, repository, openIssueRequest); return openIssues.Union(closedIssues); }
private static async void GetChangelog() { try { var shouldPrioritize = new RepositoryIssueRequest { Filter = IssueFilter.All, State = ItemStateFilter.Closed, }; var issues = await client.Issue.GetAllForRepository(options.Organization, options.Repo, shouldPrioritize); Dictionary<string, List<Issue>> labelSet = new Dictionary<string, List<Issue>>(); foreach (var issue in issues) { if (issue.Milestone?.Title == options.Milestone) { issuesList.Add(issue); foreach (var label in issue.Labels) { if (label.Name.Contains("Type")) { if (labelSet.ContainsKey(label.Name) && !label.Name.Contains("ClosedAs:External")) { labelSet[label.Name].Add(issue); continue; } labelSet.Add(label.Name, new List<Issue>() { issue }); } } } } GenerateMarkdown(labelSet); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }
public override async void GetIssues() { if (_gettingIssues) return; _gettingIssues = true; AllIssues.Clear(); OnPropertyChanged("Issues"); var wrapper = Repository; if (wrapper != null && wrapper.Repository != null) { var repository = wrapper.Repository; var request = new RepositoryIssueRequest(); request.State = ItemState.Open; request.Filter = IssueFilter.All; await GetIssues(repository.Owner.Login, repository.Name, request); } _gettingIssues = false; }
private async Task GetIssues(string owner, string name, RepositoryIssueRequest request) { _log.Write(LogLevel.Debug, "Fetching issues for {0}/{1}", owner, name); try { var issues = await _github.Issue.GetAllForRepository(owner, name, request); foreach (var issue in issues) { AllIssues.Add(issue); } } catch (Exception ex) { _log.Write(LogLevel.Warn, "Failed to fetch issues", ex); } OnPropertyChanged("Issues"); }
public async Task CanRetrieveAllIssues() { var newIssue1 = new NewIssue("A test issue1") { Body = "A new unassigned issue" }; var newIssue2 = new NewIssue("A test issue2") { Body = "A new unassigned issue" }; var newIssue3 = new NewIssue("A test issue3") { Body = "A new unassigned issue" }; var newIssue4 = new NewIssue("A test issue4") { Body = "A new unassigned issue" }; var issue1 = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue1); var issue2 = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue2); var issue3 = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue3); var issue4 = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue4); await _issuesClient.Update(_context.RepositoryOwner, _context.RepositoryName, issue4.Number, new IssueUpdate { State = ItemState.Closed }); var request = new RepositoryIssueRequest { State = ItemStateFilter.All }; var retrieved = await _issuesClient.GetAllForRepository(_context.RepositoryOwner, _context.RepositoryName, request); Assert.Equal(4, retrieved.Count); Assert.True(retrieved.Any(i => i.Number == issue1.Number)); Assert.True(retrieved.Any(i => i.Number == issue2.Number)); Assert.True(retrieved.Any(i => i.Number == issue3.Number)); Assert.True(retrieved.Any(i => i.Number == issue4.Number)); }
/// <summary> /// Gets issues for a repository. /// </summary> /// <remarks> /// http://developer.github.com/v3/issues/#list-issues-for-a-repository /// </remarks> /// <param name="owner">The owner of the repository</param> /// <param name="name">The name of the repository</param> /// <param name="request">Used to filter and sort the list of issues returned</param> /// <param name="options">Options for changing the API response</param> public Task <IReadOnlyList <Issue> > GetAllForRepository(string owner, string name, RepositoryIssueRequest request, ApiOptions options) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNull(request, "request"); Ensure.ArgumentNotNull(options, "options"); return(ApiConnection.GetAll <Issue>(ApiUrls.Issues(owner, name), request.ToParametersDictionary(), AcceptHeaders.ReactionsPreview, options)); }
/// <summary> /// Gets issues for a repository. /// </summary> /// <remarks> /// http://developer.github.com/v3/issues/#list-issues-for-a-repository /// </remarks> /// <param name="repositoryId">The Id of the repository</param> /// <param name="request">Used to filter and sort the list of issues returned</param> public Task <IReadOnlyList <Issue> > GetAllForRepository(int repositoryId, RepositoryIssueRequest request) { Ensure.ArgumentNotNull(request, "request"); return(GetAllForRepository(repositoryId, request, ApiOptions.None)); }
/// <summary> /// Gets issues for a repository. /// </summary> /// <remarks> /// http://developer.github.com/v3/issues/#list-issues-for-a-repository /// </remarks> /// <param name="owner">The owner of the repository</param> /// <param name="name">The name of the repository</param> /// <param name="request">Used to filter and sort the list of issues returned</param> /// <param name="options">Options for changing the API response</param> /// <returns>The created <see cref="Task"/> representing requesting a list of issue from the API.</returns> public Task<IReadOnlyList<Issue>> GetAllForRepository(string owner, string name, RepositoryIssueRequest request, ApiOptions options) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNull(request, "request"); Ensure.ArgumentNotNull(options, "options"); return ApiConnection.GetAll<Issue>(ApiUrls.Issues(owner, name), request.ToParametersDictionary(), options); }
private async static Task downloadIssues() { var issueRequest = new RepositoryIssueRequest { State = ItemState.All, SortDirection = SortDirection.Ascending, SortProperty = IssueSort.Created, }; var issues = await _gitHub.Issue.GetAllForRepository(_owner, _repo, issueRequest); List<ExpandoObject> myIssueData = new List<ExpandoObject>(); Console.WriteLine("Issues:"); foreach (var issue in issues) { dynamic issueData = new ExpandoObject(); var relatedIssues = new List<string>(); issueData.htmlUrl = issue.HtmlUrl; issueData.number = issue.Number; issueData.createdAt = issue.CreatedAt; issueData.title = issue.Title; issueData.submitter = issue.User.Login; issueData.body = issue.Body; Console.WriteLine($"{issue.Number} - {issue.Title}"); // Add linked issues: from title if (!String.IsNullOrEmpty(issue.Title)) { var matchingIssues = _issueRegex.Matches(issue.Title); foreach (var m in matchingIssues) { try { var match = ((Match)m).Groups[1].Captures[0]; relatedIssues.Add(match.ToString()); } catch { } } } // Add linked issues: from body if (!String.IsNullOrEmpty(issue.Body)) { var matchingIssues = _issueRegex.Matches(issue.Body); foreach (var m in matchingIssues) { try { var match = ((Match)m).Groups[1].Captures[0]; relatedIssues.Add(match.ToString()); } catch { } } } // Add linked issues: from comments var issueDiscussion = await _gitHub.Issue.Comment.GetAllForIssue(_owner, _repo, issue.Number); foreach (var discussion in issueDiscussion) { if (String.IsNullOrEmpty(discussion.Body)) continue; var matchingCommentIssues = _issueRegex.Matches(discussion.Body); foreach (var m in matchingCommentIssues) { try { var match = ((Match)m).Groups[1].Captures[0]; relatedIssues.Add(match.ToString()); } catch { } } } issueData.relatedIssues = relatedIssues; myIssueData.Add(issueData); } var json = JsonConvert.SerializeObject(myIssueData); var outputPath = Path.Combine(_targetPath, "issues.json"); File.WriteAllText(outputPath, json); }
public async Task CanRetrieveAllIssuesWithApiOptionsWithStartWithRepositoryId() { var newIssue1 = new NewIssue("A test issue1") { Body = "A new unassigned issue" }; var newIssue2 = new NewIssue("A test issue2") { Body = "A new unassigned issue" }; var newIssue3 = new NewIssue("A test issue3") { Body = "A new unassigned issue" }; var newIssue4 = new NewIssue("A test issue4") { Body = "A new unassigned issue" }; await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue1); await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue2); await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue3); var issue4 = await _issuesClient.Create(_context.Repository.Id, newIssue4); await _issuesClient.Update(_context.Repository.Id, issue4.Number, new IssueUpdate { State = ItemState.Closed }); var request = new RepositoryIssueRequest { State = ItemStateFilter.All, SortDirection = SortDirection.Ascending }; var options = new ApiOptions { PageSize = 1, PageCount = 1, StartPage = 4 }; var retrieved = await _issuesClient.GetAllForRepository(_context.Repository.Id, request, options); Assert.Equal(1, retrieved.Count); Assert.True(retrieved.Any(i => i.Number == issue4.Number)); }
async Task Check(GitHubClient client, IResponse response, string name) { var issueFilter = new RepositoryIssueRequest { State = ItemState.Closed, Since = DateTimeOffset.Parse("2014-11-01") //cutoff date }; issueFilter.Labels.Add("Type: Bug"); var bugs = await client.Issue.GetAllForRepository("Particular", name, issueFilter); foreach (var bug in bugs) { if (bug.Milestone == null) { continue; } if (bug.Milestone.State == ItemState.Closed) { continue; } var hasAffected = bug.Body.Contains("## Who's affected"); var hasSymptoms = bug.Body.Contains("## Symptoms"); if (hasAffected && hasSymptoms) { continue; } //todo: need to patch octokit to support ClosedBy var events = await client.Issue.Events.GetAllForIssue("Particular", name, bug.Number); var closedEvent = events.First(e => e.Event == EventInfoState.Closed); var userThatClosedTheIssue = closedEvent.Actor.Login; string introText; var chatUsername = Brain.Get<CredentialStore>() .Where(s => s.Credentials.Any(credential => credential.Name == "github-username" && credential.Value == userThatClosedTheIssue)) .Select(c => c.Username) .SingleOrDefault(); if (chatUsername == null) { introText = $"Hi @channel! The github user {userThatClosedTheIssue} closed this issue and I can't seem to find what slack username that maps to. Would you please remind the user that"; } else { introText = $"Hi there @{chatUsername}! I've seen that"; } await response.Send($"{introText} this bug is missing some mandatory sections. Please head over to {bug.HtmlUrl} and update it! Read more on required sections here: {"https://github.com/Particular/Housekeeping/wiki/Required-sections-for-bugs"}").IgnoreWaitContext(); if (chatUsername == null) { await response.Send(string.Format("Do you know has the GitHub username {0} ? Do me a favor and ask them to register their username using: `pbot register credential github-username={0}` so that I can get in touch with them. Thanks!", userThatClosedTheIssue)); } } }
/// <summary> /// Gets issues for a repository. /// </summary> /// <remarks> /// http://developer.github.com/v3/issues/#list-issues-for-a-repository /// </remarks> /// <param name="repositoryId">The Id of the repository</param> /// <param name="request">Used to filter and sort the list of issues returned</param> /// <param name="options">Options for changing the API response</param> public Task<IReadOnlyList<Issue>> GetAllForRepository(long repositoryId, RepositoryIssueRequest request, ApiOptions options) { Ensure.ArgumentNotNull(request, "request"); Ensure.ArgumentNotNull(options, "options"); return ApiConnection.GetAll<Issue>(ApiUrls.Issues(repositoryId), request.ToParametersDictionary(), AcceptHeaders.ReactionsPreview, options); }
/// <summary> /// Gets issues for a repository. /// </summary> /// <remarks> /// http://developer.github.com/v3/issues/#list-issues-for-a-repository /// </remarks> /// <param name="repositoryId">The Id of the repository</param> /// <param name="request">Used to filter and sort the list of issues returned</param> public Task<IReadOnlyList<Issue>> GetAllForRepository(long repositoryId, RepositoryIssueRequest request) { Ensure.ArgumentNotNull(request, "request"); return GetAllForRepository(repositoryId, request, ApiOptions.None); }
/// <summary> /// Gets issues for a repository. /// </summary> /// <remarks> /// http://developer.github.com/v3/issues/#list-issues-for-a-repository /// </remarks> /// <param name="owner">The owner of the repository</param> /// <param name="name">The name of the repository</param> /// <param name="request">Used to filter and sort the list of issues returned</param> /// <returns>The created <see cref="Task"/> representing requesting a list of issue from the API.</returns> public Task<IReadOnlyList<Issue>> GetAllForRepository(string owner, string name, RepositoryIssueRequest request) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNull(request, "request"); return GetAllForRepository(owner, name, request, ApiOptions.None); }
/// <summary> /// Gets issues for a repository. /// </summary> /// <remarks> /// http://developer.github.com/v3/issues/#list-issues-for-a-repository /// </remarks> /// <param name="owner">The owner of the repository</param> /// <param name="name">The name of the repository</param> /// <param name="request">Used to filter and sort the list of issues returned</param> public Task <IReadOnlyList <Issue> > GetAllForRepository(string owner, string name, RepositoryIssueRequest request) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNull(request, "request"); return(GetAllForRepository(owner, name, request, ApiOptions.None)); }
private Task<IReadOnlyList<Issue>> GetIssuesForRepo(string repo, GitHubClient gitHubClient) { var repositoryIssueRequest = new RepositoryIssueRequest { State = ItemState.Open, }; repositoryIssueRequest.Labels.Add("2 - Working"); return gitHubClient.Issue.GetAllForRepository("aspnet", repo, repositoryIssueRequest); }
public async Task CanRetrieveAllIssuesReturnsDistinctReulstsBasedOnApiOptions() { var newIssue1 = new NewIssue("A test issue1") { Body = "A new unassigned issue" }; var newIssue2 = new NewIssue("A test issue2") { Body = "A new unassigned issue" }; var newIssue3 = new NewIssue("A test issue3") { Body = "A new unassigned issue" }; var newIssue4 = new NewIssue("A test issue4") { Body = "A new unassigned issue" }; await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue1); await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue2); await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue3); var issue4 = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue4); await _issuesClient.Update(_context.RepositoryOwner, _context.RepositoryName, issue4.Number, new IssueUpdate { State = ItemState.Closed }); var request = new RepositoryIssueRequest { State = ItemStateFilter.All }; var firstOptions = new ApiOptions { PageSize = 2, PageCount = 1, StartPage = 1 }; var firstPage = await _issuesClient.GetAllForRepository(_context.RepositoryOwner, _context.RepositoryName, request, firstOptions); var secondOptions = new ApiOptions { PageSize = 2, PageCount = 1, StartPage = 2 }; var secondPage = await _issuesClient.GetAllForRepository(_context.RepositoryOwner, _context.RepositoryName, request, secondOptions); Assert.Equal(2, firstPage.Count); Assert.Equal(2, secondPage.Count); Assert.NotEqual(firstPage[0].Number, secondPage[0].Number); Assert.NotEqual(firstPage[1].Number, secondPage[1].Number); }