From 093ffa5fbf7143f4668bb0a3dc9659a5cc836e12 Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Sat, 17 Jun 2023 17:20:29 +1000 Subject: Moving things one level deeper To ease gnu stow usage. Now we can do stow -t ~ emacs --- emacs/.emacs.d/lisp/my/my-github.el | 68 +++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 emacs/.emacs.d/lisp/my/my-github.el (limited to 'emacs/.emacs.d/lisp/my/my-github.el') diff --git a/emacs/.emacs.d/lisp/my/my-github.el b/emacs/.emacs.d/lisp/my/my-github.el new file mode 100644 index 0000000..7dc2248 --- /dev/null +++ b/emacs/.emacs.d/lisp/my/my-github.el @@ -0,0 +1,68 @@ +;;; my-github.el -- Github client -*- lexical-binding: t -*- + +;; Copyright (C) 2023 Free Software Foundation. + +;; Author: Yuchen Pei +;; Package-Requires: ((emacs "28.2")) + +;; This file is part of dotfiles. + +;; dotfiles is free software: you can redistribute it and/or modify it under +;; the terms of the GNU Affero General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; dotfiles is distributed in the hope that it will be useful, but WITHOUT +;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General +;; Public License for more details. + +;; You should have received a copy of the GNU Affero General Public +;; License along with dotfiles. If not, see . + +;;; Commentary: + +;; Github client. + +;;; Code: + + +(defun my-grok-github (url) + "get github info of a project. +url is the url of the project +License; name; description; homepage; created at" + (when (string-match "github.com\\(/[^/]+/[^/]+\\)/?.*$" url) + (with-current-buffer (url-retrieve-synchronously + (concat "https://api.github.com/repos" + (replace-regexp-in-string + "\\.git$" "" (match-string 1 url)))) + (set-buffer-multibyte t) + (my-delete-http-header) + (my-grok-github-make-info (json-read))))) + +(defun my-post-process-licensing-name (name) + (cond ((equal name "MIT") "expat") + (t name))) + +(defun my-grok-github-make-info (raw) + (list (cons "Title" (alist-get 'name raw)) + (cons "Description" (alist-get 'description raw)) + (cons "Source" (alist-get 'html_url raw)) + (cons "Website" (alist-get 'homepage raw)) + (cons "Released" (substring (alist-get 'created_at raw) 0 10)) + (cons "Pushed" (substring (alist-get 'pushed_at raw) 0 10)) + (cons "Subject" (string-join (alist-get 'topics raw) ", ")) + ;; FIXME: why did we comment this out? + ;; (cons "License" (my-post-process-licensing-name + ;; (alist-get 'spdx_id (alist-get 'license raw)))) + (cons "Developers" (my-grok-github-get-developer-name + (alist-get 'url (alist-get 'owner raw)))))) + +(defun my-grok-github-get-developer-name (url) + (with-current-buffer (url-retrieve-synchronously url) + (set-buffer-multibyte t) + (my-delete-http-header) + (alist-get 'name (json-read)))) + +(provide 'my-github) +;;; my-github.el ends here -- cgit v1.2.3