/// <summary>
        /// Creates a milestone for the specified repository. Any user with pull access to a repository can create an
        /// Milestone.
        /// </summary>
        /// <remarks>http://developer.github.com/v3/issues/milestones/#create-a-milestone</remarks>
        /// <param name="owner">The owner of the repository</param>
        /// <param name="name">The name of the repository</param>
        /// <param name="newMilestone">A <see cref="NewMilestone"/> instance describing the new Milestone to create</param>
        /// <returns></returns>
        public Task <Milestone> Create(string owner, string name, NewMilestone newMilestone)
        {
            Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
            Ensure.ArgumentNotNullOrEmptyString(name, "name");
            Ensure.ArgumentNotNull(newMilestone, "newMilestone");

            return(ApiConnection.Post <Milestone>(ApiUrls.Milestones(owner, name), newMilestone));
        }
        /// <summary>
        /// Creates an Milestone for the specified repository. Any user with pull access to a repository can create an
        /// Milestone.
        /// </summary>
        /// <remarks>http://developer.github.com/v3/issues/milestones/#create-a-milestone</remarks>
        /// <param name="owner">The owner of the repository</param>
        /// <param name="name">The name of the repository</param>
        /// <param name="newMilestone">A <see cref="NewMilestone"/> instance describing the new Milestone to create</param>
        /// <returns></returns>
        public Task<Milestone> Create(string owner, string name, NewMilestone newMilestone)
        {
            Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
            Ensure.ArgumentNotNullOrEmptyString(name, "name");
            Ensure.ArgumentNotNull(newMilestone, "newMilestone");

            return ApiConnection.Post<Milestone>(ApiUrls.Milestones(owner, name), newMilestone);
        }
    public async Task CanRetrieveOneMilestoneWithRepositoryId()
    {
        var newMilestone = new NewMilestone("a milestone") { DueOn = DateTime.Now };
        var created = await _milestonesClient.Create(_context.Repository.Id, newMilestone);

        var result = await _milestonesClient.Get(_context.Repository.Id, created.Number);

        Assert.Equal("a milestone", result.Title);
    }
    public async Task CanRetrieveOneMilestone()
    {
        var newMilestone = new NewMilestone("a milestone") { DueOn = DateTime.Now };
        var created = await _milestonesClient.Create(_repositoryOwner, _repositoryName, newMilestone);

        var result = await _milestonesClient.Get(_repositoryOwner, _repositoryName, created.Number);

        Assert.Equal("a milestone", result.Title);
    }
            public void PostsToCorrectUrl()
            {
                var newMilestone = new NewMilestone("some title");
                var connection = Substitute.For<IApiConnection>();
                var client = new MilestonesClient(connection);

                client.Create("fake", "repo", newMilestone);

                connection.Received().Post<Milestone>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/milestones"),
                    newMilestone);
            }
    public async Task CanDeleteOneMilestoneWithRepositoryId()
    {
        var newMilestone = new NewMilestone("a milestone") { DueOn = DateTime.Now };
        var created = await _milestonesClient.Create(_context.Repository.Id, newMilestone);

        var milestone = await _milestonesClient.Get(_context.Repository.Id, created.Number);
        Assert.Equal("a milestone", milestone.Title);

        await _milestonesClient.Delete(_context.Repository.Id, created.Number);

        await Assert.ThrowsAsync<NotFoundException>(() => _milestonesClient.Get(_context.Repository.Id, created.Number));
    }
    public async Task CanUpdateOneMilestone()
    {
        var newMilestone = new NewMilestone("a milestone") { DueOn = DateTime.Now };
        var created = await _milestonesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newMilestone);

        var result1 = await _milestonesClient.Get(_context.RepositoryOwner, _context.RepositoryName, created.Number);
        Assert.Equal("a milestone", result1.Title);

        await _milestonesClient.Update(_context.RepositoryOwner, _context.RepositoryName, created.Number, new MilestoneUpdate { Title = "New title" });

        var result2 = await _milestonesClient.Get(_context.RepositoryOwner, _context.RepositoryName, created.Number);
        Assert.Equal("New title", result2.Title);
    }
    public async Task CanListMilestonesWithDefaultSortByDueDateAsc()
    {
        var milestone1 = new NewMilestone("milestone 1") { DueOn = DateTime.Now };
        var milestone2 = new NewMilestone("milestone 2") { DueOn = DateTime.Now.AddDays(1) };
        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 milestones = await _milestonesClient.GetAllForRepository(_context.RepositoryOwner, _context.RepositoryName);
        Assert.Equal(2, milestones.Count);
        Assert.Equal("milestone 1", milestones[0].Title);
        Assert.Equal("milestone 2", milestones[1].Title);
    }
    public async Task CanListMilestonesWithSortByDueDateDesc()
    {
        var milestone1 = new NewMilestone("milestone 1") { DueOn = DateTime.Now };
        var milestone2 = new NewMilestone("milestone 2") { DueOn = DateTime.Now.AddDays(1) };
        var milestone3 = new NewMilestone("milestone 3") { DueOn = DateTime.Now.AddDays(3), State = ItemState.Closed };
        await _milestonesClient.Create(_repositoryOwner, _repositoryName, milestone1);
        await _milestonesClient.Create(_repositoryOwner, _repositoryName, milestone2);
        await _milestonesClient.Create(_repositoryOwner, _repositoryName, milestone3);

        var milestones = await _milestonesClient.GetForRepository(_repositoryOwner, _repositoryName,
            new MilestoneRequest { SortDirection = SortDirection.Descending });
        Assert.Equal(2, milestones.Count);
        Assert.Equal("milestone 2", milestones[0].Title);
        Assert.Equal("milestone 1", milestones[1].Title);
    }
    public async Task CanListClosedMilestones()
    {
        var milestone1 = new NewMilestone("milestone 1") { DueOn = DateTime.Now };
        var milestone2 = new NewMilestone("milestone 2") { DueOn = DateTime.Now.AddDays(1) };
        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 milestones = await _milestonesClient.GetAllForRepository(_context.RepositoryOwner, _context.RepositoryName,
            new MilestoneRequest { State = ItemState.Closed });

        Assert.Equal(1, milestones.Count);
        Assert.Equal("milestone 3", milestones[0].Title);
    }
    public async Task ReturnsCorrectCountOfIssueLabelsWithStartForAMilestoneWithRepositoryId()
    {
        var newMilestone = new NewMilestone("New Milestone");
        var milestone = await _issuesClient.Milestone.Create(_context.RepositoryOwner, _context.RepositoryName, newMilestone);

        for (int i = 0; i < 2; i++)
        {
            int k = i + 1;
            var newIssue = new NewIssue("A test issue " + k) { Body = "A new unassigned issue " + k };
            var newLabel = new NewLabel("test label " + k, "FFFFF" + k);

            var label = await _issuesLabelsClient.Create(_context.Repository.Id, newLabel);
            var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue);

            var issueUpdate = new IssueUpdate { Milestone = milestone.Number };
            issueUpdate.AddLabel(label.Name);
            var updated = await _issuesClient.Update(_context.RepositoryOwner, _context.RepositoryName, issue.Number, issueUpdate);
            Assert.NotNull(updated);
        }

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

        var issueLabelsInfo = await _issuesLabelsClient.GetAllForMilestone(_context.Repository.Id, milestone.Number, options);

        Assert.Equal(1, issueLabelsInfo.Count);
    }
    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 async Task ReturnsCorrectCountOfMilestonesWithStartParametrizedWithRepositoryId()
    {
        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 };
        var milestone4 = new NewMilestone("milestone 4") { DueOn = DateTime.Now.AddDays(4), 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);
        await _milestonesClient.Create(_context.RepositoryOwner, _context.RepositoryName, milestone4);

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

        var milestones = await _milestonesClient.GetAllForRepository(_context.Repository.Id, new MilestoneRequest { State = ItemStateFilter.Closed }, options);

        Assert.Equal(1, milestones.Count);
    }
        public List<Milestone> MigrateToMilestones(List<String> sprintNames)
        {
            Checker.IsNull(sprintNames, "sprintNames");

            var milestones = new List<Milestone>();

            Log("Info: Creating all milestones.");
            foreach (var sprintName in sprintNames)
            {
                var newMilestone = new NewMilestone(sprintName)
                {
                    Description = sprintName,
                    DueOn = null,
                    State = ItemState.Closed
                };
                var milestoneTask = Task.Run<Milestone>(async () => await client.Issue.Milestone.Create(githubOrganizationName, githubRepositoryName, newMilestone));
                milestones.Add(milestoneTask.Result);
            }
            Log("Info: Milestones are created with success.");

            return milestones;
        }
    public async Task CanAssignAndUnassignMilestoneWithRepositoryId()
    {
        var newMilestone = new NewMilestone("a milestone");
        var milestone = await _issuesClient.Milestone.Create(_context.RepositoryOwner, _context.RepositoryName, newMilestone);

        var newIssue1 = new NewIssue("A test issue1")
        {
            Body = "A new unassigned issue",
            Milestone = milestone.Number
        };
        var issue = await _issuesClient.Create(_context.Repository.Id, newIssue1);

        Assert.NotNull(issue.Milestone);

        var issueUpdate = issue.ToUpdate();
        issueUpdate.Milestone = null;

        var updatedIssue = await _issuesClient.Update(_context.Repository.Id, issue.Number, issueUpdate);

        Assert.Null(updatedIssue.Milestone);
    }
Exemple #16
0
        public Task <Milestone> Create(long repositoryId, NewMilestone newMilestone)
        {
            Ensure.ArgumentNotNull(newMilestone, nameof(newMilestone));

            return(ApiConnection.Post <Milestone>(ApiUrls.Milestones(repositoryId), newMilestone));
        }
    public async Task CanListLabelsForAnMilestoneWithRepositoryId()
    {
        var newIssue = new NewIssue("A test issue") { Body = "A new unassigned issue" };
        var newLabel = new NewLabel("test label", "FFFFFF");
        var newMilestone = new NewMilestone("New Milestone");

        var label = await _issuesLabelsClient.Create(_context.Repository.Id, newLabel);
        var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue);
        var milestone = await _issuesClient.Milestone.Create(_context.RepositoryOwner, _context.RepositoryName, newMilestone);
        
        var issueLabelsInfo = await _issuesLabelsClient.GetAllForMilestone(_context.Repository.Id, milestone.Number);
        Assert.Empty(issueLabelsInfo);

        var issueUpdate = new IssueUpdate { Milestone = milestone.Number };
        issueUpdate.AddLabel(label.Name);

        var updated = await _issuesClient.Update(_context.RepositoryOwner, _context.RepositoryName, issue.Number, issueUpdate);
        Assert.NotNull(updated);

        issueLabelsInfo = await _issuesLabelsClient.GetAllForMilestone(_context.Repository.Id, milestone.Number);

        Assert.Equal(1, issueLabelsInfo.Count);
        Assert.Equal(label.Color, issueLabelsInfo[0].Color);
    }
        /// <summary>
        /// Creates a milestone for the specified repository. Any user with pull access to a repository can create an
        /// Milestone.
        /// </summary>
        /// <remarks>http://developer.github.com/v3/issues/milestones/#create-a-milestone</remarks>
        /// <param name="repositoryId">The Id of the repository</param>
        /// <param name="newMilestone">A <see cref="NewMilestone"/> instance describing the new Milestone to create</param>
        /// <returns></returns>
        public Task<Milestone> Create(long repositoryId, NewMilestone newMilestone)
        {
            Ensure.ArgumentNotNull(newMilestone, "newMilestone");

            return ApiConnection.Post<Milestone>(ApiUrls.Milestones(repositoryId), newMilestone);
        }
            public void CreatesFromClientIssueMilestone()
            {
                var newMilestone = new NewMilestone("some title");
                var gitHubClient = Substitute.For<IGitHubClient>();
                var client = new ObservableMilestonesClient(gitHubClient);

                client.Create("fake", "repo", newMilestone);

                gitHubClient.Issue.Milestone.Received().Create("fake", "repo", newMilestone);
            }
    public async Task ReturnsDistinctIssueLabelsBasedOnStartPageForAMilestoneWithRepositoryId()
    {
        var newMilestone = new NewMilestone("New Milestone");
        var milestone = await _issuesClient.Milestone.Create(_context.RepositoryOwner, _context.RepositoryName, newMilestone);

        for (int i = 0; i < 2; i++)
        {
            int k = i + 1;
            var newIssue = new NewIssue("A test issue " + k) { Body = "A new unassigned issue " + k };
            var newLabel = new NewLabel("test label " + k, "FFFFF" + k);

            var label = await _issuesLabelsClient.Create(_context.Repository.Id, newLabel);
            var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue);

            var issueUpdate = new IssueUpdate { Milestone = milestone.Number };
            issueUpdate.AddLabel(label.Name);
            var updated = await _issuesClient.Update(_context.RepositoryOwner, _context.RepositoryName, issue.Number, issueUpdate);
            Assert.NotNull(updated);
        }

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

        var firstPage = await _issuesLabelsClient.GetAllForMilestone(_context.Repository.Id, milestone.Number, startOptions);

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

        var secondPage = await _issuesLabelsClient.GetAllForMilestone(_context.Repository.Id, milestone.Number, skipStartOptions);

        Assert.Equal(1, firstPage.Count);
        Assert.Equal(1, secondPage.Count);
        Assert.NotEqual(firstPage.First().Color, secondPage.First().Color);
    }
    public async Task CanAssignAndUnassignMilestone()
    {
        var owner = _repository.Owner.Login;

        var newMilestone = new NewMilestone("a milestone");
        var milestone = await _issuesClient.Milestone.Create(owner, _repository.Name, newMilestone);

        var newIssue1 = new NewIssue("A test issue1")
        {
            Body = "A new unassigned issue",
            Milestone = milestone.Number
        };
        var issue = await _issuesClient.Create(owner, _repository.Name, newIssue1);

        Assert.NotNull(issue.Milestone);

        var issueUpdate = issue.ToUpdate();
        issueUpdate.Milestone = null;

        var updatedIssue = await _issuesClient.Update(owner, _repository.Name, issue.Number, issueUpdate);

        Assert.Null(updatedIssue.Milestone);
    }
    public async Task ReturnsCorrectCountOfMilestonesWithStart()
    {
        var milestone1 = new NewMilestone("milestone 1") { DueOn = DateTime.Now };
        var milestone2 = new NewMilestone("milestone 2") { DueOn = DateTime.Now.AddDays(1) };
        var milestone3 = new NewMilestone("milestone 3") { DueOn = DateTime.Now.AddDays(3) };
        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 options = new ApiOptions
        {
            PageSize = 2,
            PageCount = 1,
            StartPage = 2
        };

        var milestones = await _milestonesClient.GetAllForRepository(_context.RepositoryOwner, _context.RepositoryName, options);

        Assert.Equal(1, milestones.Count);
    }