1 | "use strict";
|
2 | const awaiter_1 = require("./awaiter");
|
3 | const hosted_git_info_1 = require("hosted-git-info");
|
4 | const promisifed_fs_1 = require("./promisifed-fs");
|
5 | const path = require("path");
|
6 | const __awaiter = awaiter_1.tsAwaiter;
|
7 | Array.isArray(__awaiter);
|
8 | class InfoRetriever {
|
9 | getInfo(provider) {
|
10 | if (this._info == null) {
|
11 | this._info = getInfo(provider);
|
12 | }
|
13 | return this._info;
|
14 | }
|
15 | }
|
16 | exports.InfoRetriever = InfoRetriever;
|
17 | function getGitUrlFromGitConfig() {
|
18 | return __awaiter(this, void 0, void 0, function* () {
|
19 | let data = null;
|
20 | try {
|
21 | data = yield promisifed_fs_1.readText(path.join(".git", "config"));
|
22 | }
|
23 | catch (e) {
|
24 | if (e.code === "ENOENT") {
|
25 | return null;
|
26 | }
|
27 | throw e;
|
28 | }
|
29 | const conf = data.split(/\r?\n/);
|
30 | const i = conf.indexOf('[remote "origin"]');
|
31 | if (i !== -1) {
|
32 | let u = conf[i + 1];
|
33 | if (!u.match(/^\s*url =/)) {
|
34 | u = conf[i + 2];
|
35 | }
|
36 | if (u.match(/^\s*url =/)) {
|
37 | return u.replace(/^\s*url = /, "");
|
38 | }
|
39 | }
|
40 | return null;
|
41 | });
|
42 | }
|
43 | function getInfo(provider) {
|
44 | return __awaiter(this, void 0, void 0, function* () {
|
45 | const repo = provider.devMetadata.repository || provider.metadata.repository;
|
46 | if (repo == null) {
|
47 | let url = process.env.TRAVIS_REPO_SLUG;
|
48 | if (url == null) {
|
49 | const user = process.env.APPVEYOR_ACCOUNT_NAME || process.env.CIRCLE_PROJECT_USERNAME;
|
50 | const project = process.env.APPVEYOR_PROJECT_NAME || process.env.CIRCLE_PROJECT_REPONAME;
|
51 | if (user != null && project != null) {
|
52 | return {
|
53 | user: user,
|
54 | project: project,
|
55 | };
|
56 | }
|
57 | url = yield getGitUrlFromGitConfig();
|
58 | }
|
59 | if (url != null) {
|
60 | return hosted_git_info_1.fromUrl(url);
|
61 | }
|
62 | }
|
63 | else {
|
64 | return hosted_git_info_1.fromUrl(typeof repo === "string" ? repo : repo.url);
|
65 | }
|
66 | return null;
|
67 | });
|
68 | }
|
69 |
|
\ | No newline at end of file |