Commit b7af9e21 authored by Ivanq's avatar Ivanq

Import branches of PRs using 'Import' button

parent 6ab42483
......@@ -567,6 +567,22 @@ class Repository {
);
});
}
importPullRequest(pullRequest) {
let other = new Repository(pullRequest.fork_address, this.zeroPage);
let ref;
return other.addMerger()
.then(() => {
return other.git.getBranchCommit(pullRequest.fork_branch);
})
.then(r => {
ref = r;
return this.git.importObjectWithDependencies(other.git, ref);
})
.then(() => {
return this.git.setRef("refs/heads/pr-" + pullRequest.id + "-" + pullRequest.json_id, ref);
});
}
// Maintainers
getUsers() {
......
......@@ -80,6 +80,7 @@
<a class="button button-blue comment-submit" id="comment_submit">Comment</a>
<a class="button comment-submit-close" id="comment_submit_close">Comment</a>
<a class="button comment-submit-close" id="comment_import">Import</a>
</div>
<template id="edit_icon_tmpl">
......
......@@ -121,5 +121,24 @@ repo.addMerger()
contentNode.disabled = false;
});
};
let commentImport = document.getElementById("comment_import");
commentImport.style.display = "inline-block";
commentImport.title = "Import branch " + pullRequest.fork_address + "/" + pullRequest.fork_branch + " as " + address + "/pr-" + id + "-" + jsonId;
commentImport.onclick = () => {
if(commentImport.classList.contains("button-disabled")) {
return;
}
commentImport.classList.add("button-disabled");
repo.importPullRequest(pullRequest)
.then(() => {
zeroPage.alert("Branch pr-" + id + "-" + jsonId + " was imported to your repository. Run git fetch to download and merge it.");
commentImport.classList.remove("button-disabled");
}, e => {
zeroPage.error(e);
commentImport.classList.remove("button-disabled");
});
};
}
});
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment