Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
logger.verbose(`Committing changes...`);
await commit({
fs: oldFs,
dir: repoDir,
// TODO: This should be configurable
author: {
name: 'Swagger Platform',
email: 'N/A',
},
// TODO: Could have a better message
message: 'Updated SDK',
});
logger.verbose(`Pushing commits...`);
await push({
fs: oldFs,
dir: repoDir,
...gitInfo.auth,
});
} catch (err) {
throw err;
} finally {
await deletePaths([repoDir]);
}
}
async pushIfNeeded(branchName: string): Promise {
console.log(`[GitManager] Pushing "${this.localUserBranch}"...`);
const remoteCommit = await this.resolveRef(this.remoteUserBranch);
const localCommit = await this.resolveRef(this.localUserBranch);
if (remoteCommit !== localCommit) {
await push({
dir: this.projectDir,
ref: this.localUserBranch,
username: this.username,
password: this.password
});
console.log(`[GitManager] Pushed.`);
} else {
console.log(`[GitManager] Push not needed.`);
}
}
async checkoutOrCreate(branchName: string): Promise {
console.log(`[GitManager] Checking out "${this.localUserBranch}"...`);
try {
await this._checkout(branchName);
} catch(err) {
await branch({
dir: this.projectDir,
ref: branchName
});
await this._checkout(branchName);
await push({
dir: this.projectDir,
ref: branchName,
username: this.username,
password: this.password
});
}
}
async function push (remoteUrl, branchRefspec, force) {
const repo = await getRepo();
const tokens = await loadOAuthConf().toPromise();
try {
const push = await git.push({
...repo,
username: tokens.token,
password: tokens.secret,
url: remoteUrl,
ref: branchRefspec,
remoteRef: 'master',
force,
});
if (push.errors != null) {
throw new Error(push.errors.join(', '));
}
return push;
}
catch (e) {
if (e.code === 'PushRejectedNonFastForward') {
throw new Error('Push rejected because it was not a simple fast-forward. Use "--force" to override.');