-
Notifications
You must be signed in to change notification settings - Fork 0
/
getRepository.js
48 lines (39 loc) · 1.15 KB
/
getRepository.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/**
* @see
* REST API v3: Repositories, vi. Get
* https://developer.github.com/v3/repos/#get
*/
'use strict';
const MODULE_REQUIRE = 1
/* built-in */
/* NPM */
, co = require('co')
, noda = require('noda')
/* in-package */
, getGithubAgent = noda.inRequire('lib/getGithubAgent')
, whoami = require('./whoami')
;
/**
* @param {string} [options.token]
* @param {string} [options.username] username of repository's owner
* @param {string} options.name repository name
* @return {Promise}
*/
function getRepository(options) {
let _agent = getGithubAgent(options);
return co(function*() {
// Get username from options or via owner of current token.
let username = options.username;
if (!username) {
let user = yield whoami(options);
if (user) username = user.login;
}
if (!username) {
throw new Error('username expected');
}
let urlname = `/repos/${username}/${options.name}`;
let repo = yield _agent.get(urlname);
return repo;
});
};
module.exports = getRepository;