Skip to content

Commit

Permalink
Adjust to changes in closql
Browse files Browse the repository at this point in the history
  • Loading branch information
tarsius committed Jul 1, 2024
1 parent b4516cf commit fb272bd
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 27 deletions.
2 changes: 1 addition & 1 deletion forge-pkg.el
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"Access Git forges from Magit."
'((emacs "27.1")
(compat "29.1.4.5")
(closql "20240405")
(closql "20240701")
(dash "2.19.1")
(emacsql "20240124")
(ghub "20240507")
Expand Down
3 changes: 3 additions & 0 deletions lisp/forge-db.el
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@
(emacsql (forge-db) (apply #'format sql args))
(apply #'emacsql (forge-db) sql args)))

(defun forge-sql-cdr (sql &rest args)
(mapcar #'cdr (apply #'forge-sql sql args)))

(defun forge-connect-database-once ()
"Try to connect Forge database on first use of `magit-status' only."
(remove-hook 'magit-status-mode-hook #'forge-connect-database-once)
Expand Down
4 changes: 2 additions & 2 deletions lisp/forge-github.el
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,7 @@

(cl-defmethod forge--set-topic-assignees
((_repo forge-github-repository) topic assignees)
(let ((value (mapcar #'car (closql--iref topic 'assignees))))
(let ((value (mapcar #'cadr (oref topic assignees))))
;; FIXME Only refresh once.
(when-let ((add (cl-set-difference assignees value :test #'equal)))
(forge--ghub-post topic "/repos/:owner/:repo/issues/:number/assignees"
Expand All @@ -723,7 +723,7 @@

(cl-defmethod forge--set-topic-review-requests
((_repo forge-github-repository) topic reviewers)
(let ((value (mapcar #'car (closql--iref topic 'review-requests))))
(let ((value (mapcar #'cadr (oref topic review-requests))))
;; FIXME Only refresh once.
(when-let ((add (cl-set-difference reviewers value :test #'equal)))
(forge--ghub-post topic
Expand Down
30 changes: 27 additions & 3 deletions lisp/forge-issue.el
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,45 @@
(locked-p :initarg :locked-p)
(milestone :initarg :milestone)
(body :initarg :body)
(assignees :closql-table (issue-assignee assignee))
(assignees :closql-tables (issue-assignee assignee))
(project-cards) ; projectsCards
(edits) ; userContentEdits
(labels :closql-table (issue-label label))
(labels :closql-tables (issue-label label))
(participants)
(posts :closql-class forge-issue-post)
(reactions)
(timeline)
(marks :closql-table (issue-mark mark))
(marks :closql-tables (issue-mark mark))
(note :initarg :note :initform nil)
(their-id :initarg :their-id)
(slug :initarg :slug)
(saved-p :initarg :saved-p :initform nil)
))

(cl-defmethod closql-dref ((obj forge-issue) (_(eql assignees)))
(forge-sql-cdr
[:select assignee:* :from assignee
:join issue-assignee :on (= issue-assignee:id assignee:id)
:where (= issue-assignee:issue $s1)
:order-by [(asc login)]]
(closql--oref obj 'id)))

(cl-defmethod closql-dref ((obj forge-issue) (_(eql labels)))
(forge-sql-cdr
[:select label:* :from label
:join issue-label :on (= issue-label:id label:id)
:where (= issue-label:issue $s1)
:order-by [(asc name)]]
(closql--oref obj 'id)))

(cl-defmethod closql-dref ((obj forge-issue) (_(eql marks)))
(forge-sql-cdr
[:select mark:* :from mark
:join issue-mark :on (= issue-mark:id mark:id)
:where (= issue-mark:issue $s1)
:order-by [(asc name)]]
(closql--oref obj 'id)))

(defclass forge-issue-post (forge-post)
((closql-table :initform 'issue-post)
(closql-primary-key :initform 'id)
Expand Down
41 changes: 37 additions & 4 deletions lisp/forge-pullreq.el
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,18 @@
(head-repo :initarg :head-repo)
(milestone :initarg :milestone)
(body :initarg :body)
(assignees :closql-table (pullreq-assignee assignee))
(assignees :closql-tables (pullreq-assignee assignee))
(project-cards) ; projectsCards
(commits)
(edits) ; userContentEdits
(labels :closql-table (pullreq-label label))
(labels :closql-tables (pullreq-label label))
(participants)
(posts :closql-class forge-pullreq-post)
(reactions)
(review-requests :closql-table (pullreq-review-request assignee))
(review-requests :closql-tables (pullreq-review-request assignee))
(reviews)
(timeline)
(marks :closql-table (pullreq-mark mark))
(marks :closql-tables (pullreq-mark mark))
(note :initarg :note :initform nil)
(base-rev :initarg :base-rev)
(head-rev :initarg :head-rev)
Expand All @@ -76,6 +76,39 @@
(saved-p :initarg :saved-p :initform nil)
))

(cl-defmethod closql-dref ((obj forge-pullreq) (_(eql assignees)))
(forge-sql-cdr
[:select assignee:* :from assignee
:join pullreq-assignee :on (= pullreq-assignee:id assignee:id)
:where (= pullreq-assignee:pullreq $s1)
:order-by [(asc login)]]
(closql--oref obj 'id)))

(cl-defmethod closql-dref ((obj forge-pullreq) (_(eql labels)))
(forge-sql-cdr
[:select label:* :from label
:join pullreq-label :on (= pullreq-label:id label:id)
:where (= pullreq-label:pullreq $s1)
:order-by [(asc name)]]
(closql--oref obj 'id)))

(cl-defmethod closql-dref ((obj forge-pullreq) (_(eql review-requests)))
(forge-sql-cdr
[:select assignee:* :from assignee
:join pullreq-review-request
:on (= pullreq-review-request:id :id assignee:id)
:where (= pullreq-review-request:pullreq :pullreq $s1)
:order-by [(asc login)]]
(closql--oref obj 'id)))

(cl-defmethod closql-dref ((obj forge-pullreq) (_(eql marks)))
(forge-sql-cdr
[:select mark:* :from mark
:join pullreq-mark :on (= pullreq-mark:id mark:id)
:where (= pullreq-mark:pullreq $s1)
:order-by [(asc name)]]
(closql--oref obj 'id)))

(defclass forge-pullreq-post (forge-post)
((closql-table :initform 'pullreq-post)
(closql-primary-key :initform 'id)
Expand Down
34 changes: 17 additions & 17 deletions lisp/forge-topic.el
Original file line number Diff line number Diff line change
Expand Up @@ -678,36 +678,36 @@ can be selected from the start."
"Labels: "
(mapcar #'cadr (oref repo labels))
nil t
(and topic (mapconcat #'car (closql--iref topic 'labels) ",")))))
(and topic (mapconcat #'cadr (oref topic labels) ",")))))

(defun forge-read-topic-marks (&optional topic)
(let ((marks (mapcar #'car (forge-sql [:select name :from mark])))
(crm-separator ","))
(magit-completing-read-multiple
"Marks: " marks nil t
(and topic (mapconcat #'car (closql--iref topic 'marks) ",")))))
(and topic (mapconcat #'cadr (oref topic marks) ",")))))

(defun forge-read-topic-assignees (&optional topic)
(let* ((repo (forge-get-repository (or topic :tracked)))
(value (and topic (closql--iref topic 'assignees)))
(value (and topic (oref topic assignees)))
(choices (mapcar #'cadr (oref repo assignees)))
(crm-separator ","))
(magit-completing-read-multiple
"Assignees: " choices nil
(if (forge--childp repo 'forge-gitlab-repository)
t ; Selecting something else would fail later on.
'confirm)
(mapconcat #'car value ","))))
(mapconcat #'cadr value ","))))

(defun forge-read-topic-review-requests (&optional topic)
(let* ((repo (forge-get-repository (or topic :tracked)))
(value (and topic (closql--iref topic 'review-requests)))
(value (and topic (oref topic review-requests)))
(choices (mapcar #'cadr (oref repo assignees)))
(crm-separator ","))
(magit-completing-read-multiple
"Request review from: " choices nil
'confirm
(mapconcat #'car value ","))))
(mapconcat #'cadr value ","))))

(defun forge--completing-read ( prompt collection &optional
predicate require-match initial-input
Expand Down Expand Up @@ -817,8 +817,8 @@ can be selected from the start."
(magit--propertize-face str 'forge-topic-label)))

(defun forge--format-topic-labels (topic)
(and-let* ((labels (closql--iref topic 'labels)))
(mapconcat (pcase-lambda (`(,name ,color ,_description))
(and-let* ((labels (oref topic labels)))
(mapconcat (pcase-lambda (`(,_id ,name ,color ,_description))
(let* ((background (forge--sanitize-color color))
(foreground (forge--contrast-color background)))
(magit--propertize-face
Expand All @@ -828,8 +828,8 @@ can be selected from the start."
labels " ")))

(defun forge--format-topic-marks (topic)
(and-let* ((marks (closql--iref topic 'marks)))
(mapconcat (pcase-lambda (`(,name ,face ,_description))
(and-let* ((marks (oref topic marks)))
(mapconcat (pcase-lambda (`(,_id ,name ,face ,_description))
(magit--propertize-face
name (list 'forge-topic-label face)))
marks " ")))
Expand Down Expand Up @@ -857,15 +857,15 @@ can be selected from the start."
('done 'forge-topic-done)))))

(defun forge--format-topic-assignees (topic)
(and-let* ((assignees (closql--iref topic 'assignees)))
(and-let* ((assignees (oref topic assignees)))
(mapconcat #'forge--format-person assignees ", ")))

(defun forge--format-topic-review-requests (topic)
(and-let* ((review-requests (closql--iref topic 'review-requests)))
(and-let* ((review-requests (oref topic review-requests)))
(mapconcat #'forge--format-person review-requests ", ")))

(defun forge--format-person (person)
(pcase-let ((`(,login ,name) person))
(pcase-let ((`(,_id ,login ,name) person))
(format "%s%s (@%s)"
(forge--format-avatar login)
name login)))
Expand Down Expand Up @@ -921,9 +921,9 @@ can be selected from the start."
(forge--insert-pullreq-commits topic)))))

(defun forge--insert-topic-labels (topic &optional separate)
(and-let* ((labels (closql--iref topic 'labels)))
(and-let* ((labels (oref topic labels)))
(prog1 t
(pcase-dolist (`(,name ,color ,description) labels)
(pcase-dolist (`(,_id ,name ,color ,description) labels)
(let* ((background (forge--sanitize-color color))
(foreground (forge--contrast-color background)))
(if separate (insert " ") (setq separate t))
Expand All @@ -939,9 +939,9 @@ can be selected from the start."
(overlay-put o 'help-echo description))))))))

(defun forge--insert-topic-marks (topic &optional separate)
(and-let* ((marks (closql--iref topic 'marks)))
(and-let* ((marks (oref topic marks)))
(prog1 t
(pcase-dolist (`(,name ,face ,description) marks)
(pcase-dolist (`(,_id ,name ,face ,description) marks)
(if separate (insert " ") (setq separate t))
(insert name)
(let ((o (make-overlay (- (point) (length name)) (point))))
Expand Down

0 comments on commit fb272bd

Please sign in to comment.