repositoryInfo.js 3.79 KB
Newer Older
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 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.getRepositoryInfo = getRepositoryInfo;

function _bluebirdLst() {
  const data = require("bluebird-lst");

  _bluebirdLst = function () {
    return data;
  };

  return data;
}

function _promise() {
  const data = require("builder-util/out/promise");

  _promise = function () {
    return data;
  };

  return data;
}

function _fsExtraP() {
  const data = require("fs-extra-p");

  _fsExtraP = 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 _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; } }

function getRepositoryInfo(projectDir, metadata, devMetadata) {
  return _getInfo(projectDir, (devMetadata == null ? null : devMetadata.repository) || (metadata == null ? null : metadata.repository));
}

function getGitUrlFromGitConfig(_x) {
  return _getGitUrlFromGitConfig.apply(this, arguments);
}

function _getGitUrlFromGitConfig() {
  _getGitUrlFromGitConfig = (0, _bluebirdLst().coroutine)(function* (projectDir) {
    const data = yield (0, _promise().orNullIfFileNotExist)((0, _fsExtraP().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;
  });
  return _getGitUrlFromGitConfig.apply(this, arguments);
}

function _getInfo(_x2, _x3) {
  return _getInfo2.apply(this, arguments);
}

function _getInfo2() {
  _getInfo2 = (0, _bluebirdLst().coroutine)(function* (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 = yield getGitUrlFromGitConfig(projectDir);
    return url == null ? null : parseRepositoryUrl(url);
  });
  return _getInfo2.apply(this, arguments);
}

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