mirror of
https://github.com/NinjaTrappeur/my-repo-pins.git
synced 2024-06-01 19:14:07 +02:00
Implement h--parse-repo-identifier
This function is meant to identify what kind of repo a user is giving to us.
This commit is contained in:
parent
e7d04c4e27
commit
db74a5794a
10
h-tests.el
10
h-tests.el
|
@ -216,5 +216,15 @@ For reference: a empty test root looks like this:
|
|||
(insert-file-contents "./tests/fixtures/github-get-request-ko.txt")
|
||||
(should (equal (h--fetch-github-parse-response (current-buffer)) nil))))
|
||||
|
||||
;; Test repo URI parser
|
||||
;;;;;;;;;;;;;;;;;
|
||||
|
||||
(ert-deftest h--test-parse-repo-idetifier ()
|
||||
"Test h--parse-repo-identifier."
|
||||
(should (equal (h--parse-repo-identifier "https://github.com/Ninjatrappeur/h.el") 'full-url))
|
||||
(should (equal (h--parse-repo-identifier "github.com/Ninjatrappeur/h.el") 'full-url))
|
||||
(should (equal (h--parse-repo-identifier "Ninjatrappeur/h.el") 'owner-repo))
|
||||
(should (equal (h--parse-repo-identifier "h.el") 'repo)))
|
||||
|
||||
(provide 'h-tests)
|
||||
;;; h-tests.el ends here
|
||||
|
|
26
h.el
26
h.el
|
@ -160,6 +160,32 @@ nil as parameter."
|
|||
(apply 'h--query-gitlab (h--parse-query-string-for-forge query-string)))
|
||||
(t (error (format "No fetcher for %s" query-string)))))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; Internal: repo URI parser
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
(defun h--parse-repo-identifier (repo-str)
|
||||
"Do its best to figure out which repo the user meant by REPO-STR.
|
||||
|
||||
A valid REPO-STR is in one of the 4 following formats:
|
||||
|
||||
1. project
|
||||
Jump to the project if available, do not fetch a remote forge
|
||||
project.
|
||||
2. owner/project
|
||||
Open a promp with available projects + fetch all the remote
|
||||
forges.
|
||||
3. forge.tld/owner/project
|
||||
Open the project is available, fetch it if not.
|
||||
4. https://forge.tld/owner/project
|
||||
Open the project is available, fetch it if not."
|
||||
(cond
|
||||
((or (string-match "^https://.*/.*/.*$" repo-str)
|
||||
(string-match "^.*/.*/.*$" repo-str))
|
||||
'full-url)
|
||||
((string-match "^.*/.*$" repo-str) 'owner-repo)
|
||||
(t 'repo)))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; Internal: code-root management functions
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
|
Loading…
Reference in a new issue