Permalink
Browse files

Auto-increment patch names

Rather than naming all pull requests `prose-patch`, name it `prose-patch-N` where `N` is the lowest possible number not already in use.

This generates the patch name in `forkRepo` and must also retrieve the patch name (from the refs passed to the callback) in `sendPatch`.

See #257 for additional discussion on the problem.
  • Loading branch information...
1 parent e4aec7f commit 6ef7388a6e76090b9629ac4b4d4e47f74623cec1 @benbalter benbalter committed with dhcole Nov 17, 2012
Showing with 10 additions and 5 deletions.
  1. +10 −5 _includes/model.js
View
@@ -290,13 +290,17 @@ function forkRepo(user, reponame, branch, cb) {
});
}, 500);
}
-
+
repo.fork(function(err) {
onceReady(function() {
repo.getRef("heads/"+branch, function(err, commitSha) {
// Create temp branch
- var refSpec = { "ref": "refs/heads/prose-patch", "sha": commitSha };
- forkedRepo.createRef(refSpec, cb);
+ forkedRepo.listBranches( function( unused, branches ){
+ //find the lowest patch number
+ i=1; while ($.inArray('prose-patch-'+i, branches)!=-1){ i++ }
+ var refSpec = { "ref": "refs/heads/prose-patch-"+i, "sha": commitSha };
+ forkedRepo.createRef(refSpec, cb);
+ });
});
});
});
@@ -324,13 +328,14 @@ function createPullRequest(user, repo, pull, cb) {
function patchFile(user, repo, branch, path, content, message, cb) {
forkRepo(user, repo, branch, function(err, info) {
- saveFile(app.username, repo, "prose-patch", path, content, message, function(err) {
+ branch = info.ref.substring( info.ref.lastIndexOf('/') + 1);
+ saveFile(app.username, repo, branch, path, content, message, function(err) {
if (err) return cb(err);
var pull = {
title: message,
body: "This pull request has been automatically generated by Prose.io.",
base: app.state.branch,
- head: app.username + ":" + "prose-patch",
+ head: app.username + ":" + branch,
};
createPullRequest(app.state.user, app.state.repo, pull, function(err) {
window.forkedRepo = github().getRepo(app.username, repo);

0 comments on commit 6ef7388

Please sign in to comment.