|
6 | 6 | import org.apache.commons.logging.Log; |
7 | 7 | import org.apache.commons.logging.LogFactory; |
8 | 8 | import org.eclipse.egit.github.core.Repository; |
| 9 | +import org.eclipse.egit.github.core.User; |
9 | 10 | import org.gitlab.api.GitlabAPI; |
10 | 11 | import org.gitlab.api.models.GitlabProject; |
| 12 | +import org.gitlab.api.models.GitlabUser; |
11 | 13 | import org.springframework.beans.factory.annotation.Autowired; |
| 14 | +import org.springframework.http.HttpStatus; |
| 15 | +import org.springframework.http.ResponseEntity; |
12 | 16 | import org.springframework.stereotype.Controller; |
13 | 17 | import org.springframework.web.bind.annotation.PathVariable; |
14 | 18 | import org.springframework.web.bind.annotation.RequestHeader; |
@@ -43,4 +47,19 @@ public List<Repository> getReposForUser( |
43 | 47 | return GitlabToGithubConverter.convertRepositories(projects); |
44 | 48 | } |
45 | 49 |
|
| 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 | + |
46 | 65 | } |
0 commit comments