Skip to content

Add support for latest releases from Gitea/Forgejo #24

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions quicklisp-controller.asd
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
(:file "upstream-git")
(:file "upstream-github")
(:file "upstream-gitlab")
(:file "upstream-gitea")
(:file "upstream-mercurial")
(:file "upstream-svn")
(:file "upstream-bzr")
Expand Down
38 changes: 38 additions & 0 deletions upstream-gitea.lisp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
;;;; upstream-gitea.lisp
;;;;
;;;; Fetch some basic info about a source from a gitea/forgejo instance
;;;;

(in-package #:quicklisp-controller)

(defun gitea-project-data (url)
(ppcre:register-groups-bind (host owner repo)
("//([^/]+?)/([^/]+?)/([^/]+?)(\\.git)?$" url)
(values host owner repo)))

(defun gitea-latest-release-uri (repo-url)
"Given a URL from a Gitea repo, give a URI to the latest release"
(multiple-value-bind (host owner repo) (gitea-project-data repo-url)
(format nil "https://~A/api/v1/repos/~A/~A/releases/latest"
host owner repo)))


(defun gitea-project-release-json (url)
(let* ((uri (gitea-latest-release-uri url))
(request (make-instance 'githappy::request
:uri uri))
(response (githappy::submit request))
(json (yason:parse (githappy::utf8-string (githappy::body response)))))
json))

(defun gitea-latest-release-info (url)
(let ((json (gitea-project-release-json url)))
(when json
(list :tag (githappy:jref json "tag_name")
:url (githappy:jref json "tarball_url")))))

(defclass latest-gitea-release-source (latest-github-release-source)
())

(defmethod github-info-plist ((source latest-gitea-release-source))
(gitea-latest-release-info (location source)))