Skip to content

Commit

Permalink
Support fetch PR list.
Browse files Browse the repository at this point in the history
  • Loading branch information
manateelazycat committed Oct 14, 2022
1 parent f00dd8a commit 4bc2014
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 13 deletions.
44 changes: 33 additions & 11 deletions buffer.py
Expand Up @@ -543,20 +543,42 @@ def status_copy_change_files_to_mirror_repo(self):

@QtCore.pyqtSlot()
def status_fetch_pr(self):
self.send_input_message("Fetch pull request, please input PR number: ", "fetch_pr")

def handle_fetch_pr(self, pr_number):
message_to_emacs("Fetch PR {} ...".format(pr_number))
remote_default = next(self.repo.config.get_multivar("remote.pushdefault"), "origin")
origin_url = get_git_https_url(self.repo.remotes[remote_default].url)

result = get_command_result("cd {}; git fetch origin pull/{}/head:pr_{} && git checkout pr_{}".format(
self.repo_root,
pr_number,
pr_number,
pr_number))
message_to_emacs("Fetch PR list...")
self.buffer_widget.eval_js_function("fetchPrList", "{}/pulls".format(origin_url))

self.update_git_info()
@QtCore.pyqtSlot(list)
def read_pr(self, pr_list):
if len(pr_list) > 0:
self.pr_ids = []
self.pr_names = []
for pr in pr_list:
self.pr_ids.append(pr[0].split("_")[1])
self.pr_names.append(pr[1])

self.send_input_message("Fetch pull request, please input PR number: ", "fetch_pr", "list", completion_list=self.pr_names)
else:
message_to_emacs("No PR found in repo.")

message_to_emacs("Fetch PR {} done.".format(pr_number))
def handle_fetch_pr(self, pr_name):
try:
pr_number = self.pr_ids[self.pr_names.index(pr_name)]

message_to_emacs("Fetch PR {} ...".format(pr_number))

result = get_command_result("cd {}; git fetch origin pull/{}/head:pr_{} && git checkout pr_{}".format(
self.repo_root,
pr_number,
pr_number,
pr_number))

self.update_git_info()

message_to_emacs("Fetch PR {} done.".format(pr_number))
except:
message_to_emacs("Input wrong PR: {}".format(pr_name))

@QtCore.pyqtSlot()
def remote_copy_url(self):
Expand Down
22 changes: 20 additions & 2 deletions src/components/Main.vue
Expand Up @@ -315,6 +315,7 @@
window.searchSubmodulesCancel = this.searchSubmodulesCancel;
window.searchSubmodulesJumpNext = this.searchSubmodulesJumpNext;
window.searchSubmodulesJumpPrev = this.searchSubmodulesJumpPrev;
window.fetchPrList = this.fetchPrList;
if (this.untrackStatusInfo) {
this.selectItemType = "untrack";
Expand Down Expand Up @@ -889,6 +890,24 @@
this.searchSubmoduleMatchIndex = this.currentSubmoduleIndex;
},
fetchPrList(url) {
fetch(url)
.then(function(response) {
// When the page is loaded convert it to text
return response.text()
})
.then(function(html) {
var parser = new DOMParser()
var doc = parser.parseFromString(html, "text/html")
var prList = Array.from(doc.getElementsByClassName('Link--primary'))
window.pyobject.read_pr(prList.map(pr => [pr.id, pr.innerHTML]))
})
.catch(function(err) {
console.log('Failed to fetch page: ', err);
});
},
searchSubmodulesFinish() {
this.searchSubmoduleStartIndex = -1;
this.searchSubmoduleKeyword = "";
Expand Down Expand Up @@ -1232,7 +1251,7 @@
display: flex;
flex-wrap: wrap;
line-height: 1.5;
flex-direction: row;
align-items: center;
Expand All @@ -1259,4 +1278,3 @@
background-color: var(--select-color);
}
</style>

0 comments on commit 4bc2014

Please sign in to comment.