public void HandlesStringAttributesCorrectly()
        {
            var stringProperties = new Dictionary<string, Action<SearchIssuesRequest, string>>
            {
                { "author:", (x,value) => x.Author = value },
                { "assignee:", (x,value) => x.Assignee = value },
                { "mentions:", (x,value) => x.Mentions = value },
                { "commenter:", (x,value) => x.Commenter = value },
                { "involves:", (x,value) => x.Involves = value },
                { "team:", (x,value) => x.Team = value },
                { "head:", (x,value) => x.Head = value },
                { "base:", (x,value) => x.Base = value },
                { "user:"******"query");

                // Ensure the specified parameter does not exist when not set
                Assert.False(request.MergedQualifiers().Any(x => x.Contains(property.Key)));

                // Set the parameter
                property.Value(request, "blah");

                // Ensure the specified parameter now exists
                Assert.True(request.MergedQualifiers().Count(x => x.Contains(property.Key)) == 1);
            }
        }
        public void ReturnsAReadOnlyDictionary()
        {
            var request = new SearchIssuesRequest("test");

            var result = request.MergedQualifiers();

            // If I can cast this to a writeable collection, then that defeats the purpose of a read only.
            AssertEx.IsReadOnlyCollection<string>(result);
        }
    public async Task SearchForOpenIssues()
    {
        var request = new SearchIssuesRequest("phone");
        request.Repo = "caliburn-micro/caliburn.micro";
        request.State = ItemState.Open;

        var issues = await _gitHubClient.Search.SearchIssues(request);

        Assert.NotEmpty(issues.Items);
    }
    public async Task SearchForWordInCode()
    {
        var request = new SearchIssuesRequest("windows");
        request.SortField = IssueSearchSort.Created;
        request.Order = SortDirection.Descending;

        var repos = await _gitHubClient.Search.SearchIssues(request);

        Assert.NotEmpty(repos.Items);
    }
Beispiel #5
0
        public override async Task Execute(string[] parameters, IResponse response)
        {
            var client = GitHubClientBuilder.Build();

            await response.Send("Looking for stale issues I am ...");

            var searchRequest = new SearchIssuesRequest
            {
                User = "******",
                Labels = new[] { parameters[1], $"\"{InProgressLabel}\"" },
                SortField = IssueSearchSort.Updated,
                State = ItemState.Open
            };
            var searchResults = await client.Search.SearchIssues(searchRequest);

            if (searchResults.TotalCount == 0)
            {
                await response.Send($"No stale issues found for tag `{parameters[1]}`.");
                return;
            }

            foreach (var issue in searchResults.Items)
            {
                var repositoryName = issue.CommentsUrl.AbsolutePath.Split('/')[3];

                var comments = await client.Issue.Comment.GetAllForIssue("Particular", repositoryName, issue.Number);
                var latestComment = comments.OrderByDescending(c => c.CreatedAt).FirstOrDefault();

                var events = await client.Issue.Events.GetAllForIssue("Particular", repositoryName, issue.Number);
                var movedToInProgress = events.Last(e => e.Label != null && e.Label.Name == InProgressLabel);

                var stalenessThreshold = DateTime.UtcNow.Subtract(StalenessPeriod);

                if (issue.CreatedAt > stalenessThreshold)
                {
                    continue;
                }

                if (latestComment != null && latestComment.CreatedAt > stalenessThreshold)
                {
                    continue;
                }

                if (movedToInProgress.CreatedAt > stalenessThreshold)
                {
                    continue;
                }

                await response.Send(issue.HtmlUrl.ToString());
            }

            await response.Send("Done.");
        }
    public async Task SearchForAllIssues()
    {
        var request = new SearchIssuesRequest("phone");
        request.Repo = "caliburn-micro/caliburn.micro";

        var issues = await _gitHubClient.Search.SearchIssues(request);

        var closedIssues = issues.Items.Where(x => x.State == ItemState.Closed);
        var openedIssues = issues.Items.Where(x => x.State == ItemState.Open);

        Assert.NotEmpty(closedIssues);
        Assert.NotEmpty(openedIssues);
    }
        public void HandlesDateRangeAttributesCorrectly()
        {
            var dateProperties = new Dictionary<string, Action<SearchIssuesRequest, DateRange>>
            {
                { "created:", (x,value) => x.Created = value },
                { "updated:", (x,value) => x.Updated = value },
                { "merged:", (x,value) => x.Merged = value },
                { "closed:", (x,value) => x.Closed = value }
            };

            foreach (var property in dateProperties)
            {
                var request = new SearchIssuesRequest("query");

                // Ensure the specified parameter does not exist when not set
                Assert.False(request.MergedQualifiers().Any(x => x.Contains(property.Key)));

                // Set the parameter
                property.Value(request, DateRange.GreaterThan(DateTime.Today.AddDays(-7)));

                // Ensure the specified parameter now exists
                Assert.True(request.MergedQualifiers().Count(x => x.Contains(property.Key)) == 1);
            }
        }
    public async Task SearchForExcludedStatus()
    {
        var status = CommitState.Success;

        // Search for issues by include filter
        var request = new SearchIssuesRequest();
        request.Repos.Add("octokit", "octokit.net");
        request.Status = status;

        var issues = await _gitHubClient.Search.SearchIssues(request);

        // Ensure we found issues
        Assert.NotEmpty(issues.Items);

        // Search for issues by exclude filter
        var excludeRequest = new SearchIssuesRequest();
        excludeRequest.Repos.Add("octokit", "octokit.net");
        excludeRequest.Exclusions = new SearchIssuesRequestExclusions
        {
            Status = status
        };

        var otherIssues = await _gitHubClient.Search.SearchIssues(excludeRequest);

        // Ensure we found issues
        Assert.NotEmpty(otherIssues.Items);

        // Ensure no items from the first search are in the results for the second
        Assert.DoesNotContain(issues.Items, x1 => otherIssues.Items.Any(x2 => x2.Id == x1.Id));
    }
    public async Task SearchForExcludedLabels()
    {
        var label1 = "up-for-grabs";
        var label2 = "feature";

        // Search for issues by include filter
        var request = new SearchIssuesRequest();
        request.Repos.Add("octokit", "octokit.net");
        request.Labels = new[] { label1, label2 };

        var issues = await _gitHubClient.Search.SearchIssues(request);

        // Ensure we found issues
        Assert.NotEmpty(issues.Items);

        // Search for issues by exclude filter
        var excludeRequest = new SearchIssuesRequest();
        excludeRequest.Repos.Add("octokit", "octokit.net");
        excludeRequest.Exclusions = new SearchIssuesRequestExclusions
        {
            Labels = new[] { label1, label2 }
        };

        var otherIssues = await _gitHubClient.Search.SearchIssues(excludeRequest);

        // Ensure we found issues
        Assert.NotEmpty(otherIssues.Items);

        // Ensure no items from the first search are in the results for the second
        Assert.DoesNotContain(issues.Items, x1 => otherIssues.Items.Any(x2 => x2.Id == x1.Id));
    }
    public async Task SearchForExcludedLanguage()
    {
        var language = Language.CSharp;

        // Search for issues by include filter
        var request = new SearchIssuesRequest("octokit");
        request.Language = language;

        var issues = await _gitHubClient.Search.SearchIssues(request);

        // Ensure we found issues
        Assert.NotEmpty(issues.Items);

        // Search for issues by exclude filter
        var excludeRequest = new SearchIssuesRequest("octokit");
        excludeRequest.Exclusions = new SearchIssuesRequestExclusions
        {
            Language = language
        };

        var otherIssues = await _gitHubClient.Search.SearchIssues(excludeRequest);

        // Ensure we found issues
        Assert.NotEmpty(otherIssues.Items);

        // Ensure no items from the first search are in the results for the second
        Assert.DoesNotContain(issues.Items, x1 => otherIssues.Items.Any(x2 => x2.Id == x1.Id));
    }
    public async Task SearchForMergedPullRequests()
    {
        var allRequest = new SearchIssuesRequest();
        allRequest.Repos.Add("octokit", "octokit.net");
        allRequest.Type = IssueTypeQualifier.PullRequest;

        var mergedRequest = new SearchIssuesRequest();
        mergedRequest.Repos.Add("octokit", "octokit.net");
        mergedRequest.Is = new List<IssueIsQualifier> { IssueIsQualifier.PullRequest, IssueIsQualifier.Merged };

        var allPullRequests = await _gitHubClient.Search.SearchIssues(allRequest);
        var mergedPullRequests = await _gitHubClient.Search.SearchIssues(mergedRequest);

        Assert.NotEmpty(allPullRequests.Items);
        Assert.NotEmpty(mergedPullRequests.Items);
        Assert.NotEqual(allPullRequests.TotalCount, mergedPullRequests.TotalCount);
    }
    public async Task SearchForMissingMetadata()
    {
        var allRequest = new SearchIssuesRequest();
        allRequest.Repos.Add("octokit", "octokit.net");

        var noAssigneeRequest = new SearchIssuesRequest();
        noAssigneeRequest.Repos.Add("octokit", "octokit.net");
        noAssigneeRequest.No = IssueNoMetadataQualifier.Assignee;

        var allIssues = await _gitHubClient.Search.SearchIssues(allRequest);
        var noAssigneeIssues = await _gitHubClient.Search.SearchIssues(noAssigneeRequest);

        Assert.NotEmpty(allIssues.Items);
        Assert.NotEmpty(noAssigneeIssues.Items);
        Assert.NotEqual(allIssues.TotalCount, noAssigneeIssues.TotalCount);
    }
        public void HandlesStateAttributeCorrectly()
        {
            var request = new SearchIssuesRequest("test");
            Assert.False(request.MergedQualifiers().Any(x => x.Contains("state:")));

            request.State = ItemState.Closed;
            Assert.True(request.MergedQualifiers().Contains("state:closed"));
        }
    public async Task SearchForAllIssues()
    {
        var request = new SearchIssuesRequest("phone");
        request.Repos.Add("caliburn-micro", "caliburn.micro");

        var issues = await _gitHubClient.Search.SearchIssues(request);

        Assert.NotEmpty(issues.Items);
    }
        public void HandlesNoMetadataAttributeCorrectly()
        {
            var request = new SearchIssuesRequest("test");
            Assert.False(request.MergedQualifiers().Any(x => x.Contains("no:")));

            request.No = IssueNoMetadataQualifier.Milestone;
            Assert.True(request.MergedQualifiers().Contains("no:milestone"));
        }
        public void HandlesLabelsAttributeCorrectly()
        {
            var request = new SearchIssuesRequest("test");
            Assert.False(request.MergedQualifiers().Any(x => x.Contains("label:")));

            request.Labels = new[] { "label1", "label2" };
            Assert.True(request.MergedQualifiers().Contains("label:label1"));
            Assert.True(request.MergedQualifiers().Contains("label:label2"));
        }
 public void SortNotSpecifiedByDefault()
 {
     var request = new SearchIssuesRequest("test");
     Assert.True(string.IsNullOrWhiteSpace(request.Sort));
     Assert.False(request.Parameters.ContainsKey("sort"));
 }
    public async Task SearchForExcludedBase()
    {
        var branch = "master";

        // Search for issues by target branch
        var request = new SearchIssuesRequest();
        request.Repos.Add("octokit", "octokit.net");
        request.Base = branch;

        var issues = await _gitHubClient.Search.SearchIssues(request);

        // Ensure we found issues
        Assert.NotEmpty(issues.Items);

        // Search for issues excluding target branch
        var excludeRequest = new SearchIssuesRequest();
        excludeRequest.Repos.Add("octokit", "octokit.net");
        excludeRequest.Exclusions = new SearchIssuesRequestExclusions
        {
            Base = branch
        };

        var otherIssues = await _gitHubClient.Search.SearchIssues(excludeRequest);

        // Ensure we found issues
        Assert.NotEmpty(otherIssues.Items);

        // Ensure no items from the first search are in the results for the second
        Assert.DoesNotContain(issues.Items, x1 => otherIssues.Items.Any(x2 => x2.Id == x1.Id));
    }
        public void HandlesRepoAttributeCorrectly()
        {
            var request = new SearchIssuesRequest("test");
            Assert.False(request.MergedQualifiers().Any(x => x.Contains("repo:")));

            request.Repos.Add("myorg", "repo1");
            request.Repos.Add("myorg", "repo2");
            Assert.True(request.MergedQualifiers().Contains("repo:myorg/repo1"));
            Assert.True(request.MergedQualifiers().Contains("repo:myorg/repo2"));
        }
        public void HandlesCommentsAttributeCorrectly()
        {
            var request = new SearchIssuesRequest("test");
            Assert.False(request.MergedQualifiers().Any(x => x.Contains("comments:")));

            request.Comments = Range.GreaterThan(5);
            Assert.True(request.MergedQualifiers().Contains("comments:>5"));
        }
        public void HandlesStatusAttributeCorrectly()
        {
            var request = new SearchIssuesRequest("test");
            Assert.False(request.MergedQualifiers().Any(x => x.Contains("status:")));

            request.Status = CommitState.Error;
            Assert.True(request.MergedQualifiers().Contains("status:error"));
        }
        public void HandlesIsAttributeCorrectly()
        {
            var request = new SearchIssuesRequest("test");
            Assert.False(request.MergedQualifiers().Any(x => x.Contains("is:")));

            request.Is = new List<IssueIsQualifier> { IssueIsQualifier.Merged, IssueIsQualifier.PullRequest };
            Assert.True(request.MergedQualifiers().Contains("is:merged"));
            Assert.True(request.MergedQualifiers().Contains("is:pr"));
        }
        public void HandlesLanguageAttributeCorrectly()
        {
            var request = new SearchIssuesRequest("test");
            Assert.False(request.MergedQualifiers().Any(x => x.Contains("language:")));

            request.Language = Language.CSharp;
            Assert.True(request.MergedQualifiers().Contains("language:C#"));
        }
 public Task <SearchIssuesResult> SearchIssues(SearchIssuesRequest search)
 {
     Ensure.ArgumentNotNull(search, nameof(search));
     return(ApiConnection.Get <SearchIssuesResult>(ApiUrls.SearchIssues(), search.Parameters));
 }
Beispiel #25
0
        public async Task<ActionResult> Stats()
        {
            var vm = new StatsViewModel();

            var issueSearch = new SearchIssuesRequest
            {
                Comments = Range.GreaterThan(25),
                Created = DateRange.GreaterThan(new DateTime(DateTime.Now.Year, 01, 01)),
                SortField = IssueSearchSort.Comments,
                Language = Language.Ruby,
                Order = SortDirection.Descending
            };
            var mostCommented = await _githubClient.Search.SearchIssues(issueSearch);
            vm.MostCommentedIssue = mostCommented.Items.OrderByDescending(x=> x.Comments).Take(10).ToList();

            var repoSearch = new SearchRepositoriesRequest
            {
                Created = DateRange.GreaterThan(new DateTime(DateTime.Now.Year, 01, 01)),
                Language = Language.CSharp,
                SortField = RepoSearchSort.Stars,
                Order = SortDirection.Descending
            };
            var mostStarred = await _githubClient.Search.SearchRepo(repoSearch);
            vm.MostStarred = mostStarred.Items.Take(10).ToList();

            var repo = new RepositoryCollection();
            repo.Add("rails", "rails");
            issueSearch = new SearchIssuesRequest
            {
                 Repos = repo,
                 Created = DateRange.GreaterThan(new DateTime(DateTime.Now.Year, 01, 01)),
            };
            var railsIssues = await _githubClient.Search.SearchIssues(issueSearch);
            var dic = new Dictionary<DayOfWeek, List<Issue>>();
            foreach (var issue in railsIssues.Items)
            {
                if(dic.ContainsKey(issue.CreatedAt.DayOfWeek))
                {
                    dic[issue.CreatedAt.DayOfWeek].Add(issue);
                }
                else
                {
                    dic.Add(issue.CreatedAt.DayOfWeek, new List<Issue> { issue });
                }
            }

            vm.RailsIssues = dic;

            return View(vm);
        }
        public void HandlesInAttributeCorrectly()
        {
            var request = new SearchIssuesRequest("test");
            Assert.False(request.MergedQualifiers().Any(x => x.Contains("in:")));

            request.In = new List<IssueInQualifier> { IssueInQualifier.Body, IssueInQualifier.Comment };
            Assert.True(request.MergedQualifiers().Contains("in:body,comment"));
        }
Beispiel #27
0
 /// <summary>
 /// search issues
 /// http://developer.github.com/v3/search/#search-issues
 /// </summary>
 /// <param name="search"></param>
 /// <returns>List of issues</returns>
 public Task<SearchIssuesResult> SearchIssues(SearchIssuesRequest search)
 {
     Ensure.ArgumentNotNull(search, "search");
     return ApiConnection.Get<SearchIssuesResult>(ApiUrls.SearchIssues(), search.Parameters);
 }
 /// <summary>
 /// search issues
 /// http://developer.github.com/v3/search/#search-issues
 /// </summary>
 /// <param name="search"></param>
 /// <returns>List of issues</returns>
 public Task <IReadOnlyList <Issue> > SearchIssues(SearchIssuesRequest search)
 {
     Ensure.ArgumentNotNull(search, "search");
     return(ApiConnection.GetAll <Issue>(ApiUrls.SearchIssues(), search.Parameters));
 }
Beispiel #29
0
 /// <summary>
 /// search issues
 /// http://developer.github.com/v3/search/#search-issues
 /// </summary>
 /// <param name="search"></param>
 /// <returns>List of issues</returns>
 public Task<IReadOnlyList<Issue>> SearchIssues(SearchIssuesRequest search)
 {
     Ensure.ArgumentNotNull(search, "search");
     return ApiConnection.GetAll<Issue>(ApiUrls.SearchIssues(), search.Parameters);
 }