Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Sawicki2012-02-10 00:51:04 +0000
committerKevin Sawicki2012-02-10 00:51:04 +0000
commit056626f17e1fd11b80d11366d12311110ce2e2b7 (patch)
treed35a69de1655e3f02bab299f55644ffdb6d6a0ee
parent467a3e84a86fa8d19109d9bf4ddb61cedb59ea71 (diff)
downloadegit-github-056626f17e1fd11b80d11366d12311110ce2e2b7.tar.gz
egit-github-056626f17e1fd11b80d11366d12311110ce2e2b7.tar.xz
egit-github-056626f17e1fd11b80d11366d12311110ce2e2b7.zip
Support editing specific repository fields only
This overloads RepositoryService.editRepository to take a map of the fields that should be changed on the repository Bug: 371062 Change-Id: Ie13a22b6af795c58d30858c493436c51ff864e3a
-rw-r--r--org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/RepositoryServiceTest.java50
-rw-r--r--org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/service/RepositoryService.java43
2 files changed, 93 insertions, 0 deletions
diff --git a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/RepositoryServiceTest.java b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/RepositoryServiceTest.java
index 46cab454..8e66be6b 100644
--- a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/RepositoryServiceTest.java
+++ b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/RepositoryServiceTest.java
@@ -17,6 +17,8 @@ import static org.mockito.Mockito.verify;
import java.io.IOException;
import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
import org.eclipse.egit.github.core.Repository;
import org.eclipse.egit.github.core.RepositoryHook;
@@ -117,6 +119,54 @@ public class RepositoryServiceTest {
}
/**
+ * Edit repository with fields
+ *
+ * @throws IOException
+ */
+ @Test(expected = IllegalArgumentException.class)
+ public void editRepositoryWithNullFields() throws IOException {
+ service.editRepository("o", "n", null);
+ }
+
+ /**
+ * Edit repository with fields
+ *
+ * @throws IOException
+ */
+ @Test
+ public void editRepositoryWithFields() throws IOException {
+ Map<String, Object> fields = new HashMap<String, Object>();
+ fields.put("has_issues", true);
+ fields.put("homepage", "test://address");
+ service.editRepository("o", "n", fields);
+ verify(client).post("/repos/o/n", fields, Repository.class);
+ }
+
+ /**
+ * Edit repository with fields
+ *
+ * @throws IOException
+ */
+ @Test(expected = IllegalArgumentException.class)
+ public void editRepositoryProviderWithNullFields() throws IOException {
+ service.editRepository(repo, null);
+ }
+
+ /**
+ * Edit repository with fields
+ *
+ * @throws IOException
+ */
+ @Test
+ public void editRepositoryProviderWithFields() throws IOException {
+ Map<String, Object> fields = new HashMap<String, Object>();
+ fields.put("has_issues", true);
+ fields.put("homepage", "test://address");
+ service.editRepository(repo, fields);
+ verify(client).post("/repos/o/n", fields, Repository.class);
+ }
+
+ /**
* Create repository with null organization name
*
* @throws IOException
diff --git a/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/service/RepositoryService.java b/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/service/RepositoryService.java
index e35cf5f2..7e9dae70 100644
--- a/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/service/RepositoryService.java
+++ b/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/service/RepositoryService.java
@@ -700,6 +700,49 @@ public class RepositoryService extends GitHubService {
}
/**
+ * Edit given fields in repository
+ * <p>
+ * Only values in the given fields map will be updated on the repository
+ *
+ * @param owner
+ * @param name
+ * @param fields
+ * @return edited repository
+ * @throws IOException
+ */
+ public Repository editRepository(String owner, String name,
+ Map<String, Object> fields) throws IOException {
+ verifyRepository(owner, name);
+ if (fields == null)
+ throw new IllegalArgumentException("Fields cannot be null"); //$NON-NLS-1$
+
+ StringBuilder uri = new StringBuilder(SEGMENT_REPOS);
+ uri.append('/').append(owner).append('/').append(name);
+ return client.post(uri.toString(), fields, Repository.class);
+ }
+
+ /**
+ * Edit given fields in repository
+ * <p>
+ * Only values in the given fields map will be updated on the repository
+ *
+ * @param provider
+ * @param fields
+ * @return edited repository
+ * @throws IOException
+ */
+ public Repository editRepository(IRepositoryIdProvider provider,
+ Map<String, Object> fields) throws IOException {
+ String id = getId(provider);
+ if (fields == null)
+ throw new IllegalArgumentException("Fields cannot be null"); //$NON-NLS-1$
+
+ StringBuilder uri = new StringBuilder(SEGMENT_REPOS);
+ uri.append('/').append(id);
+ return client.post(uri.toString(), fields, Repository.class);
+ }
+
+ /**
* Fork given repository into new repository under the currently
* authenticated user.
*

Back to the top