Skip to content

Commit aec5cdc

Browse files
committed
display reaction emojis
1 parent d08ce76 commit aec5cdc

File tree

3 files changed

+55
-3
lines changed

3 files changed

+55
-3
lines changed

graphql/get-pull-request.graphql

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ query($repo_owner:String!, $repo_name:String!, $pr_id:Int!) {
1919
title
2020
body
2121
bodyHTML
22+
reactionGroups {
23+
content
24+
reactors { totalCount }
25+
}
2226
author {
2327
login
2428
}
@@ -64,8 +68,6 @@ query($repo_owner:String!, $repo_name:String!, $pr_id:Int!) {
6468
author {
6569
login
6670
}
67-
body
68-
bodyHTML
6971
createdAt
7072
state
7173
}
@@ -93,6 +95,10 @@ query($repo_owner:String!, $repo_name:String!, $pr_id:Int!) {
9395
body
9496
bodyHTML
9597
createdAt
98+
reactionGroups {
99+
content
100+
reactors { totalCount }
101+
}
96102
}
97103
}
98104
}
@@ -169,6 +175,10 @@ query($repo_owner:String!, $repo_name:String!, $pr_id:Int!) {
169175
body
170176
bodyHTML
171177
createdAt
178+
reactionGroups {
179+
content
180+
reactors { totalCount }
181+
}
172182
}
173183
... on PullRequestReview {
174184
id
@@ -181,6 +191,10 @@ query($repo_owner:String!, $repo_name:String!, $pr_id:Int!) {
181191
login
182192
}
183193
createdAt
194+
reactionGroups {
195+
content
196+
reactors { totalCount }
197+
}
184198

185199
comments(first: 100) {
186200
nodes {

pr-review-common.el

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,11 @@
139139
"Face used for buttons."
140140
:group 'pr-review)
141141

142+
(defface pr-review-reaction-face
143+
'((t :height 0.7 :box t))
144+
"Face used for reaction emojis."
145+
:group 'pr-review)
146+
142147

143148
;; section classes
144149
(defclass pr-review--review-section (magit-section)

pr-review-render.el

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,18 @@
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+
4355
(defun pr-review--format-timestamp (str)
4456
"Convert and format timestamp STR from json."
4557
(concat
@@ -154,6 +166,23 @@ in addition to other faces."
154166
(when extra-face
155167
(add-face-text-property start end extra-face))))
156168

169+
(defun pr-review--maybe-insert-reactions (reaction-group &optional indent)
170+
"Insert REACTION-GROUP if not nil.
171+
INDENT is an optional number of extra spaces at the start of the line."
172+
(let (s)
173+
(dolist (group reaction-group)
174+
(let-alist group
175+
(when (and (> .reactors.totalCount 0) .content)
176+
(when s
177+
(setq s (concat s " ")))
178+
(setq s (concat s (format "%s*%d"
179+
(alist-get .content pr-review-reaction-emojis .content nil 'equal)
180+
.reactors.totalCount))))))
181+
(when s
182+
(when indent
183+
(insert (propertize " " 'display `(space :width (,(* indent pr-review--char-pixel-width))))))
184+
(insert (propertize s 'face 'pr-review-reaction-face) "\n"))))
185+
157186
(defun pr-review--fontify (body lang-mode &optional margin)
158187
"Fontify content BODY as LANG-MODE, return propertized string.
159188
MARGIN is an optional number, if provided,
@@ -416,6 +445,7 @@ It will be inserted at the beginning."
416445
(pr-review--format-timestamp .createdAt))
417446
(pr-review--insert-html .bodyHTML (* 2 pr-review-section-indent-width)
418447
'pr-review-thread-comment-face)
448+
(pr-review--maybe-insert-reactions .reactionGroups (* 2 pr-review-section-indent-width))
419449
(insert "\n"))))
420450
(let-alist review-thread .comments.nodes))
421451

@@ -456,6 +486,7 @@ It will be inserted at the beginning."
456486
(pr-review--format-timestamp .createdAt))
457487
(unless (string-empty-p .body)
458488
(pr-review--insert-html .bodyHTML))
489+
(pr-review--maybe-insert-reactions .reactionGroups)
459490
(insert "\n")
460491
(dolist (top-comment-and-review-thread top-comment-and-review-thread-list)
461492
(apply #'pr-review--insert-review-thread-section top-comment-and-review-thread))
@@ -475,6 +506,7 @@ It will be inserted at the beginning."
475506
" - "
476507
(pr-review--format-timestamp .createdAt))
477508
(pr-review--insert-html .bodyHTML)
509+
(pr-review--maybe-insert-reactions .reactionGroups)
478510
(insert "\n"))))
479511

480512
(defun pr-review--insert-misc-event-section (event)
@@ -837,7 +869,8 @@ it can be displayed in a single line."
837869
(oset section body .body)
838870
(oset section updatable .viewerCanUpdate)
839871
(magit-insert-heading "Description")
840-
(pr-review--insert-html .bodyHTML))
872+
(pr-review--insert-html .bodyHTML)
873+
(pr-review--maybe-insert-reactions .reactionGroups))
841874
(insert "\n")
842875
(when (< .timelineItems.filteredCount .timelineItems.totalCount)
843876
(insert (propertize (format "Timeline items truncated. Displaying last %d of %d.\n"

0 commit comments

Comments
 (0)