3 var collections = require('gitter-web-utils/lib/collections');
4 var TroupeStrategy = require('./troupe-strategy');
5 var leanTroupeDao = require('../../services/daos/troupe-dao').full;
6 var Lazy = require('lazy.js');
7 const urlJoin = require('url-join');
9 function GithubRepoStrategy(options) {
10 var troupeStrategy = new TroupeStrategy(options);
13 this.preload = function(repos) {
14 if (repos.isEmpty()) return;
16 var repoFullNames = repos
18 return repo.full_name;
22 return leanTroupeDao.findByUris(repoFullNames).then(function(troupes) {
23 troupesIndexed = collections.indexByProperty(troupes, 'uri');
25 return troupeStrategy.preload(Lazy(troupes));
29 this.map = function(item) {
30 var room = troupesIndexed[item.full_name];
35 description: item.description,
36 absoluteUri: urlJoin('https://github.com', item.full_name),
38 private: item.private,
39 room: room ? troupeStrategy.map(room) : undefined,
41 avatar_url: item.owner.avatar_url
46 GithubRepoStrategy.prototype = {
47 name: 'GithubRepoStrategy'
50 module.exports = GithubRepoStrategy;