3 var GithubRepo = require('gitter-web-github').GitHubRepoService;
4 const { GitLabProjectService } = require('gitter-web-gitlab');
5 var isGitHubUser = require('gitter-web-identity/lib/is-github-user');
6 const identityService = require('gitter-web-identity');
8 getAdminProjectsForUser
9 } = require('gitter-web-permissions/lib/admin-discovery/gitlab-project');
11 // https://docs.gitlab.com/ee/api/access_requests.html
12 const GUEST_ACCESS_LEVEL = 10;
15 * Gets a list of GitHub repos for a user
16 * @returns The promise of a list of repos for the user
18 async function _getGitHubReposForUser(user) {
19 const ghRepo = new GithubRepo(user);
20 return ghRepo.getAllReposForAuthUser().map(repo => {
21 repo.backend = 'github';
27 * Gets a list of repos for a user
28 * @returns The promise of a list of repos for the user
30 async function getReposForUser(user) {
31 if (isGitHubUser(user)) {
32 return _getGitHubReposForUser(user);
35 const gitLabIdentity = await identityService.getIdentityForUser(
37 identityService.GITLAB_IDENTITY_PROVIDER
40 const gitlabProjectService = new GitLabProjectService(user);
41 return gitlabProjectService.getProjects({
43 min_access_level: GUEST_ACCESS_LEVEL
52 * @returns The promise of a list of repos for the user
54 async function getAdminReposForUser(user) {
55 if (isGitHubUser(user)) {
56 const repos = await _getGitHubReposForUser(user);
58 return repos.filter(function(repo) {
59 if (repo) return repo.permissions && (repo.permissions.push || repo.permissions.admin);
63 const gitLabIdentity = await identityService.getIdentityForUser(
65 identityService.GITLAB_IDENTITY_PROVIDER
68 return getAdminProjectsForUser(user);
75 getReposForUser: getReposForUser,
76 getAdminReposForUser: getAdminReposForUser