UNPKG

@atomist/automation-client

Version:
45 lines 2.22 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const _ = require("lodash"); const logger_1 = require("../../internal/util/logger"); const GitCommandGitProject_1 = require("../../project/git/GitCommandGitProject"); const retry_1 = require("../../util/retry"); const GitHubRepoRef_1 = require("../common/GitHubRepoRef"); const RepoId_1 = require("../common/RepoId"); /** * Persist project to GitHub or another remote, returning remote details. Use retry. * @param {Project} p project to persist * @param {ProjectOperationCredentials} creds * @param targetId id of target repo to create * @return {Promise<ActionResult<GitProject>>} */ exports.RemoteGitProjectPersister = (p, creds, targetId, params) => { // Default to github.com if we don't have more information const gid = RepoId_1.isRemoteRepoRef(targetId) ? targetId : new GitHubRepoRef_1.GitHubRepoRef(targetId.owner, targetId.repo); const gp = GitCommandGitProject_1.GitCommandGitProject.fromProject(p, creds); return gp.init() .then(() => { return GitHubRepoRef_1.isGitHubRepoRef(gid) ? gp.configureFromRemote() : {}; }) .then(() => { logger_1.logger.debug(`Creating new repo '${targetId.owner}/${targetId.repo}'`); const description = _.get(params, "target.description", ""); const visibility = _.get(params, "target.visibility", "public"); return gp.createAndSetRemote(gid, description, visibility) .catch(err => { return Promise.reject(new Error(`Unable to create new repo '${targetId.owner}/${targetId.repo}': ` + `Probably exists: ${err}`)); }); }) .then(() => { logger_1.logger.debug(`Committing to local repo at '${gp.baseDir}'`); return gp.commit("Initial commit from Atomist"); }) .then(() => push(gp)); }; function push(gp, opts = {}) { const retryOptions = Object.assign({ retries: 5, factor: 3, minTimeout: 1 * 500, maxTimeout: 5 * 1000, randomize: true }, opts); return retry_1.doWithRetry(() => gp.push(), `Pushing local repo at '${gp.baseDir}'`, retryOptions); } exports.push = push; //# sourceMappingURL=remoteGitProjectPersister.js.map