Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Sawicki2012-06-25 17:16:48 +0000
committerKevin Sawicki2012-06-25 17:16:48 +0000
commitd604f8f603fc53c4c18d8c7a961ff3ae75b2e9b1 (patch)
tree050067c32f62c61bb6281e5615002847f619d6f4
parentdbf1fb5cb319c71380a235239d4901042f9a6ee0 (diff)
downloadegit-github-d604f8f603fc53c4c18d8c7a961ff3ae75b2e9b1.tar.gz
egit-github-d604f8f603fc53c4c18d8c7a961ff3ae75b2e9b1.tar.xz
egit-github-d604f8f603fc53c4c18d8c7a961ff3ae75b2e9b1.zip
Add service support for editing a label
-rw-r--r--org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/LabelServiceTest.java45
-rw-r--r--org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/service/LabelService.java27
2 files changed, 72 insertions, 0 deletions
diff --git a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/LabelServiceTest.java b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/LabelServiceTest.java
index f16dd699..4d3274a4 100644
--- a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/LabelServiceTest.java
+++ b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/LabelServiceTest.java
@@ -439,4 +439,49 @@ public class LabelServiceTest {
request.setUri("/repos/user/repo/labels/bugs");
verify(gitHubClient).get(request);
}
+
+ /**
+ * Edit label with null label
+ *
+ * @throws IOException
+ */
+ @Test(expected = IllegalArgumentException.class)
+ public void editLabelNullLabel() throws IOException {
+ labelService.editLabel(RepositoryId.create("a", "b"), null);
+ }
+
+ /**
+ * Edit label with null label
+ *
+ * @throws IOException
+ */
+ @Test(expected = IllegalArgumentException.class)
+ public void editLabelNullLabelName() throws IOException {
+ labelService.editLabel(RepositoryId.create("a", "b"), new Label());
+ }
+
+ /**
+ * Edit label with null label
+ *
+ * @throws IOException
+ */
+ @Test(expected = IllegalArgumentException.class)
+ public void editLabelEmptyLabelName() throws IOException {
+ labelService.editLabel(RepositoryId.create("a", "b"),
+ new Label().setName(""));
+ }
+
+ /**
+ * Edit label
+ *
+ * @throws IOException
+ */
+ @Test
+ public void editLabel() throws IOException {
+ Label label = new Label();
+ label.setName("l1");
+ label.setColor("#FF");
+ labelService.editLabel(RepositoryId.create("a", "b"), label);
+ verify(gitHubClient).post("/repos/a/b/labels/l1", label, Label.class);
+ }
}
diff --git a/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/service/LabelService.java b/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/service/LabelService.java
index 98499c32..957d988f 100644
--- a/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/service/LabelService.java
+++ b/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/service/LabelService.java
@@ -269,4 +269,31 @@ public class LabelService extends GitHubService {
uri.append('/').append(label);
client.delete(uri.toString());
}
+
+ /**
+ * Edit the given label in the given repository
+ *
+ * @param repository
+ * @param label
+ * @return edited label
+ * @throws IOException
+ */
+ public Label editLabel(IRepositoryIdProvider repository, Label label)
+ throws IOException {
+ String repoId = getId(repository);
+ if (label == null)
+ throw new IllegalArgumentException("Label cannot be null"); //$NON-NLS-1$
+ String name = label.getName();
+ if (name == null)
+ throw new IllegalArgumentException("Label name cannot be null"); //$NON-NLS-1$
+ if (name.length() == 0)
+ throw new IllegalArgumentException("Label name cannot be empty"); //$NON-NLS-1$
+
+ StringBuilder uri = new StringBuilder(SEGMENT_REPOS);
+ uri.append('/').append(repoId);
+ uri.append(SEGMENT_LABELS);
+ uri.append('/').append(name);
+
+ return client.post(uri.toString(), label, Label.class);
+ }
}

Back to the top