Skip to content

Commit 17c54eb

Browse files
committed
Minor bug fixes.
1 parent 4c063d8 commit 17c54eb

File tree

10 files changed

+50
-50
lines changed

10 files changed

+50
-50
lines changed

core/src/main/java/com/github/api/v2/services/IssueService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public interface IssueService extends GitHubService {
111111
* @param body
112112
* the body
113113
*/
114-
public void createIssue(String userName, String repositoryName, String title, String body);
114+
public Issue createIssue(String userName, String repositoryName, String title, String body);
115115

116116
/**
117117
* Close issue.

core/src/main/java/com/github/api/v2/services/OrganizationService.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.util.List;
2020

2121
import com.github.api.v2.schema.Organization;
22+
import com.github.api.v2.schema.Permission;
2223
import com.github.api.v2.schema.Repository;
2324
import com.github.api.v2.schema.Team;
2425
import com.github.api.v2.schema.User;
@@ -96,7 +97,7 @@ public interface OrganizationService extends GitHubService {
9697
* @param team
9798
* the team
9899
*/
99-
public void createTeam(Team team);
100+
public Team createTeam(String organizationName, String teamName, Permission permission, List<String> repoNames);
100101

101102
/**
102103
* Gets the team.
@@ -172,7 +173,7 @@ public interface OrganizationService extends GitHubService {
172173
* @param repositoryName
173174
* the repository name
174175
*/
175-
public void addTeamRepository(String userName, String repositoryName);
176+
public void addTeamRepository(String teamId, String userName, String repositoryName);
176177

177178
/**
178179
* Removes the team repository.

core/src/main/java/com/github/api/v2/services/PullRequestService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,5 +82,5 @@ public interface PullRequestService extends GitHubService {
8282
* @param body
8383
* the body
8484
*/
85-
public void createPullRequest(String userName, String repositoryName, String base, String head, String title, String body);
85+
public PullRequest createPullRequest(String userName, String repositoryName, String base, String head, String title, String body);
8686
}

core/src/main/java/com/github/api/v2/services/RepositoryService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ public interface RepositoryService extends GitHubService {
153153
* @param visibility
154154
* the visibility
155155
*/
156-
public void createRepository(String name, String description, String homePage, Visibility visibility);
156+
public Repository createRepository(String name, String description, String homePage, Visibility visibility);
157157

158158
/**
159159
* Delete repository.

core/src/main/java/com/github/api/v2/services/constant/ParameterNames.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,19 +52,19 @@ public interface ParameterNames {
5252
public static final String FILE_NAME = "fileName";
5353

5454
/** The Constant NET_HASH. */
55-
public static final String NET_HASH = "netHash";
55+
public static final String NET_HASH = "nethash";
5656

5757
/** The Constant START_INDEX. */
58-
public static final String START_INDEX = "startIndex";
58+
public static final String START_INDEX = "start";
5959

6060
/** The Constant END_INDEX. */
61-
public static final String END_INDEX = "endIndex";
61+
public static final String END_INDEX = "end";
6262

6363
/** The Constant LANGUAGE. */
6464
public static final String LANGUAGE = "language";
6565

6666
/** The Constant START_PAGE. */
67-
public static final String START_PAGE = "startPage";
67+
public static final String START_PAGE = "start_page";
6868

6969
/** The Constant VISIBILITY. */
7070
public static final String VISIBILITY = "visibility";
@@ -156,9 +156,6 @@ public interface ParameterNames {
156156
/** The Constant NUM. */
157157
public static final String NUM = "num";
158158

159-
/** The Constant USER_REPOSITORY_PAIR. */
160-
public static final String USER_REPOSITORY_PAIR = "userRepositoryPair";
161-
162159
/** The Constant ORGANIZATION_NAME. */
163160
public static final String ORGANIZATION_NAME = "organizationName";
164161

core/src/main/java/com/github/api/v2/services/impl/IssueServiceImpl.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,16 @@ public void closeIssue(String userName, String repositoryName,
7777
* @see com.github.api.v2.services.IssueService#createIssue(java.lang.String, java.lang.String, java.lang.String, java.lang.String)
7878
*/
7979
@Override
80-
public void createIssue(String userName, String repositoryName,
80+
public Issue createIssue(String userName, String repositoryName,
8181
String title, String body) {
8282
GitHubApiUrlBuilder builder = createGitHubApiUrlBuilder(GitHubApiUrls.IssueApiUrls.CREATE_ISSUE_URL);
8383
String apiUrl = builder.withField(ParameterNames.USER_NAME, userName).withField(ParameterNames.REPOSITORY_NAME, repositoryName).buildUrl();
8484
Map<String, String> parameters = new HashMap<String, String>();
8585
parameters.put(ParameterNames.TITLE, title);
8686
parameters.put(ParameterNames.BODY, body);
87-
callApiPost(apiUrl, parameters);
87+
JsonObject json = unmarshall(callApiPost(apiUrl, parameters));
88+
89+
return unmarshall(new TypeToken<Issue>(){}, json.get("issue"));
8890
}
8991

9092
/* (non-Javadoc)

core/src/main/java/com/github/api/v2/services/impl/OrganizationServiceImpl.java

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,15 @@
2121
import java.util.Map;
2222

2323
import com.github.api.v2.schema.Organization;
24+
import com.github.api.v2.schema.Permission;
2425
import com.github.api.v2.schema.Repository;
2526
import com.github.api.v2.schema.Team;
2627
import com.github.api.v2.schema.User;
2728
import com.github.api.v2.services.OrganizationService;
2829
import com.github.api.v2.services.constant.GitHubApiUrls;
2930
import com.github.api.v2.services.constant.ParameterNames;
3031
import com.github.api.v2.services.constant.GitHubApiUrls.GitHubApiUrlBuilder;
31-
import com.google.gson.GsonBuilder;
32+
import com.google.gson.Gson;
3233
import com.google.gson.JsonObject;
3334
import com.google.gson.reflect.TypeToken;
3435

@@ -38,48 +39,46 @@
3839
public class OrganizationServiceImpl extends BaseGitHubService implements
3940
OrganizationService {
4041

41-
42-
/* (non-Javadoc)
43-
* @see com.github.api.v2.services.impl.BaseGitHubService#getGsonBuilder()
44-
*/
45-
protected GsonBuilder getGsonBuilder() {
46-
GsonBuilder gson = super.getGsonBuilder();
47-
gson.setDateFormat("yyyy-MM-dd'T'HH:mm:ss");
48-
return gson;
49-
}
50-
5142
/* (non-Javadoc)
5243
* @see com.github.api.v2.services.OrganizationService#addTeamMember(java.lang.String, java.lang.String)
5344
*/
5445
@Override
5546
public void addTeamMember(String teamId, String userName) {
5647
GitHubApiUrlBuilder builder = createGitHubApiUrlBuilder(GitHubApiUrls.OrganizationApiUrls.ADD_TEAM_MEMBER_URL);
57-
String apiUrl = builder.withField(ParameterNames.TEAM_ID, teamId).withParameter(ParameterNames.NAME, userName).buildUrl();
58-
unmarshall(callApiPost(apiUrl, new HashMap<String, String>()));
48+
String apiUrl = builder.withField(ParameterNames.TEAM_ID, teamId).buildUrl();
49+
Map<String, String> parameters = new HashMap<String, String>();
50+
parameters.put(ParameterNames.NAME, userName);
51+
unmarshall(callApiPost(apiUrl, parameters));
5952
}
6053

6154
/* (non-Javadoc)
6255
* @see com.github.api.v2.services.OrganizationService#addTeamRepository(java.lang.String, java.lang.String)
6356
*/
6457
@Override
65-
public void addTeamRepository(String userName, String repositoryName) {
58+
public void addTeamRepository(String teamId, String userName, String repositoryName) {
6659
GitHubApiUrlBuilder builder = createGitHubApiUrlBuilder(GitHubApiUrls.OrganizationApiUrls.ADD_TEAM_REPOSITORY_URL);
67-
String apiUrl = builder.withParameter(ParameterNames.USER_REPOSITORY_PAIR, userName + "/" + repositoryName).buildUrl();
68-
unmarshall(callApiPost(apiUrl, new HashMap<String, String>()));
60+
String apiUrl = builder.withField(ParameterNames.TEAM_ID, teamId).buildUrl();
61+
Map<String, String> parameters = new HashMap<String, String>();
62+
parameters.put(ParameterNames.NAME, userName + "/" + repositoryName);
63+
unmarshall(callApiPost(apiUrl, parameters));
6964
}
7065

7166
/* (non-Javadoc)
7267
* @see com.github.api.v2.services.OrganizationService#createTeam(com.github.api.v2.schema.Team)
7368
*/
7469
@Override
75-
public void createTeam(Team team) {
70+
public Team createTeam(String organizationName, String teamName, Permission permission, List<String> repoNames) {
7671
GitHubApiUrlBuilder builder = createGitHubApiUrlBuilder(GitHubApiUrls.OrganizationApiUrls.CREATE_TEAM_URL);
77-
String apiUrl = builder.buildUrl();
72+
String apiUrl = builder.withField(ParameterNames.ORGANIZATION_NAME, organizationName).buildUrl();
7873
Map<String, String> parameters = new HashMap<String, String>();
79-
parameters.put("team[" + ParameterNames.NAME + "]", team.getName());
80-
parameters.put("team[" + ParameterNames.PERMISSION + "]", team.getPermission().value());
81-
parameters.put("team[" + ParameterNames.REPO_NAMES + "]", team.getRepoNames().toString());
82-
callApiPost(apiUrl, parameters);
74+
parameters.put("team[" + ParameterNames.NAME + "]", teamName);
75+
parameters.put("team[" + ParameterNames.PERMISSION + "]", permission.value());
76+
for (String repoName : repoNames) {
77+
parameters.put("team[" + ParameterNames.REPO_NAMES + "][]", repoName);
78+
}
79+
JsonObject json = unmarshall(callApiPost(apiUrl, parameters));
80+
81+
return unmarshall(new TypeToken<Team>(){}, json.get("team"));
8382
}
8483

8584
/* (non-Javadoc)
@@ -111,11 +110,10 @@ public List<Repository> getAllOrganizationRepositories() {
111110
public Organization getOrganization(String name) {
112111
GitHubApiUrlBuilder builder = createGitHubApiUrlBuilder(GitHubApiUrls.OrganizationApiUrls.GET_ORGANIZATION_URL);
113112
String apiUrl = builder.withField(ParameterNames.ORGANIZATION_NAME, name).buildUrl();
114-
System.out.println(convertStreamToString(callApiGet(apiUrl)));
115-
// JsonObject json = unmarshall(callApiGet(apiUrl));
116-
//
117-
// return unmarshall(new TypeToken<Organization>(){}, json.get("organization"));
118-
return new Organization();
113+
JsonObject json = unmarshall(callApiGet(apiUrl));
114+
115+
Gson gson = getGsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ss").create();
116+
return gson.fromJson(json.get("organization"), new TypeToken<Organization>(){}.getType());
119117
}
120118

121119
/* (non-Javadoc)

core/src/main/java/com/github/api/v2/services/impl/PullRequestServiceImpl.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,17 @@ public List<PullRequest> getPullRequests(String userName, String repositoryName,
7575
/* (non-Javadoc)
7676
* @see com.github.api.v2.services.ObjectService#getObjectContent(java.lang.String, java.lang.String, java.lang.String)
7777
*/
78-
public void createPullRequest(String userName, String repositoryName, String base, String head, String title, String body) {
78+
public PullRequest createPullRequest(String userName, String repositoryName, String base, String head, String title, String body) {
7979
GitHubApiUrlBuilder builder = createGitHubApiUrlBuilder(GitHubApiUrls.PullRequestApiUrls.CREATE_PULL_REQUEST_URL);
8080
String apiUrl = builder.withField(ParameterNames.USER_NAME, userName).withField(ParameterNames.REPOSITORY_NAME, repositoryName).buildUrl();
8181
Map<String, String> parameters = new HashMap<String, String>();
8282
parameters.put("pull[" + ParameterNames.BASE + "]", base);
8383
parameters.put("pull[" + ParameterNames.HEAD + "]", head);
8484
parameters.put("pull[" + ParameterNames.TITLE + "]", title);
8585
parameters.put("pull[" + ParameterNames.BODY + "]", body);
86-
callApiPost(apiUrl, parameters);
86+
JsonObject json = unmarshall(callApiPost(apiUrl, parameters));
87+
88+
return unmarshall(new TypeToken<PullRequest>(){}, json.get("pull"));
8789
}
8890

8991
/* (non-Javadoc)

core/src/main/java/com/github/api/v2/services/impl/RepositoryServiceImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public void changeVisibility(String repositoryName, Visibility visibility) {
8080
* @see com.github.api.v2.services.RepositoryService#createRepository(java.lang.String, java.lang.String, java.lang.String, com.github.api.v2.schema.Repository.Visibility)
8181
*/
8282
@Override
83-
public void createRepository(String name, String description,
83+
public Repository createRepository(String name, String description,
8484
String homePage, Visibility visibility) {
8585
GitHubApiUrlBuilder builder = createGitHubApiUrlBuilder(GitHubApiUrls.RepositoryApiUrls.CREATE_REPOSITORY_URL);
8686
String apiUrl = builder.buildUrl();
@@ -91,7 +91,7 @@ public void createRepository(String name, String description,
9191
parameters.put(ParameterNames.PUBLIC, ((visibility == Visibility.PUBLIC)? "1" : "0"));
9292
JsonObject json = unmarshall(callApiPost(apiUrl, parameters));
9393

94-
unmarshall(new TypeToken<Repository>(){}, json.get("repository"));
94+
return unmarshall(new TypeToken<Repository>(){}, json.get("repository"));
9595
}
9696

9797
/* (non-Javadoc)

core/src/main/resources/com/github/api/v2/services/constant/GitHubApiUrls.properties

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ com.github.api.v2.services.gistService.getUserGists=http://gist.github.com/api/v
4747

4848
# Network API
4949
com.github.api.v2.services.networkService.getNetworkMeta=http://github.com/{userName}/{repositoryName}/network_meta
50-
com.github.api.v2.services.networkService.getNetworkData=http://github.com/{userName}/{repositoryName}/network_data_chunk?{netHash}{startIndex}{endIndex}
50+
com.github.api.v2.services.networkService.getNetworkData=http://github.com/{userName}/{repositoryName}/network_data_chunk?{nethash}{start}{end}
5151

5252
# Repository API
53-
com.github.api.v2.services.repositoryService.searchRepositories=http://github.com/api/{version}/{format}/repos/search/{keyword}?{language}{startPage}
53+
com.github.api.v2.services.repositoryService.searchRepositories=http://github.com/api/{version}/{format}/repos/search/{keyword}?{language}{start_page}
5454
com.github.api.v2.services.repositoryService.getRepository=http://github.com/api/{version}/{format}/repos/show/{userName}/{repositoryName}
5555
com.github.api.v2.services.repositoryService.updateRepository=http://github.com/api/{version}/{format}/repos/show/{userName}/{repositoryName}
5656
com.github.api.v2.services.repositoryService.getRepositories=http://github.com/api/{version}/{format}/repos/show/{userName}
@@ -100,10 +100,10 @@ com.github.api.v2.services.organizationService.updateTeam=http://github.com/api/
100100
com.github.api.v2.services.organizationService.deleteTeam=http://github.com/api/{version}/{format}/teams/{teamId}
101101
com.github.api.v2.services.organizationService.getTeamMembers=http://github.com/api/{version}/{format}/teams/{teamId}/members
102102
com.github.api.v2.services.organizationService.addTeamMember=http://github.com/api/{version}/{format}/teams/{teamId}/members
103-
com.github.api.v2.services.organizationService.removeTeamMember=http://github.com/api/{version}/{format}/teams/{teamId}/members?name={userName}
103+
com.github.api.v2.services.organizationService.removeTeamMember=http://github.com/api/{version}/{format}/teams/{teamId}/members?{name}
104104
com.github.api.v2.services.organizationService.getTeamRepositories=http://github.com/api/{version}/{format}/teams/{teamId}/repositories
105-
com.github.api.v2.services.organizationService.addTeamRepository=http://github.com/api/{version}/{format}/teams/{teamId}/repositories?name={userName}
106-
com.github.api.v2.services.organizationService.removeTeamRepository=http://github.com/api/{version}/{format}/teams/{teamId}/repositories?name={userRepositoryPair}
105+
com.github.api.v2.services.organizationService.addTeamRepository=http://github.com/api/{version}/{format}/teams/{teamId}/repositories
106+
com.github.api.v2.services.organizationService.removeTeamRepository=http://github.com/api/{version}/{format}/teams/{teamId}/repositories?{name}
107107

108108
# Pull Request API
109109
com.github.api.v2.services.pullRequestService.createPullRequest=http://github.com/api/{version}/{format}/pulls/{userName}/{repositoryName}

0 commit comments

Comments
 (0)