Ejemplo n.º 1
0
        protected override async void GetMilestones()
        {
            Milestones.Clear();
            Milestone = null;
            if (Repository != null && Repository.Repository != null)
            {
                Milestones.Add(AllMilestones);
                Milestones.Add(NoMilestone);
                var request = new MilestoneRequest();
                request.State         = ItemState.Open;
                request.SortProperty  = MilestoneSort.DueDate;
                request.SortDirection = SortDirection.Ascending;
                try
                {
                    var milestones = await _github.Issue.Milestone.GetForRepository(Repository.Repository.Owner.Login, Repository.Repository.Name, request);

                    foreach (var milestone in milestones)
                    {
                        Milestones.Add(milestone);
                    }

                    Milestone = AllMilestones;
                }
                catch (Exception exception)
                {
                    _log.Write(LogLevel.Warn, "Failed to get milestones for repository", exception);
                }
            }
        }
        /// <summary>
        /// Gets all open milestones for the repository.
        /// </summary>
        /// <remarks>
        /// http://developer.github.com/v3/issues/milestones/#list-milestones-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 Milestones returned</param>
        /// <returns></returns>
        public IObservable<Milestone> GetAllForRepository(string owner, string name, MilestoneRequest request)
        {
            Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
            Ensure.ArgumentNotNullOrEmptyString(name, "name");
            Ensure.ArgumentNotNull(request, "request");

            return GetAllForRepository(owner, name, request, ApiOptions.None);
        }
        /// <summary>
        /// Gets all open milestones for the repository.
        /// </summary>
        /// <remarks>
        /// http://developer.github.com/v3/issues/milestones/#list-milestones-for-a-repository
        /// </remarks>
        /// <param name="repositoryId">The Id of the repository</param>
        /// <param name="request">Used to filter and sort the list of Milestones returned</param>
        /// <param name="options">Options for changing the API response</param>
        /// <returns></returns>
        public IObservable <Milestone> GetAllForRepository(int repositoryId, MilestoneRequest request, ApiOptions options)
        {
            Ensure.ArgumentNotNull(request, "request");
            Ensure.ArgumentNotNull(options, "options");

            return(_connection.GetAndFlattenAllPages <Milestone>(ApiUrls.Milestones(repositoryId),
                                                                 request.ToParametersDictionary(), options));
        }
Ejemplo n.º 4
0
        public async Task <IReadOnlyList <Milestone> > GetMilestones(RoachRepoId repoId)
        {
            var request = new MilestoneRequest()
            {
                State = ItemStateFilter.All
            };

            return(await _client.Issue.Milestone.GetAllForRepository(repoId.Owner, repoId.Name, request));
        }
        /// <summary>
        /// Gets all open milestones for the repository.
        /// </summary>
        /// <remarks>
        /// http://developer.github.com/v3/issues/milestones/#list-milestones-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 Milestones returned</param>
        /// <returns></returns>
        public IObservable <Milestone> GetForRepository(string owner, string name, MilestoneRequest request)
        {
            Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
            Ensure.ArgumentNotNullOrEmptyString(name, "name");
            Ensure.ArgumentNotNull(request, "request");

            return(_connection.GetAndFlattenAllPages <Milestone>(ApiUrls.Milestones(owner, name),
                                                                 request.ToParametersDictionary()));
        }
        /// <summary>
        /// Gets all open milestones for the repository.
        /// </summary>
        /// <remarks>
        /// http://developer.github.com/v3/issues/milestones/#list-milestones-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 Milestones returned</param>
        /// <returns></returns>
        public IObservable<Milestone> GetAllForRepository(string owner, string name, MilestoneRequest request)
        {
            Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
            Ensure.ArgumentNotNullOrEmptyString(name, "name");
            Ensure.ArgumentNotNull(request, "request");

            return _connection.GetAndFlattenAllPages<Milestone>(ApiUrls.Milestones(owner, name),
                request.ToParametersDictionary());
        }
Ejemplo n.º 7
0
        private static Task <IReadOnlyList <Milestone> > RequestMilestonesAsync(GitHubClientFactory factory, GitHubClient client, string org, string repo)
        {
            var request = new MilestoneRequest
            {
                State = ItemStateFilter.All
            };

            return(RetryOnRateLimiting(factory, client, () => client.Issue.Milestone.GetAllForRepository(org, repo, request)));
        }
Ejemplo n.º 8
0
        public void ReturnsDefaultValuesForDefaultRequest()
        {
            var request = new MilestoneRequest();

            var parameters = request.ToParametersDictionary();

            Assert.Equal("open", parameters["state"]);
            Assert.Equal("due_date", parameters["sort"]);
            Assert.Equal("asc", parameters["direction"]);
        }
            public void SendsAppropriateParameters()
            {
                var gitHubClient = Substitute.For<IGitHubClient>();
                var client = new ObservableMilestonesClient(gitHubClient);

                var milestoneRequest = new MilestoneRequest { SortDirection = SortDirection.Descending };
                client.GetAllForRepository("fake", "repo", milestoneRequest);

                gitHubClient.Received().Issue.Milestone.GetAllForRepository("fake", "repo", milestoneRequest, Args.ApiOptions);
            }
Ejemplo n.º 10
0
        private static async Task <Milestone> GetExistingMilestone(this IGitHubClient gitHubClient, string existingMilestoneTitle)
        {
            Console.WriteLine($"Fetching milestone '{existingMilestoneTitle}'...");
            var milestoneRequest = new MilestoneRequest {
                State = ItemStateFilter.Open
            };
            var existingMilestone = (await gitHubClient.Issue.Milestone.GetAllForRepository(RepoOwner, repoName, milestoneRequest))
                                    .Single(milestone => milestone.Title == existingMilestoneTitle);

            Console.WriteLine($"Fetched milestone '{existingMilestone.Title}'");
            return(existingMilestone);
        }
            public void SendsAppropriateParametersWithRepositoryId()
            {
                var gitHubClient = Substitute.For <IGitHubClient>();
                var client       = new ObservableMilestonesClient(gitHubClient);

                var milestoneRequest = new MilestoneRequest {
                    SortDirection = SortDirection.Descending
                };

                client.GetAllForRepository(1, milestoneRequest);

                gitHubClient.Received().Issue.Milestone.GetAllForRepository(1, milestoneRequest, Args.ApiOptions);
            }
Ejemplo n.º 12
0
        public void ContainsSetValues()
        {
            var request = new MilestoneRequest
            {
                State         = ItemState.Closed,
                SortProperty  = MilestoneSort.Completeness,
                SortDirection = SortDirection.Descending,
            };

            var parameters = request.ToParametersDictionary();

            Assert.Equal("closed", parameters["state"]);
            Assert.Equal("completeness", parameters["sort"]);
            Assert.Equal("desc", parameters["direction"]);
        }
Ejemplo n.º 13
0
        public async Task ReturnsDistinctResultsBasedOnStartPageParametrizedWithRepositoryId()
        {
            var milestone1 = new NewMilestone("milestone 1")
            {
                DueOn = DateTime.Now
            };
            var milestone2 = new NewMilestone("milestone 2")
            {
                DueOn = DateTime.Now.AddDays(1), State = ItemState.Closed
            };
            var milestone3 = new NewMilestone("milestone 3")
            {
                DueOn = DateTime.Now.AddDays(3), State = ItemState.Closed
            };
            await _milestonesClient.Create(_context.RepositoryOwner, _context.RepositoryName, milestone1);

            await _milestonesClient.Create(_context.RepositoryOwner, _context.RepositoryName, milestone2);

            await _milestonesClient.Create(_context.RepositoryOwner, _context.RepositoryName, milestone3);

            var milestoneRequest = new MilestoneRequest {
                State = ItemStateFilter.Closed
            };

            var startOptions = new ApiOptions
            {
                PageSize  = 1,
                PageCount = 1
            };

            var firstPage = await _milestonesClient.GetAllForRepository(_context.Repository.Id, milestoneRequest, startOptions);

            var skipStartOptions = new ApiOptions
            {
                PageSize  = 1,
                PageCount = 1,
                StartPage = 2
            };

            var secondPage = await _milestonesClient.GetAllForRepository(_context.Repository.Id, milestoneRequest, skipStartOptions);

            Assert.NotEqual(firstPage[0].Number, secondPage[0].Number);
        }
            public void SendsAppropriateParametersWithApiOptions()
            {
                var gitHubClient = Substitute.For <IGitHubClient>();
                var client       = new ObservableMilestonesClient(gitHubClient);

                var options = new ApiOptions
                {
                    PageCount = 1,
                    PageSize  = 1,
                    StartPage = 1
                };

                var milestoneRequest = new MilestoneRequest {
                    SortDirection = SortDirection.Descending
                };

                client.GetAllForRepository("fake", "repo", milestoneRequest, options);

                gitHubClient.Received().Issue.Milestone.GetAllForRepository("fake", "repo", milestoneRequest, options);
            }
Ejemplo n.º 15
0
 public async Task <MilestoneResponse> UpdateMilestoneAsync(string code, int id, MilestoneRequest milestoneRequest)
 {
     return(await _api.UpdateMilestone(_api_token, code, id, milestoneRequest));
 }
        /// <summary>
        /// Gets all open milestones for the repository.
        /// </summary>
        /// <remarks>
        /// http://developer.github.com/v3/issues/milestones/#list-milestones-for-a-repository
        /// </remarks>
        /// <param name="repositoryId">The Id of the repository</param>
        /// <param name="request">Used to filter and sort the list of Milestones returned</param>
        /// <returns></returns>
        public IObservable <Milestone> GetAllForRepository(int repositoryId, MilestoneRequest request)
        {
            Ensure.ArgumentNotNull(request, "request");

            return(GetAllForRepository(repositoryId, request, ApiOptions.None));
        }
        /// <summary>
        /// Gets all open milestones for the repository.
        /// </summary>
        /// <remarks>
        /// http://developer.github.com/v3/issues/milestones/#list-milestones-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 Milestones returned</param>
        /// <returns></returns>
        public IObservable <Milestone> GetAllForRepository(string owner, string name, MilestoneRequest request)
        {
            Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
            Ensure.ArgumentNotNullOrEmptyString(name, "name");
            Ensure.ArgumentNotNull(request, "request");

            return(GetAllForRepository(owner, name, request, ApiOptions.None));
        }
            public void SendsAppropriateParametersWithApiOptionsWithRepositoryId()
            {
                var gitHubClient = Substitute.For<IGitHubClient>();
                var client = new ObservableMilestonesClient(gitHubClient);

                var options = new ApiOptions
                {
                    PageCount = 1,
                    PageSize = 1,
                    StartPage = 1
                };

                var milestoneRequest = new MilestoneRequest { SortDirection = SortDirection.Descending };
                client.GetAllForRepository(1, milestoneRequest, options);

                gitHubClient.Received().Issue.Milestone.GetAllForRepository(1, milestoneRequest, options);
            }
Ejemplo n.º 19
0
        /// <summary>
        /// Gets all open milestones for the repository.
        /// </summary>
        /// <remarks>
        /// http://developer.github.com/v3/issues/milestones/#list-milestones-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 Milestones returned</param>
        /// <param name="options">Options for changing the API response</param>
        /// <returns></returns>
        public IObservable <Milestone> GetAllForRepository(string owner, string name, MilestoneRequest request, ApiOptions options)
        {
            Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
            Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
            Ensure.ArgumentNotNull(request, nameof(request));
            Ensure.ArgumentNotNull(options, nameof(options));

            return(_connection.GetAndFlattenAllPages <Milestone>(ApiUrls.Milestones(owner, name),
                                                                 request.ToParametersDictionary(), options));
        }
Ejemplo n.º 20
0
        // The incoming param values come (ultimately) come from parsing the incoming URL in QueryCountComponent in
        // count.component.ts.  The URLs could include milestones and/or labels.  Here, we have to translate the values
        // to GitHub/Octokit to get the desired result set.  There are some quirks that need clarification below...
        private async Task <IReadOnlyList <Issue> > GetIssuesAsync(string owner, string repository, string milestone, string labels, string excludedMilestone, string excludedLabels)
        {
            // First, for milestone.  The URL handled by the Angular app might not have a milestone query parameter so it
            // would look something like this:
            //    https://<host>/count/nuget/home?label=VS1ES
            // In that case, the angular app will set the milestone to "undefined" before calling this service, which will
            // receive a URL like:
            //    https://<host>/api/CountByMilestone/nuget/home/undefined/VS1ES
            // Map "undefined" and null/whitespace to `null` in the Octokit issue request.  This tells Octokit "don't
            // consider milestones in this query."  Then Octokit returns issues regardless of their milestone setting -
            // including issues with _no_ milestone setting.  The URL could have "milestone='*'" - the milestone parameter
            // will pass that value.  GitHub/Octokit treats milestone = '*' as "any _set_ milestone."  So Octokit would
            // return all issues that have any milestone setting of any value - as long as the issue has one is set.
            // However, with '*' it won't return issues that have NO milestone setting.  Finally, if the URL includes a
            // valid milestone (eg "milestone=15.8"), translate that string value into the corresponding milestone ID and
            // put that in the issue request...
            if (string.IsNullOrWhiteSpace(milestone) || milestone == "undefined")
            {
                milestone = null;
            }
            else if (milestone == "any" || milestone == "*")
            {
                milestone = "*";
            }
            else if (milestone != "none")
            {
                // This throws a KeyNotFoundException if the incoming milestone value doesn't exist in the repo's collection
                // of milestone values.  Catch it in the calling function...
                var milestonesClient = new MilestonesClient(new ApiConnection(_gitHubClient.Connection));
                var milestoneRequest = new MilestoneRequest {
                    State = ItemStateFilter.Open
                };
                var milestones = await milestonesClient.GetAllForRepository(owner, repository, milestoneRequest);

                var milestonesByName = milestones.ToDictionary(m => m.Title, m => m.Number);
                milestone = milestonesByName[milestone].ToString();
            }

            var issueRequest = new RepositoryIssueRequest
            {
                Milestone = milestone,
                State     = ItemStateFilter.Open,
            };

            // Second, for labels.  In GitHub, issues can have zero or more label values, and the incoming URL could specify a
            // query for multiple values.  Those URL values are passed to this function as a string of comma separated values.
            // No values in the URL results in labels param value of "undefined" (same as above for milestone); A URL value of
            // "label=test&label=VS1ES" results in "test,VS1ES" --> split those and add each value to the issue request
            // Labels collection...
            if (!string.IsNullOrWhiteSpace(labels) && (labels != "undefined"))
            {
                var labelvalues = labels.Split(',');
                foreach (var label in labelvalues)
                {
                    issueRequest.Labels.Add(label);
                }
            }

            // This could throw an ApiValidationException if the milestone doesn't exist in the repo.
            // Catch it in the calling function...
            var allIssues = await _gitHubClient.Issue.GetAllForRepository(owner, repository, issueRequest);

            var issues = allIssues.Where(i => i.PullRequest == null);

            // We now need to exclude the milestone
            if (!string.IsNullOrEmpty(excludedMilestone) && (excludedMilestone != "undefined"))
            {
                issues = issues.Where(i => i.Milestone == null || i.Milestone.Title != excludedMilestone);
            }

            // We now need to exclude all the issues that have labels that should be excluded
            if (!string.IsNullOrEmpty(excludedLabels) && (excludedLabels != "undefined"))
            {
                var filteredIssues      = new List <Issue>();
                var excludedLabelValues = excludedLabels.Split(',');

                foreach (Issue i in issues)
                {
                    bool skip = false;
                    foreach (Label l in i.Labels)
                    {
                        if (excludedLabelValues.Contains(l.Name))
                        {
                            skip = true;
                        }
                    }

                    if (!skip)
                    {
                        filteredIssues.Add(i);
                    }
                }

                issues = filteredIssues;
            }

            return(issues.ToList());
        }
        /// <summary>
        /// Gets all open milestones for the repository.
        /// </summary>
        /// <remarks>
        /// http://developer.github.com/v3/issues/milestones/#list-milestones-for-a-repository
        /// </remarks>
        /// <param name="repositoryId">The Id of the repository</param>
        /// <param name="request">Used to filter and sort the list of Milestones returned</param>
        /// <returns></returns>
        public IObservable<Milestone> GetAllForRepository(long repositoryId, MilestoneRequest request)
        {
            Ensure.ArgumentNotNull(request, "request");

            return GetAllForRepository(repositoryId, request, ApiOptions.None);
        }
        /// <summary>
        /// Gets all open milestones for the repository.
        /// </summary>
        /// <remarks>
        /// http://developer.github.com/v3/issues/milestones/#list-milestones-for-a-repository
        /// </remarks>
        /// <param name="repositoryId">The Id of the repository</param>
        /// <param name="request">Used to filter and sort the list of Milestones returned</param>
        /// <param name="options">Options for changing the API response</param>
        /// <returns></returns>
        public IObservable<Milestone> GetAllForRepository(long repositoryId, MilestoneRequest request, ApiOptions options)
        {
            Ensure.ArgumentNotNull(request, "request");
            Ensure.ArgumentNotNull(options, "options");

            return _connection.GetAndFlattenAllPages<Milestone>(ApiUrls.Milestones(repositoryId),
                request.ToParametersDictionary(), options);
        }
Ejemplo n.º 23
0
 public async Task <MilestoneResponse> CreateMilestoneAsync(string code, MilestoneRequest milestoneRequest)
 {
     return(await _api.CreateNewMilestone(_api_token, code, milestoneRequest));
 }