Skip to content

Commit

Permalink
[wip] discussions
Browse files Browse the repository at this point in the history
  • Loading branch information
tarsius committed Oct 3, 2023
1 parent 39bd96f commit 3949956
Show file tree
Hide file tree
Showing 10 changed files with 685 additions and 70 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
42 changes: 42 additions & 0 deletions lisp/forge-commands.el
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ Takes the pull-request as only argument and must return a directory."
("f t" "one topic" forge-pull-topic)
("f n" "notifications" forge-pull-notifications)
"""Create"
;; TODO hide for gitlab (Gitlab doesn't have discussions, does it?)
("c d" "discussion" forge-create-discussion)
("c i" "issue" forge-create-issue)
("c p" "pull-request" forge-create-pullreq)
("c u" "pull-request from issue" forge-create-pullreq-from-issue
Expand All @@ -71,6 +73,7 @@ Takes the pull-request as only argument and must return a directory."
["List"
:if forge-get-repository-p
("l t" "topics" forge-list-topics)
("l d" "discussions" forge-list-discussions)
("l i" "issues" forge-list-issues)
("l p" "pull-requests" forge-list-pullreqs)
("l n" "notifications" forge-list-notifications)
Expand All @@ -86,14 +89,17 @@ Takes the pull-request as only argument and must return a directory."
[:if forge-get-repository-p
[:description (lambda () (forge-dispatch--format-description "Visit"))
("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)]
[:description (lambda () (forge-dispatch--format-description "Browse"))
("b t" "topic" forge-browse-topic)
("b d" "discussion" forge-browse-discussion)
("b i" "issue" forge-browse-issue)
("b p" "pull-request" forge-browse-pullreq)]
["Browse"
("b r" "remote" forge-browse-remote)
("b D" "discussions" forge-browse-discussions)
("b I" "issues" forge-browse-issues)
("b P" "pull-requests" forge-browse-pullreqs)]]
[["Configure"
Expand Down Expand Up @@ -260,6 +266,13 @@ web interface, because Github doesn't consider that an update."

;;; 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 @@ -282,6 +295,14 @@ also offer closed topics."
(interactive (list (forge-read-pullreq "Browse topic" t)))
(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 @@ -418,6 +439,14 @@ with a prefix argument also closed topics."
(interactive (list (forge-read-topic "View topic" t)))
(forge-visit (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-visit (forge-get-discussion discussion)))

;;;###autoload
(defun forge-visit-issue (issue)
"Read an ISSUE and visit it.
Expand Down Expand Up @@ -448,6 +477,19 @@ with a prefix argument also closed topics."

;;; 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
121 changes: 119 additions & 2 deletions lisp/forge-db.el
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,11 @@
(pullreqs :default eieio-unbound)
selective-p
worktree
(milestones :default eieio-unbound)])
(milestones :default eieio-unbound)
(discussion-categories :default eieio-unbound)
(discussions :default eieio-unbound)
discussions-p
])

(assignee
[(repository :not-null)
Expand All @@ -119,6 +123,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 @@ -439,7 +540,23 @@
(emacsql db [:alter-table notification :add-column done-p
:default eieio-unbound])
(closql--db-set-version db (setq version 10))
(message "Upgrading Forge database from version 9 to 10...done")))
(message "Upgrading Forge database from version 9 to 10...done"))
(when nil ; TODO (= version 10)
(message "Upgrading Forge database from version 10 to 11...")
;; (let ((db (forge-db)))
;; (closql-with-transaction db
(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 11))
(message "Upgrading Forge database from version 10 to 11...done")))
(cl-call-next-method)))

(defun forge--backup-database (db)
Expand Down
Loading

0 comments on commit 3949956

Please sign in to comment.