Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Sawicki2012-01-10 17:42:28 +0000
committerKevin Sawicki2012-01-10 17:42:28 +0000
commitcf317d7e845a59ed2db433db6d5efaccd2eb08c2 (patch)
treed7baebee0568ff54c21ba75bb9a0f870c03865bb
parente270b86caa90a29fb9267bc2f0b2d4c65748fabc (diff)
downloadegit-github-cf317d7e845a59ed2db433db6d5efaccd2eb08c2.tar.gz
egit-github-cf317d7e845a59ed2db433db6d5efaccd2eb08c2.tar.xz
egit-github-cf317d7e845a59ed2db433db6d5efaccd2eb08c2.zip
Overload methods to take an IRepositoryProvider
This is an alternative to take a String owner and name Change-Id: Id164e5173fcdba51bcf68aab9069ce5619bd4586
-rw-r--r--org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/IssueServiceTest.java77
-rw-r--r--org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/service/IssueService.java180
2 files changed, 252 insertions, 5 deletions
diff --git a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/IssueServiceTest.java b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/IssueServiceTest.java
index 7f52565b..cabb2ba9 100644
--- a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/IssueServiceTest.java
+++ b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/IssueServiceTest.java
@@ -402,6 +402,19 @@ public class IssueServiceTest {
}
/**
+ * Create issue with null issue
+ *
+ * @throws IOException
+ */
+ @Test
+ public void createIssueNullIssueWithRepositoryId() throws IOException {
+ RepositoryId id = new RepositoryId("tu", "tr");
+ issueService.createIssue(id, null);
+ verify(gitHubClient).post("/repos/tu/tr/issues",
+ new HashMap<String, String>(), Issue.class);
+ }
+
+ /**
* Edit issue with null user
*
* @throws IOException
@@ -474,6 +487,28 @@ public class IssueServiceTest {
}
/**
+ * Edit issue with valid parameters
+ *
+ * @throws IOException
+ */
+ @Test
+ public void editIssueWithRepositoryId() throws IOException {
+ Issue issue = new Issue();
+ issue.setNumber(1);
+ issue.setTitle("test_title");
+ issue.setBody("test_body");
+ issue.setState("test_state");
+ RepositoryId id = new RepositoryId("tu", "tr");
+ issueService.editIssue(id, issue);
+
+ Map<String, String> params = new HashMap<String, String>();
+ params.put(IssueService.FIELD_TITLE, "test_title");
+ params.put(IssueService.FIELD_BODY, "test_body");
+ params.put(IssueService.FILTER_STATE, "test_state");
+ verify(gitHubClient).post("/repos/tu/tr/issues/1", params, Issue.class);
+ }
+
+ /**
* Create issue comment with null user
*
* @throws IOException
@@ -551,6 +586,22 @@ public class IssueServiceTest {
}
/**
+ * Create issue comment with valid parameters
+ *
+ * @throws IOException
+ */
+ @Test
+ public void createCommentWithRepositoryId() throws IOException {
+ RepositoryId id = new RepositoryId("tu", "tr");
+ issueService.createComment(id, 1, "test_comment");
+
+ Map<String, String> params = new HashMap<String, String>();
+ params.put(IssueService.FIELD_BODY, "test_comment");
+ verify(gitHubClient).post("/repos/tu/tr/issues/1/comments", params,
+ Comment.class);
+ }
+
+ /**
* Delete comment with null user
*
* @throws IOException
@@ -622,6 +673,18 @@ public class IssueServiceTest {
}
/**
+ * Delete issue comment
+ *
+ * @throws IOException
+ */
+ @Test
+ public void deleteCommentWithRepositoryId() throws IOException {
+ RepositoryId id = new RepositoryId("user", "repo");
+ issueService.deleteComment(id, 1);
+ verify(gitHubClient).delete("/repos/user/repo/issues/comments/1");
+ }
+
+ /**
* Page issues for current user
*
* @throws IOException
@@ -752,4 +815,18 @@ public class IssueServiceTest {
verify(gitHubClient).post("/repos/user/repo/issues/comments/29",
comment, Comment.class);
}
+
+ /**
+ * Edit issue comment
+ *
+ * @throws IOException
+ */
+ @Test
+ public void editIssueCommentWithRepositoryId() throws IOException {
+ RepositoryId id = new RepositoryId("user", "repo");
+ Comment comment = new Comment().setId(44).setBody("new body");
+ issueService.editComment(id, comment);
+ verify(gitHubClient).post("/repos/user/repo/issues/comments/44",
+ comment, Comment.class);
+ }
}
diff --git a/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/service/IssueService.java b/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/service/IssueService.java
index 66e907a2..cffc6df0 100644
--- a/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/service/IssueService.java
+++ b/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/service/IssueService.java
@@ -608,8 +608,36 @@ public class IssueService extends GitHubService {
throws IOException {
verifyRepository(user, repository);
+ String id = user + '/' + repository;
+ return createIssue(id, issue);
+ }
+
+ /**
+ * Create issue
+ *
+ * @param repository
+ * @param issue
+ * @return created issue
+ * @throws IOException
+ */
+ public Issue createIssue(IRepositoryIdProvider repository, Issue issue)
+ throws IOException {
+ String id = getId(repository);
+ return createIssue(id, issue);
+ }
+
+ /**
+ * Create issue
+ *
+ * @param id
+ * @param issue
+ * @return created issue
+ * @throws IOException
+ */
+ private Issue createIssue(String id, Issue issue) throws IOException {
+
StringBuilder uri = new StringBuilder(SEGMENT_REPOS);
- uri.append('/').append(user).append('/').append(repository);
+ uri.append('/').append(id);
uri.append(SEGMENT_ISSUES);
Map<Object, Object> params = createIssueMap(issue, true);
@@ -628,11 +656,40 @@ public class IssueService extends GitHubService {
public Issue editIssue(String user, String repository, Issue issue)
throws IOException {
verifyRepository(user, repository);
+
+ String id = user + '/' + repository;
+ return editIssue(id, issue);
+ }
+
+ /**
+ * Edit issue
+ *
+ * @param repository
+ * @param issue
+ * @return created issue
+ * @throws IOException
+ */
+ public Issue editIssue(IRepositoryIdProvider repository, Issue issue)
+ throws IOException {
+ String id = getId(repository);
+ return editIssue(id, issue);
+ }
+
+ /**
+ * Edit issue
+ *
+ * @param id
+ * @param repository
+ * @param issue
+ * @return created issue
+ * @throws IOException
+ */
+ private Issue editIssue(String id, Issue issue) throws IOException {
if (issue == null)
throw new IllegalArgumentException("Issue cannot be null"); //$NON-NLS-1$
StringBuilder uri = new StringBuilder(SEGMENT_REPOS);
- uri.append('/').append(user).append('/').append(repository);
+ uri.append('/').append(id);
uri.append(SEGMENT_ISSUES);
uri.append('/').append(issue.getNumber());
@@ -672,13 +729,58 @@ public class IssueService extends GitHubService {
public Comment createComment(String user, String repository,
String issueId, String comment) throws IOException {
verifyRepository(user, repository);
+
+ String id = user + '/' + repository;
+ return createComment(id, issueId, comment);
+ }
+
+ /**
+ * Create comment on specified issue id
+ *
+ * @param repository
+ * @param issueId
+ * @param comment
+ * @return created issue
+ * @throws IOException
+ */
+ public Comment createComment(IRepositoryIdProvider repository, int issueId,
+ String comment) throws IOException {
+ return createComment(repository, Integer.toString(issueId), comment);
+ }
+
+ /**
+ * Create comment on specified issue id
+ *
+ * @param repository
+ * @param issueId
+ * @param comment
+ * @return created issue
+ * @throws IOException
+ */
+ public Comment createComment(IRepositoryIdProvider repository,
+ String issueId, String comment) throws IOException {
+ String id = getId(repository);
+ return createComment(id, issueId, comment);
+ }
+
+ /**
+ * Create comment on specified issue id
+ *
+ * @param id
+ * @param issueId
+ * @param comment
+ * @return created issue
+ * @throws IOException
+ */
+ private Comment createComment(String id, String issueId, String comment)
+ throws IOException {
if (issueId == null)
throw new IllegalArgumentException("Issue id cannot be null"); //$NON-NLS-1$
if (issueId.length() == 0)
throw new IllegalArgumentException("Issue id cannot be empty"); //$NON-NLS-1$
StringBuilder uri = new StringBuilder(SEGMENT_REPOS);
- uri.append('/').append(user).append('/').append(repository);
+ uri.append('/').append(id);
uri.append(SEGMENT_ISSUES);
uri.append('/').append(issueId);
uri.append(SEGMENT_COMMENTS);
@@ -724,11 +826,40 @@ public class IssueService extends GitHubService {
public Comment editComment(String user, String repository, Comment comment)
throws IOException {
verifyRepository(user, repository);
+
+ String id = user + '/' + repository;
+ return editComment(id, comment);
+ }
+
+ /**
+ * Edit issue comment
+ *
+ * @param repository
+ * @param comment
+ * @return edited comment
+ * @throws IOException
+ */
+ public Comment editComment(IRepositoryIdProvider repository, Comment comment)
+ throws IOException {
+ String id = getId(repository);
+ return editComment(id, comment);
+ }
+
+ /**
+ * Edit issue comment
+ *
+ * @param user
+ * @param repository
+ * @param comment
+ * @return edited comment
+ * @throws IOException
+ */
+ private Comment editComment(String id, Comment comment) throws IOException {
if (comment == null)
throw new IllegalArgumentException("Comment cannot be null"); //$NON-NLS-1$
StringBuilder uri = new StringBuilder(SEGMENT_REPOS);
- uri.append('/').append(user).append('/').append(repository);
+ uri.append('/').append(id);
uri.append(SEGMENT_ISSUES).append(SEGMENT_COMMENTS);
uri.append('/').append(comment.getId());
return client.post(uri.toString(), comment, Comment.class);
@@ -758,13 +889,52 @@ public class IssueService extends GitHubService {
public void deleteComment(String user, String repository, String commentId)
throws IOException {
verifyRepository(user, repository);
+
+ String id = user + '/' + repository;
+ deleteComment(id, commentId);
+ }
+
+ /**
+ * Delete the issue comment with the given id
+ *
+ * @param repository
+ * @param commentId
+ * @throws IOException
+ */
+ public void deleteComment(IRepositoryIdProvider repository, long commentId)
+ throws IOException {
+ deleteComment(repository, Long.toString(commentId));
+ }
+
+ /**
+ * Delete the issue comment with the given id
+ *
+ * @param repository
+ * @param commentId
+ * @throws IOException
+ */
+ public void deleteComment(IRepositoryIdProvider repository, String commentId)
+ throws IOException {
+ String id = getId(repository);
+ deleteComment(id, commentId);
+ }
+
+ /**
+ * Delete the issue comment with the given id
+ *
+ * @param user
+ * @param repository
+ * @param commentId
+ * @throws IOException
+ */
+ private void deleteComment(String id, String commentId) throws IOException {
if (commentId == null)
throw new IllegalArgumentException("Comment cannot be null"); //$NON-NLS-1$
if (commentId.length() == 0)
throw new IllegalArgumentException("Comment cannot be empty"); //$NON-NLS-1$
StringBuilder uri = new StringBuilder(SEGMENT_REPOS);
- uri.append('/').append(user).append('/').append(repository);
+ uri.append('/').append(id);
uri.append(SEGMENT_ISSUES).append(SEGMENT_COMMENTS);
uri.append('/').append(commentId);
client.delete(uri.toString());

Back to the top