function main()

in packages/actions/deployWeb.js [12:83]


function main(params) {
  const activationId = process.env.__OW_ACTIVATION_ID;
  // Grab optional envData and manifestPath params for wskdeploy
  let {
    envData,
    manifestPath,
    gitUrl
  } = params;

  // confirm gitUrl was provided as a parameter
  if (!gitUrl) {
    return sendError(400, new Error('Please enter the GitHub repo url in params'));
  }

  if (params.__ow_method === "post") {
    return new Promise((resolve, reject) => {
      // if no manifestPath was provided, use current directory
      if (!manifestPath) {
        manifestPath = '.';
      }
      // Grab wsp api host and auth from params, or process.env
      const { wskApiHost, wskAuth } = getWskApiAuth(params);

      // Extract the name of the repo for the tmp directory
      const tmpUrl = gitUrl.replace('https://', '');
      const repoSplit = tmpUrl.split('/');
      const repoOrg = repoSplit[1];
      const repoName = repoSplit[2];
      const localDirName = `${__dirname}/../tmp/${repoOrg}/${repoName}`;

      // any pre installed github repos should be a sibling to this package in "preInstalled" folder
      const templatesDirName = `${__dirname}/preInstalled/${repoOrg}/${repoName}`;

      if (fs.existsSync(templatesDirName)) {
        resolve({
          repoDir: templatesDirName,
          usingTemp: false,
          manifestPath,
          manifestFileName: 'manifest.yaml',
          wskAuth,
          wskApiHost,
          envData,
        });
      } else {
        return git().clone(gitUrl, localDirName, ['--depth', '1'], (err) => {
          if (err) {
            reject(new Error('There was a problem cloning from github.  Does that github repo exist?  Does it begin with http?'));
          }
          resolve({
            repoDir: localDirName,
            usingTemp: true,
            manifestPath,
            manifestFileName: 'manifest.yaml',
            wskAuth,
            wskApiHost,
            envData,
          });
        });
      }
    })
      .then(result => common.main(result))
      .then(success =>
        new Promise((resolve, reject) => {
          resolve({
            statusCode: 200,
            headers: { 'Content-Type': 'application/json' },
            body: { status: success, activationId },
          });
        }))
      .catch(err => (sendError(400, err)));
  }
}