repositoryInfo.js
3.63 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getRepositoryInfo = getRepositoryInfo;
function _promise() {
const data = require("builder-util/out/promise");
_promise = function () {
return data;
};
return data;
}
function _fsExtra() {
const data = require("fs-extra");
_fsExtra = function () {
return data;
};
return data;
}
function _hostedGitInfo() {
const data = require("hosted-git-info");
_hostedGitInfo = function () {
return data;
};
return data;
}
var path = _interopRequireWildcard(require("path"));
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function getRepositoryInfo(projectDir, metadata, devMetadata) {
return _getInfo(projectDir, (devMetadata == null ? null : devMetadata.repository) || (metadata == null ? null : metadata.repository));
}
async function getGitUrlFromGitConfig(projectDir) {
const data = await (0, _promise().orNullIfFileNotExist)((0, _fsExtra().readFile)(path.join(projectDir, ".git", "config"), "utf8"));
if (data == null) {
return null;
}
const conf = data.split(/\r?\n/);
const i = conf.indexOf('[remote "origin"]');
if (i !== -1) {
let u = conf[i + 1];
if (!u.match(/^\s*url =/)) {
u = conf[i + 2];
}
if (u.match(/^\s*url =/)) {
return u.replace(/^\s*url = /, "");
}
}
return null;
}
async function _getInfo(projectDir, repo) {
if (repo != null) {
return parseRepositoryUrl(typeof repo === "string" ? repo : repo.url);
}
const slug = process.env.TRAVIS_REPO_SLUG || process.env.APPVEYOR_REPO_NAME;
if (slug != null) {
const splitted = slug.split("/");
return {
user: splitted[0],
project: splitted[1]
};
}
const user = process.env.CIRCLE_PROJECT_USERNAME;
const project = process.env.CIRCLE_PROJECT_REPONAME;
if (user != null && project != null) {
return {
user,
project
};
}
const url = await getGitUrlFromGitConfig(projectDir);
return url == null ? null : parseRepositoryUrl(url);
}
function parseRepositoryUrl(url) {
const info = (0, _hostedGitInfo().fromUrl)(url);
if (info != null) {
delete info.protocols;
delete info.treepath;
delete info.filetemplate;
delete info.bugstemplate;
delete info.gittemplate;
delete info.tarballtemplate;
delete info.sshtemplate;
delete info.sshurltemplate;
delete info.browsetemplate;
delete info.docstemplate;
delete info.httpstemplate;
delete info.shortcuttemplate;
delete info.pathtemplate;
delete info.pathmatch;
delete info.protocols_re;
delete info.committish;
delete info.default;
delete info.opts;
delete info.browsefiletemplate;
delete info.auth;
}
return info;
}
// __ts-babel@6.0.4
//# sourceMappingURL=repositoryInfo.js.map