From 65975c2c933d82e52803c4d0a5f940509f7ff9a6 Mon Sep 17 00:00:00 2001 From: Wanderson Ferreira Date: Sun, 10 Oct 2021 13:27:42 -0300 Subject: [PATCH 1/6] enable goto-source code from diff buffer --- README.md | 18 ++++++++++++++++++ github-review.el | 13 ++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 26446ab..a4d9d43 100644 --- a/README.md +++ b/README.md @@ -127,6 +127,24 @@ configure the endpoint of your GitHub Enterprise installation, this should look `github-review-view-comments-in-code-lines-outdated` to `t`, however we cannot guarantee correct placement of these comments in the review buffer. + You can also enable replies to inline comments by setting + `github-review-reply-inline-comments` to `t`, this feature only works if + `github-review-view-comments-in-code-lines` is also set to `t`. This way, if + you include a comment right after a previous received comment in the diff + buffer, your new comment will be sent as a reply. + +- By default, `github-review` does not allow you to move back and forth the diff + buffer and the actual source code. + You can define a list of projects and the respective directory location to + enable `diff-goto-source` (bound to `C-c c-c` by default) e.g.: + ```elisp + + (setq github-review-projects-worktree + '(("charignon/github-review". "~/.doom.d/sources/github-review") + ("magit/forge" . "~/code/oss/magit-forge"))) + + ``` + ## Notice *I am providing code in the repository to you under an open source license. Because this is my personal repository, the license you receive to my diff --git a/github-review.el b/github-review.el index 5a9c9e3..7504534 100644 --- a/github-review.el +++ b/github-review.el @@ -68,6 +68,9 @@ "Flag to enable displaying outdated comments in code lines." :group 'github-review) +(defcustom github-review-projects-worktree () + "Define directory path for your projects to be used by `diff-goto-source'. ") + (defconst github-review-diffheader '(("Accept" . "application/vnd.github.v3.diff")) "Header for requesting diffs from GitHub.") @@ -329,7 +332,15 @@ ACC is an alist accumulating parsing state." (erase-buffer) (insert diff) (save-buffer) - (github-review-mode))) + (github-review-mode) + + ;; Use `C-c C-c' in diff-mode to go to source code + (when-let ((repo-path (alist-get + (format "%s/%s" .owner .repo) + github-review-projects-worktree + nil nil 'equal))) + (setq diff-remembered-defdir repo-path) + (setq default-directory repo-path)))) (defun github-review-parsed-review-from-current-buffer () "Return a code review given the current buffer containing a diff." From 8aa7c4999c2d29fb59afe055e08a7afa1cb6abe7 Mon Sep 17 00:00:00 2001 From: Wanderson Ferreira Date: Sun, 10 Oct 2021 17:15:58 -0300 Subject: [PATCH 2/6] update based on issue #41 --- README.md | 12 ------------ github-review.el | 8 ++------ 2 files changed, 2 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index a4d9d43..2ce2872 100644 --- a/README.md +++ b/README.md @@ -133,18 +133,6 @@ configure the endpoint of your GitHub Enterprise installation, this should look you include a comment right after a previous received comment in the diff buffer, your new comment will be sent as a reply. -- By default, `github-review` does not allow you to move back and forth the diff - buffer and the actual source code. - You can define a list of projects and the respective directory location to - enable `diff-goto-source` (bound to `C-c c-c` by default) e.g.: - ```elisp - - (setq github-review-projects-worktree - '(("charignon/github-review". "~/.doom.d/sources/github-review") - ("magit/forge" . "~/code/oss/magit-forge"))) - - ``` - ## Notice *I am providing code in the repository to you under an open source license. Because this is my personal repository, the license you receive to my diff --git a/github-review.el b/github-review.el index 7504534..3051a08 100644 --- a/github-review.el +++ b/github-review.el @@ -335,12 +335,7 @@ ACC is an alist accumulating parsing state." (github-review-mode) ;; Use `C-c C-c' in diff-mode to go to source code - (when-let ((repo-path (alist-get - (format "%s/%s" .owner .repo) - github-review-projects-worktree - nil nil 'equal))) - (setq diff-remembered-defdir repo-path) - (setq default-directory repo-path)))) + (setq default-directory forge-current-dir))) (defun github-review-parsed-review-from-current-buffer () "Return a code review given the current buffer containing a diff." @@ -516,6 +511,7 @@ Github API provides only the originalPosition in the query.") (interactive) (let* ((pullreq (or (forge-pullreq-at-point) (forge-current-topic))) (repo (forge-get-repository pullreq))) + (setq forge-current-dir default-directory) (github-review-start-internal (a-alist 'owner (oref repo owner) 'repo (oref repo name) 'apihost (oref repo apihost) From 2260d70e7d6fb81bf98e0d1a21f9fcf5d1aa1369 Mon Sep 17 00:00:00 2001 From: Wanderson Ferreira Date: Sun, 10 Oct 2021 17:17:10 -0300 Subject: [PATCH 3/6] remove unnecessary code --- README.md | 6 ------ github-review.el | 3 --- 2 files changed, 9 deletions(-) diff --git a/README.md b/README.md index 2ce2872..26446ab 100644 --- a/README.md +++ b/README.md @@ -127,12 +127,6 @@ configure the endpoint of your GitHub Enterprise installation, this should look `github-review-view-comments-in-code-lines-outdated` to `t`, however we cannot guarantee correct placement of these comments in the review buffer. - You can also enable replies to inline comments by setting - `github-review-reply-inline-comments` to `t`, this feature only works if - `github-review-view-comments-in-code-lines` is also set to `t`. This way, if - you include a comment right after a previous received comment in the diff - buffer, your new comment will be sent as a reply. - ## Notice *I am providing code in the repository to you under an open source license. Because this is my personal repository, the license you receive to my diff --git a/github-review.el b/github-review.el index 3051a08..864cda5 100644 --- a/github-review.el +++ b/github-review.el @@ -68,9 +68,6 @@ "Flag to enable displaying outdated comments in code lines." :group 'github-review) -(defcustom github-review-projects-worktree () - "Define directory path for your projects to be used by `diff-goto-source'. ") - (defconst github-review-diffheader '(("Accept" . "application/vnd.github.v3.diff")) "Header for requesting diffs from GitHub.") From 6bebd41eec763541c2d2d9de762f2b6c97c7a450 Mon Sep 17 00:00:00 2001 From: Wanderson Ferreira Date: Sun, 10 Oct 2021 17:22:28 -0300 Subject: [PATCH 4/6] start at the beginning of the buffer --- github-review.el | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/github-review.el b/github-review.el index 5a9c9e3..f70356d 100644 --- a/github-review.el +++ b/github-review.el @@ -329,7 +329,8 @@ ACC is an alist accumulating parsing state." (erase-buffer) (insert diff) (save-buffer) - (github-review-mode))) + (github-review-mode) + (goto-char (point-min)))) (defun github-review-parsed-review-from-current-buffer () "Return a code review given the current buffer containing a diff." From f0e556783fffe0ca5d5633b908a69135eac393c9 Mon Sep 17 00:00:00 2001 From: Laurent Charignon Date: Sun, 10 Oct 2021 14:57:53 -0700 Subject: [PATCH 5/6] Fix formatting --- github-review.el | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/github-review.el b/github-review.el index 0aeef8e..35b039e 100644 --- a/github-review.el +++ b/github-review.el @@ -508,14 +508,15 @@ Github API provides only the originalPosition in the query.") (interactive) (let* ((pullreq (or (forge-pullreq-at-point) (forge-current-topic))) (repo (forge-get-repository pullreq))) + (if (not (forge-pullreq-p pullreq)) (message "We can only review PRs at the moment. You tried on something else.") (progn (setq forge-current-dir default-directory) (github-review-start-internal (a-alist 'owner (oref repo owner) - 'repo (oref repo name) - 'apihost (oref repo apihost) - 'num (oref pullreq number))))))) + 'repo (oref repo name) + 'apihost (oref repo apihost) + 'num (oref pullreq number))))))) ;;;###autoload (defun github-review-start (url) From f138a83be6b0ef6017731182e7445af7057c4579 Mon Sep 17 00:00:00 2001 From: Laurent Charignon Date: Sun, 10 Oct 2021 14:59:01 -0700 Subject: [PATCH 6/6] Update github-review.el --- github-review.el | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/github-review.el b/github-review.el index 35b039e..fedaebe 100644 --- a/github-review.el +++ b/github-review.el @@ -508,15 +508,15 @@ Github API provides only the originalPosition in the query.") (interactive) (let* ((pullreq (or (forge-pullreq-at-point) (forge-current-topic))) (repo (forge-get-repository pullreq))) - + (if (not (forge-pullreq-p pullreq)) (message "We can only review PRs at the moment. You tried on something else.") - (progn - (setq forge-current-dir default-directory) - (github-review-start-internal (a-alist 'owner (oref repo owner) - 'repo (oref repo name) - 'apihost (oref repo apihost) - 'num (oref pullreq number))))))) + (progn + (setq forge-current-dir default-directory) + (github-review-start-internal (a-alist 'owner (oref repo owner) + 'repo (oref repo name) + 'apihost (oref repo apihost) + 'num (oref pullreq number))))))) ;;;###autoload (defun github-review-start (url)