Skip to content

Commit

Permalink
Overload methods to take an IRepositoryProvider
Browse files Browse the repository at this point in the history
This is an alternative to take a String owner and name

Change-Id: Id164e5173fcdba51bcf68aab9069ce5619bd4586
  • Loading branch information
kevinsawicki committed Jan 10, 2012
1 parent e270b86 commit cf317d7
Show file tree
Hide file tree
Showing 2 changed files with 252 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,19 @@ public void createIssueNullIssue() throws IOException {
new HashMap<String, String>(), Issue.class);
}

/**
* 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
*
Expand Down Expand Up @@ -473,6 +486,28 @@ public void editIssue() throws IOException {
params, Issue.class);
}

/**
* 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
*
Expand Down Expand Up @@ -550,6 +585,22 @@ public void createComment() throws IOException {
Comment.class);
}

/**
* 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
*
Expand Down Expand Up @@ -621,6 +672,18 @@ public void deleteComment() throws IOException {
verify(gitHubClient).delete("/repos/user/repo/issues/comments/1");
}

/**
* 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
*
Expand Down Expand Up @@ -752,4 +815,18 @@ public void editIssueComment() throws IOException {
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -608,8 +608,36 @@ public Issue createIssue(String user, String repository, Issue issue)
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);
Expand All @@ -628,11 +656,40 @@ public Issue createIssue(String user, String repository, Issue issue)
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());

Expand Down Expand Up @@ -672,13 +729,58 @@ public Comment createComment(String user, String repository, int issueId,
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);
Expand Down Expand Up @@ -724,11 +826,40 @@ public Comment getComment(String user, String repository, long commentId)
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);
Expand Down Expand Up @@ -758,13 +889,52 @@ public void deleteComment(String user, String repository, long commentId)
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());
Expand Down

0 comments on commit cf317d7

Please sign in to comment.