-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
repository.js
58 lines (47 loc) · 1.29 KB
/
repository.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
49
50
51
52
53
54
55
56
57
58
'use strict';
const git = require('./helpers/git');
const getOwner = require('./helpers/owner');
const utils = require('../utils');
const merge = require('../merge');
module.exports = function(val, key, config, schema) {
merge(config, schema);
let owner = config.owner;
val = val || config[key];
if (schema.checked[key]) {
return val;
}
if (utils.isObject(val) && val.url) {
val = val.url;
}
if (!utils.isString(val)) {
const parsed = git(val, key, config, schema);
const remote = utils.get(parsed, 'remote.origin.url');
if (parsed.user && parsed.user.username) {
owner = parsed.user.username;
config.owner = owner;
schema.checked.owner = true;
}
if (remote) {
const expanded = utils.repo.expandUrl(remote);
const data = utils.merge({}, expanded, config);
utils.merge(config, data);
schema.data.merge(data);
}
}
if (!utils.isString(val) && config.homepage) {
val = config.homepage;
}
if (!owner) {
owner = getOwner(val, key, config, schema);
}
if (config.name && owner) {
val = owner + '/' + config.name;
}
if (utils.isString(val)) {
schema.checked[key] = true;
return utils.repo.repository(val);
}
// if not returned already, val is invalid
delete config[key];
return;
};