public async Task ReturnsCorrectCountOfIssueLabelsWithoutStartForAnIssue()
    {
        var newIssue = new NewIssue("A test issue") { Body = "A new unassigned issue" };
        var newLabel = new NewLabel("test label", "FFFFFF");

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

        var issueLabelsInfo = await _issuesLabelsClient.GetAllForIssue(_context.RepositoryOwner, _context.RepositoryName, issue.Number);
        Assert.Empty(issueLabelsInfo);

        var issueUpdate = new IssueUpdate();
        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
        };

        issueLabelsInfo = await _issuesLabelsClient.GetAllForIssue(_context.RepositoryOwner, _context.RepositoryName, issue.Number, options);

        Assert.Equal(1, issueLabelsInfo.Count);
        Assert.Equal(newLabel.Color, issueLabelsInfo[0].Color);
    }
    public async Task CanRetrieveIssueLabelByName()
    {
        var newLabel = new NewLabel("test label 1b", "FFFFFF");
        var label = await _issuesLabelsClient.Create(_repositoryOwner, _repository.Name, newLabel);
        Assert.NotNull(label);

        var issueLabelLookupByName = await _issuesLabelsClient.Get(_repositoryOwner, _repositoryName, label.Name);

        Assert.Equal(label.Name, issueLabelLookupByName.Name);
        Assert.Equal(label.Color, issueLabelLookupByName.Color);
    }
    public async Task CanListIssueLabelsForARepository()
    {
        var newLabel1 = new NewLabel("test label 1", "FFFFFF");
        var newLabel2 = new NewLabel("test label 2", "FFFFFF");

        var originalIssueLabels = await _issuesLabelsClient.GetForRepository(_repositoryOwner, _repositoryName);

        await _issuesLabelsClient.Create(_repositoryOwner, _repository.Name, newLabel1);
        await _issuesLabelsClient.Create(_repositoryOwner, _repository.Name, newLabel2);

        var issueLabels = await _issuesLabelsClient.GetForRepository(_repositoryOwner, _repositoryName);

        Assert.Equal(originalIssueLabels.Count + 2, issueLabels.Count);
    }
    public async Task CanListLabelsForAnIssue()
    {
        var newIssue = new NewIssue("A test issue") { Body = "A new unassigned issue" };
        var newLabel = new NewLabel("test label", "FFFFFF");

        var label = await _issuesLabelsClient.Create(_repositoryOwner, _repository.Name, newLabel);
        var issue = await _issuesClient.Create(_repositoryOwner, _repositoryName, newIssue);

        var issueLabelsInfo = await _issuesLabelsClient.GetForIssue(_repositoryOwner, _repositoryName, issue.Number);
        Assert.Empty(issueLabelsInfo);

        var issueUpdate = new IssueUpdate();
        issueUpdate.Labels.Add(label.Name);
        var updated = await _issuesClient.Update(_repositoryOwner, _repository.Name, issue.Number, issueUpdate);
        Assert.NotNull(updated);
        issueLabelsInfo = await _issuesLabelsClient.GetForIssue(_repositoryOwner, _repositoryName, issue.Number);

        Assert.Equal(1, issueLabelsInfo.Count);
        Assert.Equal(newLabel.Color, issueLabelsInfo[0].Color);
    }
        /// <summary>
        /// Creates a label.
        /// </summary>
        /// <remarks>
        /// See the <a href="http://developer.github.com/v3/issues/labels/#create-a-label">API documentation</a> for more information.
        /// </remarks>
        /// <param name="repositoryId">The Id of the repository</param>
        /// <param name="newLabel">The data for the label to be created</param>
        public Task <Label> Create(long repositoryId, NewLabel newLabel)
        {
            Ensure.ArgumentNotNull(newLabel, "newLabel");

            return(ApiConnection.Post <Label>(ApiUrls.Labels(repositoryId), newLabel));
        }
        public Task <Label> Create(long repositoryId, NewLabel newLabel)
        {
            Ensure.ArgumentNotNull(newLabel, nameof(newLabel));

            return(ApiConnection.Post <Label>(ApiUrls.Labels(repositoryId), newLabel, AcceptHeaders.LabelsApiPreview));
        }
    public async Task CanReplaceAllForIssueWithRepositoryId()
    {
        var newIssue1 = new NewIssue("A test issue") { Body = "A new unassigned issue" };
        var newLabel1 = new NewLabel("test label 1b", "FFFFFF");
        var newLabel2 = new NewLabel("test label 1a", "FFFFFF");

        var label1 = await _issuesLabelsClient.Create(_context.Repository.Id, newLabel1);
        Assert.NotNull(label1);
        var label2 = await _issuesLabelsClient.Create(_context.Repository.Id, newLabel2);
        Assert.NotNull(label2);

        var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue1);
        Assert.NotNull(issue);

        await _issuesLabelsClient.AddToIssue(_context.Repository.Id, issue.Number, new[] { label1.Name });
        await _issuesLabelsClient.ReplaceAllForIssue(_context.Repository.Id, issue.Number, new[] { label2.Name });

        var labels = await _issuesLabelsClient.GetAllForIssue(_context.Repository.Id, issue.Number);

        Assert.NotEmpty(labels);
        Assert.Equal(label2.Name, labels[0].Name);
        Assert.Equal(label2.Color, labels[0].Color);
    }
    public async Task CanRemoveFromIssueWithRepositoryId()
    {
        var newIssue = new NewIssue("A test issue") { Body = "A new unassigned issue" };
        var newLabel = new NewLabel("test label 1b", "FFFFFF");

        var label = await _issuesLabelsClient.Create(_context.Repository.Id, newLabel);
        Assert.NotNull(label);

        var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue);
        Assert.NotNull(issue);

        await _issuesLabelsClient.AddToIssue(_context.Repository.Id, issue.Number, new[] { label.Name });
        await _issuesLabelsClient.RemoveFromIssue(_context.Repository.Id, issue.Number, label.Name);

        var labels = await _issuesLabelsClient.GetAllForIssue(_context.Repository.Id, issue.Number);

        Assert.Empty(labels);
    }
    public async Task CanDeleteIssueLabelByNameWithRepositoryId()
    {
        var newLabel = new NewLabel("test label 1b", "FFFFFF");
        var label = await _issuesLabelsClient.Create(_context.Repository.Id, newLabel);
        Assert.NotNull(label);

        var issueLabelLookupByName = await _issuesLabelsClient.Get(_context.Repository.Id, label.Name);

        Assert.Equal(label.Name, issueLabelLookupByName.Name);
        Assert.Equal(label.Color, issueLabelLookupByName.Color);

        await _issuesLabelsClient.Delete(_context.RepositoryOwner, _context.RepositoryName, label.Name);

        await Assert.ThrowsAsync<NotFoundException>(() => _issuesLabelsClient.Get(_context.RepositoryOwner, _context.RepositoryName, label.Name));
    }
    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 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 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);
    }
Example #13
0
        /// <summary>
        /// Creates a label.
        /// </summary>
        /// <remarks>
        /// See the <a href="http://developer.github.com/v3/issues/labels/#create-a-label">API documentation</a> for more information.
        /// </remarks>
        /// <param name="repositoryId">The Id of the repository</param>
        /// <param name="newLabel">The data for the label to be created</param>
        public Task<Label> Create(int repositoryId, NewLabel newLabel)
        {
            Ensure.ArgumentNotNull(newLabel, "newLabel");

            return ApiConnection.Post<Label>(ApiUrls.Labels(repositoryId), newLabel);
        }
Example #14
0
        /// <summary>
        /// Creates a label.
        /// </summary>
        /// <remarks>
        /// See the <a href="http://developer.github.com/v3/issues/labels/#create-a-label">API documentation</a> for more information.
        /// </remarks>
        /// <param name="owner">The owner of the repository</param>
        /// <param name="name">The name of the repository</param>
        /// <param name="newLabel">The data for the label to be created</param>
        public Task<Label> Create(string owner, string name, NewLabel newLabel)
        {
            Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
            Ensure.ArgumentNotNullOrEmptyString(name, "name");
            Ensure.ArgumentNotNull(newLabel, "newLabel");

            return ApiConnection.Post<Label>(ApiUrls.Labels(owner, name), newLabel);
        }
Example #15
0
        public List<Label> MigrateToLabels(List<String> labelNames)
        {
            var labels = new List<Label>();

            Log("Info: Creating all labels.");
            foreach (var labelName in labelNames)
            {
                var newLabel = new NewLabel(labelName, "006b75");

                try
                {
                    var labelTask = Task.Run<Label>(async () => await client.Issue.Labels.Create(githubOrganizationName, githubRepositoryName, newLabel));
                    labels.Add(labelTask.Result);
                }
                catch (Exception ex)
                {
                    Log(String.Format("ERROR: not creating label {0}, get him.", labelName));

                    var labelTask = Task.Run<Label>(async () => await client.Issue.Labels.Get(githubOrganizationName, githubRepositoryName, labelName));
                    labels.Add(labelTask.Result);
                }
            }
            Log("Info: Labels are created with success.");

            return labels;
        }