diff options
author | Yuchen Pei <id@ypei.org> | 2025-01-05 17:34:34 +1100 |
---|---|---|
committer | Yuchen Pei <id@ypei.org> | 2025-01-05 17:34:34 +1100 |
commit | bb57c3e606d844000ceb725a4f15f7d92a1d5b67 (patch) | |
tree | b6ce6cf0aa8e619dd3b1de03ff35e34d38961c0a /emacs/.emacs.d/lisp/my/my-gitlab.el | |
parent | 72139ef3250f7cad9dad3ccbdc7a829befcb5c5f (diff) |
[emacs][gdb] Infobox with gitlab
* emacs/.emacs.d/init/ycp-org.el: Forgot to require 'my-org-remark
* emacs/.emacs.d/lisp/my/infobox.el: A utility to display alist in a
help buffer
* emacs/.emacs.d/lisp/my/my-buffer.el: Add a function that fontify a
string with a given mode
* emacs/.emacs.d/lisp/my/my-gitlab.el: Example of using infobox, by
displaying gitlab project info in a help buffer
* emacs/.emacs.d/lisp/my/my-net.el: add a function that fetch a url raw
* emacs/.emacs.d/lisp/my/my-prog.el: reduce timeout in gdb completion
from 1 to .1 sec, but the code is commented out anyway because it does
not work (see preceding comments)
* misc/.gdbinit: enable debuginfod and reduce max-completions to 20 to
reduce hanging caused by exhaustive search of completions
Diffstat (limited to 'emacs/.emacs.d/lisp/my/my-gitlab.el')
-rw-r--r-- | emacs/.emacs.d/lisp/my/my-gitlab.el | 75 |
1 files changed, 65 insertions, 10 deletions
diff --git a/emacs/.emacs.d/lisp/my/my-gitlab.el b/emacs/.emacs.d/lisp/my/my-gitlab.el index 6dd484c..04d2ba0 100644 --- a/emacs/.emacs.d/lisp/my/my-gitlab.el +++ b/emacs/.emacs.d/lisp/my/my-gitlab.el @@ -26,8 +26,9 @@ ;;; Code: +(require 'infobox) -(defun my-get-gitlab-project-id (url) +(defun my-gitlab-get-project-id (url) (with-current-buffer (url-retrieve-synchronously (replace-regexp-in-string "\\.git$" "" url)) (let ((dom (libxml-parse-html-region (point-min) (point-max)))) @@ -35,16 +36,70 @@ (dom-search dom (lambda (n) (dom-attr n 'data-project-id)))) 'data-project-id)))) -(defun my-grok-gitlab (url) +(defun my-gitlab-api-projects (url) (when-let* ((urlobj (url-generic-parse-url url)) - (project-id (my-get-gitlab-project-id url))) - (with-current-buffer - (url-retrieve-synchronously - (concat (url-type urlobj) "://" (url-host urlobj) - "/api/v4/projects/" project-id)) - (set-buffer-multibyte t) - (my-delete-http-header) - (my-grok-gitlab-make-info (json-read))))) + (project-id (my-gitlab-get-project-id url))) + (my-url-fetch-json + (format "%s://%s/api/v4/projects/%s" + (url-type urlobj) + (url-host urlobj) + project-id)))) + +(defvar my-gitlab-readme-get-raw nil "Whether to get raw or html readme") + +(defun my-gitlab-project-info (url) + "Given a url, returns project info." + (let ((info (my-gitlab-api-projects url))) + (let-alist info + (when .readme_url + (setf (alist-get 'readme info) + (if my-gitlab-readme-get-raw + (format + "\n%s" + (my-url-fetch-raw + (replace-regexp-in-string "/-/blob/" "/-/raw/" .readme_url))) + (alist-get + 'html + (my-url-fetch-json + (format "%s?format=json&viewer=rich" .readme_url))))))) + info)) + +(defun my-gitlab-format-time-string (t) + (format-time-string "%Y-%m-%d %M:%M:%S" (encode-time (parse-time-string t)))) + +(require 'my-buffer) + +(defvar my-gitlab-project-info-specs + `((http_url_to_repo . "Clone") + (name_with_namespace . "Name") + (description . "Description") + (created_at . ("Created at" . my-gitlab-format-time-string)) + (last_activity_at . ("Updated at" . my-gitlab-format-time-string)) + (topics . ("Topics" . ,(lambda (xs) + (mapconcat #'identity xs "; ")))) + (star_count . ("Stars" . number-to-string)) + (forks_count . ("Forks" . number-to-string)) + (readme . (body . ,(lambda (text) + (with-temp-buffer + (insert text) + (shr-render-region (point-min) (point-max)) + (buffer-string))))))) + +(defun my-gitlab-project-infobox (url) + "Display a gitlab project info at URL in a help buffer. + +A good example would be +<https://gitlab.com/woob/woob> +" + (interactive "sGitlab project URL: ") + (infobox-render + (infobox-translate + (my-gitlab-project-info url) my-gitlab-project-info-specs) + `(my-gitlab-project-infobox ,url) + (called-interactively-p 'interactive))) + +(defun my-grok-gitlab (url) + (my-grok-gitlab-make-info (my-gitlab-api-projects url))) (defun my-grok-gitlab-make-info (raw) (list (cons "Title" (alist-get 'name raw)) |