1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.getRepositoryInfo = getRepositoryInfo;
|
7 |
|
8 | function _bluebirdLst() {
|
9 | const data = require("bluebird-lst");
|
10 |
|
11 | _bluebirdLst = function () {
|
12 | return data;
|
13 | };
|
14 |
|
15 | return data;
|
16 | }
|
17 |
|
18 | function _promise() {
|
19 | const data = require("builder-util/out/promise");
|
20 |
|
21 | _promise = function () {
|
22 | return data;
|
23 | };
|
24 |
|
25 | return data;
|
26 | }
|
27 |
|
28 | function _fsExtraP() {
|
29 | const data = require("fs-extra-p");
|
30 |
|
31 | _fsExtraP = function () {
|
32 | return data;
|
33 | };
|
34 |
|
35 | return data;
|
36 | }
|
37 |
|
38 | function _hostedGitInfo() {
|
39 | const data = require("hosted-git-info");
|
40 |
|
41 | _hostedGitInfo = function () {
|
42 | return data;
|
43 | };
|
44 |
|
45 | return data;
|
46 | }
|
47 |
|
48 | var path = _interopRequireWildcard(require("path"));
|
49 |
|
50 | let getGitUrlFromGitConfig = (() => {
|
51 | var _ref = (0, _bluebirdLst().coroutine)(function* (projectDir) {
|
52 | const data = yield (0, _promise().orNullIfFileNotExist)((0, _fsExtraP().readFile)(path.join(projectDir, ".git", "config"), "utf8"));
|
53 |
|
54 | if (data == null) {
|
55 | return null;
|
56 | }
|
57 |
|
58 | const conf = data.split(/\r?\n/);
|
59 | const i = conf.indexOf('[remote "origin"]');
|
60 |
|
61 | if (i !== -1) {
|
62 | let u = conf[i + 1];
|
63 |
|
64 | if (!u.match(/^\s*url =/)) {
|
65 | u = conf[i + 2];
|
66 | }
|
67 |
|
68 | if (u.match(/^\s*url =/)) {
|
69 | return u.replace(/^\s*url = /, "");
|
70 | }
|
71 | }
|
72 |
|
73 | return null;
|
74 | });
|
75 |
|
76 | return function getGitUrlFromGitConfig(_x) {
|
77 | return _ref.apply(this, arguments);
|
78 | };
|
79 | })();
|
80 |
|
81 | let _getInfo = (() => {
|
82 | var _ref2 = (0, _bluebirdLst().coroutine)(function* (projectDir, repo) {
|
83 | if (repo != null) {
|
84 | return parseRepositoryUrl(typeof repo === "string" ? repo : repo.url);
|
85 | }
|
86 |
|
87 | const slug = process.env.TRAVIS_REPO_SLUG || process.env.APPVEYOR_REPO_NAME;
|
88 |
|
89 | if (slug != null) {
|
90 | const splitted = slug.split("/");
|
91 | return {
|
92 | user: splitted[0],
|
93 | project: splitted[1]
|
94 | };
|
95 | }
|
96 |
|
97 | const user = process.env.CIRCLE_PROJECT_USERNAME;
|
98 | const project = process.env.CIRCLE_PROJECT_REPONAME;
|
99 |
|
100 | if (user != null && project != null) {
|
101 | return {
|
102 | user,
|
103 | project
|
104 | };
|
105 | }
|
106 |
|
107 | const url = yield getGitUrlFromGitConfig(projectDir);
|
108 | return url == null ? null : parseRepositoryUrl(url);
|
109 | });
|
110 |
|
111 | return function _getInfo(_x2, _x3) {
|
112 | return _ref2.apply(this, arguments);
|
113 | };
|
114 | })();
|
115 |
|
116 | function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
|
117 |
|
118 | function getRepositoryInfo(projectDir, metadata, devMetadata) {
|
119 | return _getInfo(projectDir, (devMetadata == null ? null : devMetadata.repository) || (metadata == null ? null : metadata.repository));
|
120 | }
|
121 |
|
122 | function parseRepositoryUrl(url) {
|
123 | const info = (0, _hostedGitInfo().fromUrl)(url);
|
124 |
|
125 | if (info != null) {
|
126 | delete info.protocols;
|
127 | delete info.treepath;
|
128 | delete info.filetemplate;
|
129 | delete info.bugstemplate;
|
130 | delete info.gittemplate;
|
131 | delete info.tarballtemplate;
|
132 | delete info.sshtemplate;
|
133 | delete info.sshurltemplate;
|
134 | delete info.browsetemplate;
|
135 | delete info.docstemplate;
|
136 | delete info.httpstemplate;
|
137 | delete info.shortcuttemplate;
|
138 | delete info.pathtemplate;
|
139 | delete info.pathmatch;
|
140 | delete info.protocols_re;
|
141 | delete info.committish;
|
142 | delete info.default;
|
143 | delete info.opts;
|
144 | delete info.browsefiletemplate;
|
145 | delete info.auth;
|
146 | }
|
147 |
|
148 | return info;
|
149 | }
|
150 |
|
\ | No newline at end of file |