Skip to content

Commit

Permalink
Support creating and showing review requests
Browse files Browse the repository at this point in the history
Closes #82.
  • Loading branch information
tarsius committed Jul 11, 2019
1 parent b8cd594 commit f105027
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 3 deletions.
14 changes: 14 additions & 0 deletions lisp/forge-commands.el
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,20 @@ point is currently on."
'confirm)
(mapconcat #'car value ","))))))

(defun forge-edit-topic-review-requests (topic)
"Edit the review-requests of TOPIC."
(interactive (list (forge-read-pullreq "Request review for")))
(let* ((repo (forge-get-repository topic))
(value (closql--iref topic 'review-requests))
(choices (mapcar #'cadr (oref repo assignees)))
(crm-separator ","))
(forge--set-topic-review-requests
repo topic
(magit-completing-read-multiple*
"Request review from: " choices nil
'confirm
(mapconcat #'car value ",")))))

;;; Delete

(defun forge-delete-comment (comment)
Expand Down
19 changes: 18 additions & 1 deletion lisp/forge-db.el
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
(require 'emacsql)
(require 'emacsql-sqlite)

(defvar forge--db-table-schemata)

(declare-function forge-reset-database "forge")

;;; Options
Expand All @@ -41,7 +43,7 @@
(defclass forge-database (closql-database)
((object-class :initform forge-repository)))

(defconst forge--db-version 2)
(defconst forge--db-version 3)

(defvar forge--db-connection nil
"The EmacSQL database connection.")
Expand All @@ -54,6 +56,14 @@
(let* ((db forge--db-connection)
(version (caar (emacsql db "PRAGMA user_version"))))
(cond
((and (= version 2) (= forge--db-version 3))
(message "Upgrading Forge database from version 2 to 3...")
(let ((db forge--db-connection))
(emacsql-with-transaction db
(emacsql db [:create-table pullreq-review-request $S1]
(cdr (assq 'pullreq-review-request forge--db-table-schemata)))
(emacsql db (format "PRAGMA user_version = %s" 3))))
(message "Upgrading Forge database from version 2 to 3...done"))
((> version forge--db-version)
(emacsql-close db)
(user-error "BUG: forge-db-version is too low"))
Expand Down Expand Up @@ -283,6 +293,13 @@
[pullreq] :references pullreq [id]
:on-delete :cascade))

(pullreq-review-request
[(pullreq :not-null)
(id :not-null)]
(:foreign-key
[pullreq] :references pullreq [id]
:on-delete :cascade))

(revnote
[(class :not-null)
(id :not-null :primary-key)
Expand Down
16 changes: 16 additions & 0 deletions lisp/forge-github.el
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,9 @@ repositories.
t)))
(when bump
(forge--set-id-slot repo pullreq 'assignees .assignees)
(forge--set-id-slot repo pullreq 'review-requests
(--map (cdr (cadr it))
(car .reviewRequests)))
(forge--set-id-slot repo pullreq 'labels .labels))
pullreq))))

Expand Down Expand Up @@ -504,6 +507,19 @@ repositories.
`((assignees . ,remove)))))
(forge-pull))

(cl-defmethod forge--set-topic-review-requests
((_repo forge-github-repository) topic reviewers)
(let ((value (mapcar #'car (closql--iref topic 'review-requests))))
(when-let ((add (cl-set-difference reviewers value :test #'equal)))
(forge--ghub-post
topic "/repos/:owner/:repo/pulls/:number/requested_reviewers"
`((reviewers . ,add))))
(when-let ((remove (cl-set-difference value reviewers :test #'equal)))
(forge--ghub-delete
topic "/repos/:owner/:repo/pulls/:number/requested_reviewers"
`((reviewers . ,remove)))))
(forge-pull))

(cl-defmethod forge--topic-templates ((repo forge-github-repository)
(_ (subclass forge-issue)))
(when-let ((files (magit-revision-files (oref repo default-branch))))
Expand Down
2 changes: 1 addition & 1 deletion lisp/forge-pullreq.el
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
(participants)
(posts :closql-class forge-pullreq-post)
(reactions)
(review-requests)
(review-requests :closql-table (pullreq-review-request assignee))
(reviews)
(timeline)
;; We don't use these fields:
Expand Down
21 changes: 20 additions & 1 deletion lisp/forge-topic.el
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,8 @@ identifier."
'(forge-insert-topic-title
forge-insert-topic-state
forge-insert-topic-labels
forge-insert-topic-assignees))
forge-insert-topic-assignees
forge-insert-topic-review-requests))

(defvar forge-post-section-map
(let ((map (make-sparse-keymap)))
Expand Down Expand Up @@ -471,6 +472,24 @@ identifier."
(insert (propertize "none" 'face 'magit-dimmed)))
(insert ?\n)))

(defvar forge-topic-review-requests-section-map
(let ((map (make-sparse-keymap)))
(define-key map [remap magit-edit-thing] 'forge-edit-topic-review-requests)
map))

(cl-defun forge-insert-topic-review-requests
(&optional (topic forge-buffer-topic))
(when (and (forge-github-repository-p (forge-get-repository topic))
(forge-pullreq-p topic))
(magit-insert-section (topic-review-requests)
(insert (format "%-11s" "Review-Requests: "))
(if-let ((review-requests (closql--iref topic 'review-requests)))
(insert (mapconcat (pcase-lambda (`(,login ,name))
(format "%s (@%s)" name login))
review-requests ", "))
(insert (propertize "none" 'face 'magit-dimmed)))
(insert ?\n))))

(defun forge--fontify-markdown (text)
(with-temp-buffer
(delay-mode-hooks
Expand Down

0 comments on commit f105027

Please sign in to comment.