Skip to content

Commit

Permalink
[wip] discussions
Browse files Browse the repository at this point in the history
  • Loading branch information
tarsius committed Dec 8, 2024
1 parent b2bf67a commit 71db07e
Show file tree
Hide file tree
Showing 9 changed files with 636 additions and 33 deletions.
1 change: 1 addition & 0 deletions default.mk
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ ELS += $(PKG).el
ELS += $(PKG)-repo.el
ELS += $(PKG)-post.el
ELS += $(PKG)-topic.el
ELS += $(PKG)-discussion.el
ELS += $(PKG)-issue.el
ELS += $(PKG)-pullreq.el
ELS += $(PKG)-revnote.el
Expand Down
44 changes: 43 additions & 1 deletion lisp/forge-commands.el
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ Takes the pull-request as only argument and must return a directory."
["Visit"
:inapt-if-not forge--get-repository:tracked?
("v t" "topic" forge-visit-topic)
("v d" "discussion" forge-visit-discussion)
("v i" "issue" forge-visit-issue)
("v p" "pull-request" forge-visit-pullreq)]
["Browse"
Expand Down Expand Up @@ -221,6 +222,13 @@ repository cannot be determined, instead invoke `forge-add-repository'."

;;; Browse

;;;###autoload
(defun forge-browse-discussions ()
"Visit the current repository's discussions using a browser."
(interactive)
(browse-url (forge--format (forge-get-repository 'stub)
'discussions-url-format)))

;;;###autoload
(defun forge-browse-issues ()
"Visit the current repository's issues using a browser."
Expand All @@ -243,6 +251,14 @@ also offer closed topics."
(interactive (list (forge-read-topic "Browse topic")))
(forge--browse-topic topic))

;;;###autoload
(defun forge-browse-discussion (discussion)
"Read an DISCUSSION and visit it using a browser.
By default only offer open discussions but with a prefix argument
also offer closed issues."
(interactive (list (forge-read-issue "Browse discussion" t)))
(forge--browse-topic discussion))

;;;###autoload
(defun forge-browse-issue (issue)
"Read an ISSUE and visit it using a browser.
Expand Down Expand Up @@ -348,6 +364,9 @@ argument also offer closed pull-requests."
(cl-defgeneric forge-get-url (obj)
"Return the URL for a forge object.")

(cl-defmethod forge-get-url ((discussion forge-discussion))
(forge--format discussion 'discussion-url-format))

(cl-defmethod forge-get-url ((issue forge-issue))
(forge--format issue 'issue-url-format))

Expand Down Expand Up @@ -387,7 +406,9 @@ argument also offer closed pull-requests."

(cl-defmethod forge-get-url ((post forge-post))
(forge--format post (let ((topic (forge-get-parent post)))
(cond ((forge--childp topic 'forge-issue)
(cond ((forge--childp topic 'forge-discussion)
'discussion-post-url-format)
((forge--childp topic 'forge-issue)
'issue-post-url-format)
((forge--childp topic 'forge-pullreq)
'pullreq-post-url-format)))))
Expand All @@ -407,6 +428,14 @@ the limitation to active topics."
(interactive (list (forge-read-topic "View topic")))
(forge-topic-setup-buffer (forge-get-topic topic)))

;;;###autoload
(defun forge-visit-discussion (discussion)
"Read a DISCUSSION and visit it.
By default only offer open topics for completion;
with a prefix argument also closed topics."
(interactive (list (forge-read-discussion "View discussion" t)))
(forge-topic-setup-buffer (forge-get-discussion discussion)))

;;;###autoload
(defun forge-visit-issue (issue)
"Read an ISSUE and visit it.
Expand Down Expand Up @@ -462,6 +491,19 @@ With prefix argument MENU, also show the topic menu."

;;; Create

(defun forge-create-discussion ()
"Create a new discussion for the current repository."
(interactive)
(let* ((repo (forge-get-repository t))
(buf (forge--prepare-post-buffer
"new-discussion" ;TODO
(forge--format repo "Create new discussion on %p"))))
(when buf
(with-current-buffer buf
(setq forge--buffer-post-object repo)
(setq forge--submit-post-function #'forge--submit-create-discussion))
(forge--display-post-buffer buf))))

(defun forge-create-issue ()
"Create a new issue for the current repository."
(interactive)
Expand Down
114 changes: 114 additions & 0 deletions lisp/forge-db.el
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@
(milestones :default eieio-unbound)
issues-until
pullreqs-until
(discussion-categories :default eieio-unbound)
(discussions :default eieio-unbound)
discussions-p
])

(assignee
Expand All @@ -134,6 +137,103 @@
[repository] :references repository [id]
:on-delete :cascade))

(discussion
[(class :not-null)
(id :not-null :primary-key)
fid
number
repository
answer
state
state-reason
author
title
created
updated
closed
unread-p
done-p
locked-p
body
note
(edits :default eieio-unbound)
(labels :default eieio-unbound)
(posts :default eieio-unbound)
(reactions :default eieio-unbound)
(timeline :default eieio-unbound)
(marks :default eieio-unbound)]
(:foreign-key
[repository] :references repository [id]
:on-delete :cascade))

(discussion-category
[(repository :not-null)
(id :not-null :primary-key)
name
emoji
answerable-p
description]
(:foreign-key
[repository] :references repository [id]
:on-delete :cascade))

(discussion-label
[(discussion :not-null)
(id :not-null)]
(:foreign-key
[discussion] :references discussion [id]
:on-delete :cascade)
(:foreign-key
[id] :references label [id]
:on-delete :cascade))

(discussion-mark
[(discussion :not-null)
(id :not-null)]
(:foreign-key
[discussion] :references discussion [id]
:on-delete :cascade)
(:foreign-key
[id] :references mark [id]
:on-delete :cascade))

(discussion-post ; aka top-level answer
[(class :not-null)
(id :not-null :primary-key)
fid
number
discussion
author
created
updated
body
(edits :default eieio-unbound)
(reactions :default eieio-unbound)
(replies :default eieio-unbound)]
(:foreign-key
[discussion] :references discussion [id]
:on-delete :cascade))

(discussion-reply ; aka nested reply to top-level answer
[(class :not-null)
(id :not-null :primary-key)
fid
number
post
discussion
author
created
updated
body
(edits :default eieio-unbound)
(reactions :default eieio-unbound)]
(:foreign-key
[post] :references discussion-post [id]
:on-delete :cascade)
(:foreign-key
[discussion] :references discussion [id]
:on-delete :cascade))

(fork
[(parent :not-null)
(id :not-null :primary-key)
Expand Down Expand Up @@ -534,6 +634,20 @@
id))
(closql--db-set-version db (setq version 13))
(message "Upgrading Forge database from version 12 to 13...done"))
(when nil ; TODO (= version 13)
(message "Upgrading Forge database from version 13 to 14...")
(emacsql db [:create-table discussion $S1]
(cdr (assq 'discussion forge--db-table-schemata)))
(emacsql db [:create-table discussion-label $S1]
(cdr (assq 'discussion-label forge--db-table-schemata)))
(emacsql db [:create-table discussion-mark $S1]
(cdr (assq 'discussion-mark forge--db-table-schemata)))
(emacsql db [:create-table discussion-post $S1]
(cdr (assq 'discussion-post forge--db-table-schemata)))
(emacsql db [:create-table discussion-reply $S1]
(cdr (assq 'discussion-reply forge--db-table-schemata)))
(closql--db-set-version db (setq version 14))
(message "Upgrading Forge database from version 13 to 14...done"))
)
(cl-call-next-method)))

Expand Down
Loading

0 comments on commit 71db07e

Please sign in to comment.