From 6bfd6fdcc1e577f7d61a64b26fd6d28292c440ea Mon Sep 17 00:00:00 2001 From: Brendan Forster Date: Tue, 24 Feb 2015 13:02:24 +0930 Subject: [PATCH] added ClearLabels helper function --- .../Clients/IssuesClientTests.cs | 29 +++++++++++++++++++ Octokit/Models/Request/IssueUpdate.cs | 13 +++++++++ 2 files changed, 42 insertions(+) diff --git a/Octokit.Tests.Integration/Clients/IssuesClientTests.cs b/Octokit.Tests.Integration/Clients/IssuesClientTests.cs index e8903a73..363c12b7 100644 --- a/Octokit.Tests.Integration/Clients/IssuesClientTests.cs +++ b/Octokit.Tests.Integration/Clients/IssuesClientTests.cs @@ -322,6 +322,35 @@ public class IssuesClientTests : IDisposable Assert.Equal("another thing", updatedIssue.Labels[0].Name); } + [IntegrationTest] + public async Task CanClearLabelsForAnIssue() + { + var owner = _repository.Owner.Login; + + // create some labels + await _issuesClient.Labels.Create(owner, _repository.Name, new NewLabel("something", "FF0000")); + await _issuesClient.Labels.Create(owner, _repository.Name, new NewLabel("another thing", "0000FF")); + + // setup us the issue + var newIssue = new NewIssue("A test issue1") + { + Body = "A new unassigned issue", + }; + newIssue.Labels.Add("something"); + newIssue.Labels.Add("another thing"); + + var issue = await _issuesClient.Create(owner, _repository.Name, newIssue); + Assert.Equal(2, issue.Labels.Count); + + // update the issue + var issueUpdate = issue.ToUpdate(); + issueUpdate.ClearLabels(); + + var updatedIssue = await _issuesClient.Update(owner, _repository.Name, issue.Number, issueUpdate); + + Assert.Empty(updatedIssue.Labels); + } + public void Dispose() { Helper.DeleteRepo(_repository); diff --git a/Octokit/Models/Request/IssueUpdate.cs b/Octokit/Models/Request/IssueUpdate.cs index 1e5fe3cb..78fc964e 100644 --- a/Octokit/Models/Request/IssueUpdate.cs +++ b/Octokit/Models/Request/IssueUpdate.cs @@ -69,5 +69,18 @@ namespace Octokit Labels.Add(name); } + + public void ClearLabels() + { + // lazily create the label array + if (Labels == null) + { + Labels = new List(); + } + else + { + Labels.Clear(); + } + } } }