1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const _ = require("lodash");
|
4 | const logger_1 = require("../../internal/util/logger");
|
5 | const GitCommandGitProject_1 = require("../../project/git/GitCommandGitProject");
|
6 | const retry_1 = require("../../util/retry");
|
7 | const GitHubRepoRef_1 = require("../common/GitHubRepoRef");
|
8 | const RepoId_1 = require("../common/RepoId");
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 | exports.RemoteGitProjectPersister = (p, creds, targetId, params) => {
|
17 |
|
18 | const gid = RepoId_1.isRemoteRepoRef(targetId) ? targetId : new GitHubRepoRef_1.GitHubRepoRef(targetId.owner, targetId.repo);
|
19 | const gp = GitCommandGitProject_1.GitCommandGitProject.fromProject(p, creds);
|
20 | return gp.init()
|
21 | .then(() => {
|
22 | return GitHubRepoRef_1.isGitHubRepoRef(gid) ? gp.configureFromRemote() : {};
|
23 | })
|
24 | .then(() => {
|
25 | logger_1.logger.debug(`Creating new repo '${targetId.owner}/${targetId.repo}'`);
|
26 | const description = _.get(params, "target.description", "");
|
27 | const visibility = _.get(params, "target.visibility", "public");
|
28 | return gp.createAndSetRemote(gid, description, visibility)
|
29 | .catch(err => {
|
30 | return Promise.reject(new Error(`Unable to create new repo '${targetId.owner}/${targetId.repo}': ` +
|
31 | `Probably exists: ${err}`));
|
32 | });
|
33 | })
|
34 | .then(() => {
|
35 | logger_1.logger.debug(`Committing to local repo at '${gp.baseDir}'`);
|
36 | return gp.commit("Initial commit from Atomist");
|
37 | })
|
38 | .then(() => push(gp));
|
39 | };
|
40 | function push(gp, opts = {}) {
|
41 | const retryOptions = Object.assign({ retries: 5, factor: 3, minTimeout: 1 * 500, maxTimeout: 5 * 1000, randomize: true }, opts);
|
42 | return retry_1.doWithRetry(() => gp.push(), `Pushing local repo at '${gp.baseDir}'`, retryOptions);
|
43 | }
|
44 | exports.push = push;
|
45 |
|
\ | No newline at end of file |