diff --git a/ghpr-api.el b/ghpr-api.el index ca2422b..1cfeb21 100644 --- a/ghpr-api.el +++ b/ghpr-api.el @@ -82,28 +82,6 @@ Returns a list of pull request objects on success, nil on failure." (message "Error fetching pull requests: %s" error-thrown))))) result)) -(defun ghpr--get-pr (repo-name pr-number) - "Retrieve a single pull request by PR-NUMBER in REPO-NAME. -Returns a parsed PR object on success, nil on failure." - (let ((token (ghpr--get-token)) - (url (format "https://api.github.com/repos/%s/pulls/%s" repo-name pr-number)) - (result nil)) - (when token - (request url - :type "GET" - :headers `(("Accept" . "application/vnd.github+json") - ("Authorization" . ,(format "Bearer %s" token)) - ("X-GitHub-Api-Version" . "2022-11-28")) - :parser 'json-read - :sync t - :success (cl-function - (lambda (&key data &allow-other-keys) - (setq result (ghpr--parse-api-pr data)))) - :error (cl-function - (lambda (&key error-thrown &allow-other-keys) - (message "Error fetching PR: %s" error-thrown))))) - result)) - (defun ghpr--get-diff-content (repo-name pr-number) "Retrieve the diff contents for PR-NUMBER in REPO-NAME." (let ((token (ghpr--get-token)) diff --git a/ghpr-review.el b/ghpr-review.el index 5961798..4e7a98c 100644 --- a/ghpr-review.el +++ b/ghpr-review.el @@ -68,14 +68,14 @@ ("^\\(> \\)$" (0 'ghpr-review-misc-line t))) "Font lock keywords for ghpr-review-mode.") -(defvar-local ghpr--review-base-content nil - "Stores the base starting content, including diff, for the current PR.") +(defvar-local ghpr--review-diff-content nil + "Buffer-local variable storing the diff content for the current PR.") (defvar-local ghpr--review-pr-metadata nil - "Stores the PR metadata for the current PR.") + "Buffer-local variable storing the PR metadata for the current PR.") (defvar-local ghpr--review-repo-name nil - "Stores the repository name for the current PR.") + "Buffer-local variable storing the repository name for the current PR.") (defvar ghpr-review-mode-map (let ((map (make-sparse-keymap)) @@ -111,7 +111,7 @@ "Return a string of the title, body, and patch content separated by newlines." (let* ((body (or (alist-get 'body pr) "")) (content-parts (list (ghpr--pr-summary pr)))) - (when (and body (not (string-empty-p body))) + (when (not (string-empty-p body)) (push body content-parts)) (when diff-content (push diff-content content-parts)) @@ -122,11 +122,11 @@ (erase-buffer) (let* ((number (alist-get 'number pr)) (diff-content (ghpr--get-diff-content repo-name number)) - (contents (ghpr--prefix-lines (ghpr--open-pr/collect-contents pr diff-content)))) - (setq ghpr--review-base-content contents) + (contents (ghpr--open-pr/collect-contents pr diff-content))) + (setq ghpr--review-diff-content diff-content) (setq ghpr--review-pr-metadata pr) (setq ghpr--review-repo-name repo-name) - (insert contents))) + (insert (ghpr--prefix-lines contents)))) (defun ghpr--open-pr (pr repo-name) "Open a new buffer containing the body of the PR." @@ -339,14 +339,6 @@ Returns an alist with comment, file-path, commit-sha, and diff-position, or nil (commit-sha . ,(alist-get 'commit-sha context)) (diff-position . ,(alist-get 'diff-position context))))))) -(defun ghpr--validate-base-content-unchanged () - "Validate that all base content (lines with > or < prefixes) remains unchanged. -Returns t if validation passes, nil otherwise." - (let* ((current-lines (split-string (buffer-string) "\n")) - (base-lines (split-string ghpr--review-base-content "\n")) - (current-base-lines (seq-filter #'ghpr--special-line-p current-lines))) - (equal current-base-lines base-lines))) - (defun ghpr--collect-review-comments () "Collect all inline review comments from the current buffer. Returns an alist of comments with their associated diff lines and GitHub API context. @@ -375,9 +367,6 @@ Collects review body and inline comments from current buffer." (error "No PR metadata found in buffer")) (unless ghpr--review-repo-name (error "No repository name found in buffer")) - ;; TODO: needs better usability. maybe highlight which lines were broken/missing and restore. - (unless (ghpr--validate-base-content-unchanged) - (error "Base content has been modified. Please restore the original diff content before submitting")) (let* ((body (ghpr--collect-review-body)) (inline-comments (ghpr--collect-review-comments)) @@ -393,17 +382,13 @@ Collects review body and inline comments from current buffer." (or (not body) (string-empty-p (string-trim body)))) (error "Review body is required for %s events" event)) - (when (yes-or-no-p (format "Submit review (%s)? " event)) - (if (ghpr--create-review ghpr--review-repo-name - pr-number - commit-sha - (or body "") - event - api-comments) - (progn - (message "Review submitted successfully") - (kill-buffer (current-buffer))) - (message "Failed to submit review"))))) + (unless (ghpr--create-review ghpr--review-repo-name + pr-number + commit-sha + (or body "") + event + api-comments) + (message "Failed to submit review")))) (defun ghpr-review-comment () "Submit review comments with COMMENT event." diff --git a/ghpr.el b/ghpr.el index 6e780bf..6bba261 100644 --- a/ghpr.el +++ b/ghpr.el @@ -54,15 +54,6 @@ (let ((pr (cdr (assoc selected-item pr-items)))) (ghpr--open-pr pr repo-name)))))))) -(defun ghpr-open-pr (pr-number) - "Open a specific pull request by PR-NUMBER." - (interactive "nPR number: ") - (let* ((repo-name (ghpr--get-repo-name)) - (pr (when repo-name (ghpr--get-pr repo-name pr-number)))) - (if pr - (ghpr--open-pr pr repo-name) - (message "Could not open PR #%d" pr-number)))) - (provide 'ghpr) ;;; ghpr.el ends here