Compare commits
No commits in common. "d142a39966a11afade1dae809b75ad54329e82d4" and "aa4749c648d4235be5c487dd03d18920d7cf0e9e" have entirely different histories.
d142a39966
...
aa4749c648
3 changed files with 1 additions and 128 deletions
|
@ -49,11 +49,7 @@ Returns the token string if found, nil otherwise."
|
||||||
(username . ,(alist-get 'login user))
|
(username . ,(alist-get 'login user))
|
||||||
(author . ,(alist-get 'login user))
|
(author . ,(alist-get 'login user))
|
||||||
(base_sha . ,(alist-get 'sha base))
|
(base_sha . ,(alist-get 'sha base))
|
||||||
(base_ref . ,(alist-get 'ref base))
|
|
||||||
(head_sha . ,(alist-get 'sha head))
|
(head_sha . ,(alist-get 'sha head))
|
||||||
(head_ref . ,(alist-get 'ref head))
|
|
||||||
(head_repo . ,(alist-get 'repo head))
|
|
||||||
(head_user . ,(alist-get 'user head))
|
|
||||||
(merge_commit_sha . ,(alist-get 'merge_commit_sha pr)))))
|
(merge_commit_sha . ,(alist-get 'merge_commit_sha pr)))))
|
||||||
|
|
||||||
(defun ghpr--parse-api-pr-list (pr-list)
|
(defun ghpr--parse-api-pr-list (pr-list)
|
||||||
|
|
49
ghpr-repo.el
49
ghpr-repo.el
|
@ -41,55 +41,6 @@ Returns nil if origin remote doesn't exist or is not a GitHub repository."
|
||||||
(when (string-match "github\\.com[:/]\\([^/]+/[^/.]+\\)" origin-url)
|
(when (string-match "github\\.com[:/]\\([^/]+/[^/.]+\\)" origin-url)
|
||||||
(match-string 1 origin-url)))))
|
(match-string 1 origin-url)))))
|
||||||
|
|
||||||
(defun ghpr--is-fork-pr-p (pr-metadata)
|
|
||||||
"Return t if PR is from a fork, nil if from same repository.
|
|
||||||
PR-METADATA should contain head_repo and head_user information."
|
|
||||||
(let ((head-repo (alist-get 'head_repo pr-metadata))
|
|
||||||
(head-user (alist-get 'head_user pr-metadata))
|
|
||||||
(origin-repo-name (ghpr--get-repo-name)))
|
|
||||||
(when (and head-repo head-user origin-repo-name)
|
|
||||||
(let ((head-repo-full-name (alist-get 'full_name head-repo))
|
|
||||||
(head-user-login (alist-get 'login head-user)))
|
|
||||||
(not (string= head-repo-full-name origin-repo-name))))))
|
|
||||||
|
|
||||||
(defun ghpr--get-or-add-remote (pr-metadata)
|
|
||||||
"Get or add the remote for the PR's head repository.
|
|
||||||
Returns the remote name to use for fetching the PR branch."
|
|
||||||
(let* ((head-repo (alist-get 'head_repo pr-metadata))
|
|
||||||
(head-user (alist-get 'head_user pr-metadata))
|
|
||||||
(head-user-login (alist-get 'login head-user))
|
|
||||||
(head-repo-clone-url (alist-get 'clone_url head-repo))
|
|
||||||
(remote-name head-user-login))
|
|
||||||
|
|
||||||
(if (ghpr--is-fork-pr-p pr-metadata)
|
|
||||||
(progn
|
|
||||||
(unless (magit-remote-p remote-name)
|
|
||||||
(magit-remote-add remote-name head-repo-clone-url))
|
|
||||||
remote-name)
|
|
||||||
"origin")))
|
|
||||||
|
|
||||||
(defun ghpr--checkout-pr-branch (pr-metadata)
|
|
||||||
"Check out the PR branch using Magit.
|
|
||||||
Fetches the branch from appropriate remote if needed, then checks it out.
|
|
||||||
PR-METADATA should contain head_ref, head_sha, and repository information."
|
|
||||||
(let* ((head-ref (alist-get 'head_ref pr-metadata))
|
|
||||||
(head-sha (alist-get 'head_sha pr-metadata))
|
|
||||||
(pr-number (alist-get 'number pr-metadata))
|
|
||||||
(remote-name (ghpr--get-or-add-remote pr-metadata))
|
|
||||||
(remote-branch-ref (format "%s/%s" remote-name head-ref))
|
|
||||||
(local-branch-name head-ref))
|
|
||||||
|
|
||||||
(unless head-ref
|
|
||||||
(error "PR metadata missing head branch reference"))
|
|
||||||
|
|
||||||
(message "Fetching PR branch from %s..." remote-name)
|
|
||||||
(magit-fetch-branch remote-name head-ref local-branch-name)
|
|
||||||
|
|
||||||
(message "Checking out PR branch: %s" local-branch-name)
|
|
||||||
(magit-checkout local-branch-name)
|
|
||||||
|
|
||||||
(message "Checked out PR #%s branch: %s" pr-number local-branch-name)))
|
|
||||||
|
|
||||||
(provide 'ghpr-repo)
|
(provide 'ghpr-repo)
|
||||||
|
|
||||||
;;; ghpr-repo.el ends here
|
;;; ghpr-repo.el ends here
|
||||||
|
|
|
@ -35,7 +35,6 @@
|
||||||
(require 'magit-git)
|
(require 'magit-git)
|
||||||
|
|
||||||
(require 'ghpr-api)
|
(require 'ghpr-api)
|
||||||
(require 'ghpr-repo)
|
|
||||||
(require 'ghpr-utils)
|
(require 'ghpr-utils)
|
||||||
|
|
||||||
(defface ghpr-review-added-line
|
(defface ghpr-review-added-line
|
||||||
|
@ -83,9 +82,6 @@
|
||||||
(define-key prefix-map (kbd "C-c") 'ghpr-review-comment)
|
(define-key prefix-map (kbd "C-c") 'ghpr-review-comment)
|
||||||
(define-key prefix-map (kbd "C-a") 'ghpr-review-approve)
|
(define-key prefix-map (kbd "C-a") 'ghpr-review-approve)
|
||||||
(define-key prefix-map (kbd "C-r") 'ghpr-review-reject-changes)
|
(define-key prefix-map (kbd "C-r") 'ghpr-review-reject-changes)
|
||||||
(define-key prefix-map (kbd "C-o") 'ghpr-review-checkout-branch)
|
|
||||||
(define-key prefix-map (kbd "C-d") 'ghpr-review-magit-diff)
|
|
||||||
(define-key prefix-map (kbd "C-k") 'ghpr-review-quit)
|
|
||||||
(define-key map (kbd "C-c") prefix-map)
|
(define-key map (kbd "C-c") prefix-map)
|
||||||
map)
|
map)
|
||||||
"Keymap for `ghpr-review-mode'.")
|
"Keymap for `ghpr-review-mode'.")
|
||||||
|
@ -137,7 +133,7 @@
|
||||||
(ghpr-review-mode)
|
(ghpr-review-mode)
|
||||||
(ghpr--open-pr/insert-contents pr repo-name)
|
(ghpr--open-pr/insert-contents pr repo-name)
|
||||||
(goto-char (point-min)))
|
(goto-char (point-min)))
|
||||||
(switch-to-buffer-other-window buffer)))
|
(display-buffer buffer)))
|
||||||
|
|
||||||
(defun ghpr--is-comment-line (line)
|
(defun ghpr--is-comment-line (line)
|
||||||
"Return t if LINE is a user comment (no prefix), nil otherwise."
|
"Return t if LINE is a user comment (no prefix), nil otherwise."
|
||||||
|
@ -405,76 +401,6 @@ Collects review body and inline comments from current buffer."
|
||||||
(interactive)
|
(interactive)
|
||||||
(ghpr--submit-review "REQUEST_CHANGES"))
|
(ghpr--submit-review "REQUEST_CHANGES"))
|
||||||
|
|
||||||
(defun ghpr-review-checkout-branch ()
|
|
||||||
"Check out the PR branch using Magit."
|
|
||||||
(interactive)
|
|
||||||
(unless ghpr--review-pr-metadata
|
|
||||||
(error "No PR metadata found in buffer"))
|
|
||||||
(ghpr--checkout-pr-branch ghpr--review-pr-metadata))
|
|
||||||
|
|
||||||
(defun ghpr--review-magit-diff/both-local (local-base-branch local-pr-branch)
|
|
||||||
"Handle case where both base and PR branches exist locally."
|
|
||||||
(message "Diffing local branches: %s..%s" local-base-branch local-pr-branch)
|
|
||||||
(magit-diff-range (format "%s..%s" local-base-branch local-pr-branch)))
|
|
||||||
|
|
||||||
(defun ghpr--review-magit-diff/base-local-pr-remote (local-base-branch local-pr-branch pr-metadata)
|
|
||||||
"Handle case where base branch exists locally but PR branch needs to be fetched."
|
|
||||||
(message "Local base branch found, fetching and checking out PR branch...")
|
|
||||||
(magit-git-fetch "origin" nil)
|
|
||||||
(ghpr--checkout-pr-branch pr-metadata)
|
|
||||||
(if (magit-branch-p local-pr-branch)
|
|
||||||
(progn
|
|
||||||
(message "Diffing: %s..%s" local-base-branch local-pr-branch)
|
|
||||||
(magit-diff-range (format "%s..%s" local-base-branch local-pr-branch)))
|
|
||||||
(error "Unable to create PR branch. This may happen when testing on a repository that doesn't contain the actual PR")))
|
|
||||||
|
|
||||||
(defun ghpr--review-magit-diff/remote-handling (local-base-branch local-pr-branch remote-base-branch local-base-exists-p local-pr-exists-p pr-metadata)
|
|
||||||
"Handle case where remote operations are needed for base and/or PR branch."
|
|
||||||
(message "Local branches not found, fetching and checking out...")
|
|
||||||
(magit-git-fetch "origin" nil)
|
|
||||||
(unless local-pr-exists-p
|
|
||||||
(ghpr--checkout-pr-branch pr-metadata))
|
|
||||||
(let ((base-to-use (if local-base-exists-p local-base-branch remote-base-branch)))
|
|
||||||
(if (magit-branch-p local-pr-branch)
|
|
||||||
(progn
|
|
||||||
(message "Diffing: %s..%s" base-to-use local-pr-branch)
|
|
||||||
(magit-diff-range (format "%s..%s" base-to-use local-pr-branch)))
|
|
||||||
(error "Unable to create PR branch. This may happen when testing on a repository that doesn't contain the actual PR"))))
|
|
||||||
|
|
||||||
(defun ghpr-review-magit-diff ()
|
|
||||||
"Show Magit diff between PR base and head branches.
|
|
||||||
Checks if branches exist locally first, falls back to remote handling if needed."
|
|
||||||
(interactive)
|
|
||||||
(unless ghpr--review-pr-metadata
|
|
||||||
(error "No PR metadata found in buffer"))
|
|
||||||
|
|
||||||
(let* ((pr-number (alist-get 'number ghpr--review-pr-metadata))
|
|
||||||
(base-ref (alist-get 'base_ref ghpr--review-pr-metadata))
|
|
||||||
(head-ref (alist-get 'head_ref ghpr--review-pr-metadata))
|
|
||||||
(local-pr-branch head-ref)
|
|
||||||
(local-base-branch base-ref)
|
|
||||||
(remote-base-branch (format "origin/%s" base-ref))
|
|
||||||
(local-base-exists-p (magit-branch-p local-base-branch))
|
|
||||||
(local-pr-exists-p (magit-branch-p local-pr-branch)))
|
|
||||||
(unless base-ref
|
|
||||||
(error "PR metadata missing base branch reference"))
|
|
||||||
(unless head-ref
|
|
||||||
(error "PR metadata missing head branch reference"))
|
|
||||||
|
|
||||||
(cond
|
|
||||||
((and local-base-exists-p local-pr-exists-p)
|
|
||||||
(ghpr--review-magit-diff/both-local local-base-branch local-pr-branch))
|
|
||||||
(local-base-exists-p
|
|
||||||
(ghpr--review-magit-diff/base-local-pr-remote local-base-branch local-pr-branch ghpr--review-pr-metadata))
|
|
||||||
(t
|
|
||||||
(ghpr--review-magit-diff/remote-handling local-base-branch local-pr-branch remote-base-branch local-base-exists-p local-pr-exists-p ghpr--review-pr-metadata)))))
|
|
||||||
|
|
||||||
(defun ghpr-review-quit ()
|
|
||||||
"Quit and close the review buffer with confirmation."
|
|
||||||
(interactive)
|
|
||||||
(when (yes-or-no-p "Quit review? ")
|
|
||||||
(kill-buffer (current-buffer))))
|
|
||||||
|
|
||||||
(provide 'ghpr-review)
|
(provide 'ghpr-review)
|
||||||
|
|
||||||
;;; ghpr-review.el ends here
|
;;; ghpr-review.el ends here
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue