mirror of
https://github.com/NinjaTrappeur/my-repo-pins.git
synced 2024-06-18 03:21:57 +02:00
Implement dummy gitea and gitlab fetchers
This commit is contained in:
parent
ce62de0bc2
commit
e7d04c4e27
|
@ -6,10 +6,10 @@ Project checkout and navigation Emacs package heavily inspired by [zimbatm/h](ht
|
|||
TODO before first release:
|
||||
|
||||
- [x] Replace `directory-files-recursively` with custom implemention. Support 'till Emacs 24.
|
||||
- [ ] Implement GitHub fetcher.
|
||||
- [x] Implement GitHub fetcher.
|
||||
- [ ] Implement GitLab fetcher.
|
||||
- [ ] Implement sr.ht fetcher.
|
||||
- [ ] Implement codeberg fetcher.
|
||||
- [ ] ~~Implement sr.ht fetcher~~: GraphQL, no doc, playground behind loginwall. I won't bother after all. PR welcome.
|
||||
- [ ] Document how to implement a new fetcher.
|
||||
- [ ] Explain what the hell this thing is about in readme.
|
||||
|
||||
|
|
52
h.el
52
h.el
|
@ -108,6 +108,58 @@ nil as parameter."
|
|||
(format "https://api.github.com/repos/%s/%s" user-name repo-name)
|
||||
(lambda (&rest _rest) (funcall callback (h--fetch-github-parse-response(current-buffer))))))
|
||||
|
||||
;;; Gitea Fetcher
|
||||
|
||||
(defun h--query-gitea (instance-url user-name repo-name callback)
|
||||
"Queries the INSTANCE-URL gitea instance to retrieve a repo informations.
|
||||
This function will first try to dertermine whether the
|
||||
USER-NAME/REPO-NAME exists.
|
||||
|
||||
If so, calls the CALLBACK function with a alist containing the ssh and
|
||||
https clone URLs. If the repo does not exists, calls the callback with
|
||||
nil as parameter."
|
||||
(url-retrieve
|
||||
(format "%s/api/v1/repos/%s/%s" instance-url user-name repo-name)
|
||||
(lambda (&rest _rest) (funcall callback (h--fetch-gitea-parse-response(current-buffer))))))
|
||||
; Get /repos/owner/repo
|
||||
|
||||
|
||||
;;; Gitlab Fetcher
|
||||
|
||||
(defun h--query-gitlab (instance-url user-name repo-name callback)
|
||||
"Queries the INSTANCE-URL gitlab instance to retrieve a repo informations.
|
||||
This function will first try to dertermine whether the
|
||||
USER-NAME/REPO-NAME exists.
|
||||
|
||||
If so, calls the CALLBACK function with a alist containing the ssh and
|
||||
https clone URLs. If the repo does not exists, calls the callback with
|
||||
nil as parameter."
|
||||
(url-retrieve
|
||||
(format "%s/api/v4/users/%s/projects" instance-url user-name)
|
||||
(lambda (&rest _rest) (funcall callback nil))))
|
||||
;1. Find project in
|
||||
;https://gitlab.com/api/v4/users/ninjatrappeur/projects
|
||||
|
||||
;;; Generic fetcher infrastructure
|
||||
|
||||
(defcustom h-forge-fetchers
|
||||
'((github . ((query . h--query-github) (fqdn . "github.com"))))
|
||||
"List of forges for which we want to remote fetch projects."
|
||||
:type '(alist :key-type 'symbol :value-type 'function)
|
||||
:group 'h-group)
|
||||
|
||||
(defun h--parse-query-string-for-forge (query-string)
|
||||
"Parse QUERY-STRING for forge."
|
||||
query-string)
|
||||
|
||||
(defun h--dispatch-fetcher (query-string)
|
||||
"Try to download QUERY-STRING via the fetchers registered in ‘h-forge-fetchers’."
|
||||
(cond ((string-match-p "github.com" query-string)
|
||||
(apply 'h--query-github (h--parse-query-string-for-forge query-string)))
|
||||
((string-match-p "gitlab.com" query-string)
|
||||
(apply 'h--query-gitlab (h--parse-query-string-for-forge query-string)))
|
||||
(t (error (format "No fetcher for %s" query-string)))))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; Internal: code-root management functions
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
|
Loading…
Reference in a new issue