Skip to content

Commit 4c804c7

Browse files
committed
#6 Support user retrieval
1 parent 69a5c53 commit 4c804c7

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

src/main/java/com/dkaedv/glghproxy/controller/UsersController.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,13 @@
66
import org.apache.commons.logging.Log;
77
import org.apache.commons.logging.LogFactory;
88
import org.eclipse.egit.github.core.Repository;
9+
import org.eclipse.egit.github.core.User;
910
import org.gitlab.api.GitlabAPI;
1011
import org.gitlab.api.models.GitlabProject;
12+
import org.gitlab.api.models.GitlabUser;
1113
import org.springframework.beans.factory.annotation.Autowired;
14+
import org.springframework.http.HttpStatus;
15+
import org.springframework.http.ResponseEntity;
1216
import org.springframework.stereotype.Controller;
1317
import org.springframework.web.bind.annotation.PathVariable;
1418
import org.springframework.web.bind.annotation.RequestHeader;
@@ -43,4 +47,19 @@ public List<Repository> getReposForUser(
4347
return GitlabToGithubConverter.convertRepositories(projects);
4448
}
4549

50+
@RequestMapping("/{username}")
51+
public ResponseEntity<User> getUser(
52+
@PathVariable String username,
53+
@RequestHeader("Authorization") String authorization) throws IOException {
54+
55+
GitlabAPI api = gitlab.connect(authorization);
56+
List<GitlabUser> users = api.findUsers(username);
57+
58+
if (users.size() >= 1) {
59+
return new ResponseEntity<User>(GitlabToGithubConverter.convertUser(users.get(0)), HttpStatus.OK);
60+
} else {
61+
return new ResponseEntity<User>(HttpStatus.NOT_FOUND);
62+
}
63+
}
64+
4665
}

src/main/java/com/dkaedv/glghproxy/converter/GitlabToGithubConverter.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,11 @@ private static PullRequest convertMergeRequest(GitlabMergeRequest glmr) {
193193
pull.setUpdatedAt(glmr.getCreatedAt());
194194
}
195195

196+
if (pull.isMerged()) {
197+
pull.setMergedAt(glmr.getUpdatedAt());
198+
pull.setMergedBy(convertUser(glmr.getAssignee()));
199+
}
200+
196201
return pull;
197202
}
198203

@@ -234,7 +239,7 @@ private static Milestone convertMilestone(GitlabMilestone glmilestone) {
234239
return milestone;
235240
}
236241

237-
private static User convertUser(GitlabUser gluser) {
242+
public static User convertUser(GitlabUser gluser) {
238243
if (gluser == null) {
239244
return null;
240245
}

0 commit comments

Comments
 (0)