Created
February 23, 2015 23:51
-
-
Save jkresner/12af1e1a8fcae775ca64 to your computer and use it in GitHub Desktop.
airpair-post-repo-creation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
setupPostRepo(repo, githubOwner, post, readmeMD, user, cb){ | |
// console.log(`setting up repo ${repo} for ${githubOwner}`) | |
var _this = this | |
this.createRepo(repo, function(err, result){ | |
if (err){ | |
var parsedError = JSON.parse(err.message); | |
var errors = parsedError.errors | |
if (errors && errors.length == 1 && errors[0].message === "name already exists on this account") | |
$log("repo already created"); | |
else | |
return verboseErrorCB(cb, err, 'createRepo', `${repo} ${githubOwner}`) | |
} | |
var githubUrl = `https://github.com/${config.auth.github.org}/${repo}` | |
setTimeout(function(){ | |
_this.addFile(org, repo, "README.md", readmeMD, "Add README.md", null, function(err, result){ | |
if (err && err === "file already exists") | |
console.warn("README.md already exists on this repo") | |
else if (err) return verboseErrorCB(cb, err, 'addFile', `${repo} README.md`) | |
_this.createRepoReviewTeam(repo, post._id, function(err, result){ | |
if (err) return verboseErrorCB(cb, err, 'createRepoReviewTeam', `${repo} review team`) | |
var reviewTeamId = result.id | |
_this.createRepoAuthorTeam(repo, post._id, function(err, result){ | |
if (err) return verboseErrorCB(cb, err, 'createRepoAuthorTeam', `${repo} author team`) | |
var authorTeamId = result.id | |
_this.addToTeam(githubOwner, authorTeamId, user, function(err, result){ | |
if (err) return verboseErrorCB(cb, err, 'addToTeam', `${repo} author team ${authorTeamId}`) | |
_this.addFile(org, repo, "post.md", post.md, "Initial Commit", user, function(err, result){ | |
if (err && err === "file already exists"){ | |
_this.updateFile(org, repo, "post.md", post.md, "Reinitialize", user, function(err,result){ | |
if (err) return verboseErrorCB(cb, err, 'updateFile [reinitialize]', `${repo} post.md`) | |
cb(null, {reviewTeamId, authorTeamId, owner:githubOwner, url:githubUrl, author: user.social.gh.username}) | |
}) | |
} else { | |
if (err) return verboseErrorCB(cb, err, 'addFile', `${repo} post.md`) | |
cb(null, {reviewTeamId, authorTeamId, owner:githubOwner, url:githubUrl, author: user.social.gh.username}) | |
} | |
}) | |
}) | |
}) | |
}) | |
}) | |
}, 2000) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment