Skip to content

Commit ce70592

Browse files
committed
Support updating reactions
1 parent df2b868 commit ce70592

File tree

6 files changed

+71
-18
lines changed

6 files changed

+71
-18
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ Some other keybindings or commands:
9191
- `C-c C-o`: open this pull request in browser
9292
- `C-c C-q`: request reviewers
9393
- `C-c C-l`: set labels
94+
- `C-c C-j`: set reactions (emojis) for comment or description under current point
9495
- `C-c C-f`: view current file; invoke with `C-u` prefix to select head or base
9596
- `C-c C-d`: open current diff; invoke with `C-u` prefix to select file
9697
- `M-x pr-review-select-commit`: select only some commits for review

pr-review-action.el

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -614,5 +614,31 @@ Return t if found, nil otherwise."
614614
.commit.oid)))))
615615
(pr-review-refresh))
616616

617+
(defun pr-review-update-reactions ()
618+
"Interactively select reactions for comment or description under point."
619+
(interactive)
620+
(let* ((section (magit-current-section))
621+
(all-reaction-names (mapcar (lambda (item) (car item)) pr-review-reaction-emojis))
622+
(completion-extra-properties
623+
(list :annotation-function
624+
(lambda (n) (concat " " (alist-get n pr-review-reaction-emojis "" nil 'equal)))))
625+
subject-id current-reaction-groups current-my-reactions)
626+
(if (or (pr-review--description-section-p section)
627+
(pr-review--review-section-p section)
628+
(pr-review--comment-section-p section)
629+
(pr-review--review-thread-item-section-p section))
630+
(setq subject-id (oref section value)
631+
current-reaction-groups (oref section reaction-groups))
632+
(user-error "Current point is not reactable"))
633+
(dolist (x current-reaction-groups)
634+
(when (alist-get 'viewerHasReacted x)
635+
(push (alist-get 'content x) current-my-reactions)))
636+
637+
(pr-review--update-reactions
638+
subject-id
639+
(completing-read-multiple "Reactions: " all-reaction-names nil t
640+
(concat (string-join current-my-reactions ",") ",")))
641+
(pr-review-refresh)))
642+
617643
(provide 'pr-review-action)
618644
;;; pr-review-action.el ends here

pr-review-api.el

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,5 +472,22 @@ See `pr-review--get-repo-labels-1' for return value."
472472
`((input . ((labelableId . ,pr-node-id)
473473
(labelIds . ,(vconcat label-node-ids)))))))
474474

475+
(defun pr-review--update-reactions (subject-id reactions)
476+
"Update REACTIONS to SUBJECT-ID.
477+
REACTIONS is a list of reaction names.
478+
Those not in the list would be removed."
479+
(let ((graphql (mapconcat
480+
(lambda (enum-item)
481+
(if (member (car enum-item) reactions)
482+
(format "_%s: addReaction(input: { content: %s, subjectId: \"%s\" }) {clientMutationId}"
483+
(car enum-item) (car enum-item) subject-id)
484+
(format "_%s: removeReaction(input: { content: %s, subjectId: \"%s\" }) {clientMutationId}"
485+
(car enum-item) (car enum-item) subject-id)))
486+
pr-review-reaction-emojis
487+
"\n")))
488+
(pr-review--execute-graphql-raw
489+
(concat "mutation { \n" graphql "\n}")
490+
nil)))
491+
475492
(provide 'pr-review-api)
476493
;;; pr-review-api.el ends here

pr-review-common.el

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,14 @@
149149
(defclass pr-review--review-section (magit-section)
150150
((body :initform nil)
151151
(updatable :initform nil)
152-
(databaseId :initform nil)))
152+
(databaseId :initform nil)
153+
(reaction-groups :initform nil)))
153154

154155
(defclass pr-review--comment-section (magit-section)
155156
((body :initform nil)
156157
(updatable :initform nil)
157-
(databaseId :initform nil)))
158+
(databaseId :initform nil)
159+
(reaction-groups :initform nil)))
158160

159161
(defclass pr-review--diff-section (magit-section) ())
160162
(defclass pr-review--check-section (magit-section) ())
@@ -167,15 +169,17 @@
167169
(defclass pr-review--review-thread-item-section (magit-section)
168170
((body :initform nil)
169171
(updatable :initform nil)
170-
(databaseId :initform nil)))
172+
(databaseId :initform nil)
173+
(reaction-groups :initform nil)))
171174

172175
(defclass pr-review--root-section (magit-section)
173176
((title :initform nil)
174177
(updatable :initform nil)))
175178

176179
(defclass pr-review--description-section (magit-section)
177180
((body :initform nil)
178-
(updatable :initform nil)))
181+
(updatable :initform nil)
182+
(reaction-groups :initform nil)))
179183

180184
(defclass pr-review--event-section (magit-section) ())
181185

@@ -202,5 +206,17 @@ Set to nil to disable source language syntax highlighting."
202206
:type 'number
203207
:group 'pr-review)
204208

209+
(defvar pr-review-reaction-emojis
210+
'(("CONFUSED" . "😕")
211+
("EYES" . "👀")
212+
("HEART" . "❤️")
213+
("HOORAY" . "🎉")
214+
("LAUGH" . "😄")
215+
("ROCKET" . "🚀")
216+
("THUMBS_DOWN" . "👎")
217+
("THUMBS_UP" . "👍"))
218+
"Alist of github reaction name to emoji unicode.
219+
See https://docs.github.com/en/graphql/reference/enums#reactioncontent")
220+
205221
(provide 'pr-review-common)
206222
;;; pr-review-common.el ends here

pr-review-render.el

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,6 @@
4040
:type 'integer
4141
:group 'pr-review)
4242

43-
(defvar pr-review-reaction-emojis
44-
'(("CONFUSED" . "😕")
45-
("EYES" . "👀")
46-
("HEART" . "❤️")
47-
("HOORAY" . "🎉")
48-
("LAUGH" . "😄")
49-
("ROCKET" . "🚀")
50-
("THUMBS_DOWN" . "👎")
51-
("THUMBS_UP" . "👍"))
52-
"Alist of github reaction name to emoji unicode.
53-
See https://docs.github.com/en/graphql/reference/enums#reactioncontent")
54-
5543
(defun pr-review--format-timestamp (str)
5644
"Convert and format timestamp STR from json."
5745
(concat
@@ -177,7 +165,7 @@ INDENT is an optional number of extra spaces at the start of the line."
177165
(setq s (concat s " ")))
178166
(setq s (concat
179167
s
180-
(format "%s*%d"
168+
(format "%s%d"
181169
(alist-get .content pr-review-reaction-emojis .content nil 'equal)
182170
.reactors.totalCount)
183171
(when .viewerHasReacted
@@ -442,6 +430,7 @@ It will be inserted at the beginning."
442430
(oset item-section databaseId .databaseId)
443431
(oset item-section updatable .viewerCanUpdate)
444432
(oset item-section body .body)
433+
(oset item-section reaction-groups .reactionGroups)
445434
(magit-insert-heading
446435
(make-string (* 2 pr-review-section-indent-width) ?\s)
447436
(pr-review--propertize-username .author.login)
@@ -481,6 +470,7 @@ It will be inserted at the beginning."
481470
(oset section databaseId .databaseId)
482471
(oset section updatable .viewerCanUpdate)
483472
(oset section body .body)
473+
(oset section reaction-groups .reactionGroups)
484474
(magit-insert-heading
485475
(propertize "Reviewed by " 'face 'magit-section-heading)
486476
(pr-review--propertize-username .author.login)
@@ -504,6 +494,7 @@ It will be inserted at the beginning."
504494
(oset section databaseId .databaseId)
505495
(oset section updatable .viewerCanUpdate)
506496
(oset section body .body)
497+
(oset section reaction-groups .reactionGroups)
507498
(magit-insert-heading
508499
(propertize "Commented by " 'face 'magit-section-heading)
509500
(pr-review--propertize-username .author.login)
@@ -869,9 +860,10 @@ it can be displayed in a single line."
869860
(pr-review--insert-reviewers-info pr)
870861
(pr-review--insert-assignees-info pr)
871862
(insert "\n")
872-
(magit-insert-section section (pr-review--description-section)
863+
(magit-insert-section section (pr-review--description-section .id)
873864
(oset section body .body)
874865
(oset section updatable .viewerCanUpdate)
866+
(oset section reaction-groups .reactionGroups)
875867
(magit-insert-heading "Description")
876868
(pr-review--insert-html .bodyHTML)
877869
(pr-review--maybe-insert-reactions .reactionGroups))

pr-review.el

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
(define-key map (kbd "C-c C-o") #'pr-review-open-in-default-browser)
5353
(define-key map (kbd "C-c C-q") #'pr-review-request-reviews)
5454
(define-key map (kbd "C-c C-l") #'pr-review-set-labels)
55+
(define-key map (kbd "C-c C-j") #'pr-review-update-reactions)
5556
map))
5657

5758
(defvar pr-review--mode-map-setup-for-evil-done nil)

0 commit comments

Comments
 (0)