diff --git a/helm-github-stars.el b/helm-github-stars.el index da77964..320b5d9 100644 --- a/helm-github-stars.el +++ b/helm-github-stars.el @@ -72,7 +72,8 @@ (insert (s-join "\n" (hgs/get-github-stars)))))) (candidates-in-buffer) (action . (lambda (candidate) - (browse-url (concat hgs/github-url candidate))))) + (let ((repo (substring candidate 0 (string-match " - " candidate)))) + (browse-url (concat hgs/github-url repo)))))) "Helm source definition.") (defvar hgs/helm-c-source-repos @@ -83,7 +84,8 @@ (insert (s-join "\n" (hgs/get-github-repos)))))) (candidates-in-buffer) (action . (lambda (candidate) - (browse-url (concat hgs/github-url candidate))))) + (let ((repo (substring candidate 0 (string-match " - " candidate)))) + (browse-url (concat hgs/github-url repo)))))) "Helm source definition.") (defvar hgs/helm-c-source-search @@ -96,14 +98,13 @@ "Read cache file and return list of starred repositories." (with-temp-buffer (insert-file-contents helm-github-stars-cache-file) - (let ((json-object-type 'hash-table)) - (json-read-from-string (buffer-string))))) + (read (current-buffer)))) (defun hgs/write-cache-file (hash) "Write HASH of repositories in cache file." (with-temp-buffer (let ((file helm-github-stars-cache-file)) - (insert (json-encode hash)) + (print hash (current-buffer)) (when (file-writable-p file) (write-region (point-min) (point-max) file))))) @@ -177,7 +178,10 @@ (repos []) (i 0)) (while (< i (length github-repos)) - (setq repos (vconcat repos (vector (cdr (assoc 'full_name (elt github-repos i)))))) + (setq repos (vconcat repos (vector (concat + (cdr (assoc 'full_name (elt github-repos i))) + " - " + (cdr (assoc 'description (elt github-repos i))))))) (setq i (1+ i))) repos)) diff --git a/test/helm-github-stars-test.el b/test/helm-github-stars-test.el index 0bb93c1..1a4dfa3 100644 --- a/test/helm-github-stars-test.el +++ b/test/helm-github-stars-test.el @@ -36,7 +36,7 @@ (ert-deftest hgs/read-cache-file-test () (with-cache - (f-write-text hgs-test/cache-json-string 'utf-8 cache-test-file) + (f-write-text hgs-test/cache-string 'utf-8 cache-test-file) (should (equal (gethash "repos" (hgs/read-cache-file)) hgs-test/repos-list)) (should (equal (gethash "stars" (hgs/read-cache-file)) hgs-test/stars-list)))) @@ -44,7 +44,7 @@ (with-cache (hgs/write-cache-file hgs-test/cache-hash-table) (should (equal (f-read-text cache-test-file) - hgs-test/cache-json-string)))) + hgs-test/cache-string)))) (ert-deftest hgs/cache-file-exists-test () (with-cache @@ -69,16 +69,16 @@ (elt hgs-test/github-repos-response-stub (1- page))) (hgs/generate-cache-file) (should (equal (f-read-text cache-test-file) - hgs-test/cache-json-string)))) + hgs-test/cache-string)))) (ert-deftest hgs/parse-github-response-test () (should (equal (hgs/parse-github-response (elt hgs-test/github-stars-response-stub 0)) - ["star/1" "star/2"]))) + ["star/1 - desc-star1" "star/2 - desc-star2"]))) (ert-deftest hgs/get-github-stars-with-generated-cache-test () (with-cache - (f-write-text hgs-test/cache-json-string 'utf-8 cache-test-file) - (should (equal (hgs/get-github-stars) ["star/1" "star/2" "star/3"])))) + (f-write-text hgs-test/cache-string 'utf-8 cache-test-file) + (should (equal (hgs/get-github-stars) ["star/1 - desc-star1" "star/2 - desc-star2" "star/3 - desc-star3"])))) (ert-deftest hgs/get-github-stars-without-generated-cache-test () (with-cache @@ -88,12 +88,12 @@ (defun hgs/request-github-repos (page) "Stub github response." (elt hgs-test/github-repos-response-stub (1- page))) - (should (equal (hgs/get-github-stars) ["star/1" "star/2" "star/3"])))) + (should (equal (hgs/get-github-stars) ["star/1 - desc-star1" "star/2 - desc-star2" "star/3 - desc-star3"])))) (ert-deftest hgs/get-github-repos-with-generated-cache-test () (with-cache - (f-write-text hgs-test/cache-json-string 'utf-8 cache-test-file) - (should (equal (hgs/get-github-repos) ["repo/1" "repo/2" "repo/3"])))) + (f-write-text hgs-test/cache-string 'utf-8 cache-test-file) + (should (equal (hgs/get-github-repos) ["repo/1 - desc-repo1" "repo/2 - desc-repo2" "repo/3 - desc-repo3"])))) (ert-deftest hgs/get-github-repos-without-generated-cache-test () (with-cache @@ -103,7 +103,7 @@ (defun hgs/request-github-repos (page) "Stub github response." (elt hgs-test/github-repos-response-stub (1- page))) - (should (equal (hgs/get-github-repos) ["repo/1" "repo/2" "repo/3"])))) + (should (equal (hgs/get-github-repos) ["repo/1 - desc-repo1" "repo/2 - desc-repo2" "repo/3 - desc-repo3"])))) (ert-deftest helm-github-stars-fetch-test () "This test just check that cache file is removed before calling helm-github-stars" @@ -111,7 +111,7 @@ (defun helm-github-stars () "Overwrite helm-github-stars. Return t if cache file exists, nil if not exists." (f-file? cache-test-file)) - (f-write-text hgs-test/cache-json-string 'utf-8 cache-test-file) + (f-write-text hgs-test/cache-string 'utf-8 cache-test-file) (should (not (helm-github-stars-fetch))))) ;;; helm-github-stars-test.el ends here diff --git a/test/test-helper.el b/test/test-helper.el index 07a3c0a..7052db7 100644 --- a/test/test-helper.el +++ b/test/test-helper.el @@ -44,7 +44,7 @@ (expand-file-name "helm-github-stars.el" root-dir)) (defmacro with-cache (&rest body) - "Evaluate TEST with cache interaction." + "Evaluate BODY with cache interaction." `(let ((helm-github-stars-cache-file cache-test-file)) (when (f-file? cache-test-file) (f-delete cache-test-file)) @@ -54,23 +54,23 @@ ;;Stubing (defvar hgs-test/github-stars-response-stub - ["[ {\"full_name\": \"star/1\"},{\"full_name\": \"star/2\"}]" - "[ {\"full_name\": \"star/3\"}]" + ["[ {\"full_name\": \"star/1\", \"description\": \"desc-star1\"},{\"full_name\": \"star/2\", \"description\": \"desc-star2\"}]" + "[ {\"full_name\": \"star/3\", \"description\": \"desc-star3\"}]" "[ ]"]) (defvar hgs-test/github-repos-response-stub - ["[ {\"full_name\": \"repo/1\"},{\"full_name\": \"repo/2\"}]" - "[ {\"full_name\": \"repo/3\"}]" + ["[ {\"full_name\": \"repo/1\", \"description\": \"desc-repo1\"},{\"full_name\": \"repo/2\", \"description\": \"desc-repo2\"}]" + "[ {\"full_name\": \"repo/3\", \"description\": \"desc-repo3\"}]" "[ ]"]) -(defvar hgs-test/cache-json-string - "{\"repos\":[\"repo\\/1\", \"repo\\/2\", \"repo\\/3\"], \"stars\":[\"star\\/1\", \"star\\/2\", \"star\\/3\"]}") +(defvar hgs-test/cache-string + "\n#s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8 data (\"stars\" [\"star/1 - desc-star1\" \"star/2 - desc-star2\" \"star/3 - desc-star3\"] \"repos\" [\"repo/1 - desc-repo1\" \"repo/2 - desc-repo2\" \"repo/3 - desc-repo3\"]))\n") (defvar hgs-test/repos-list - ["repo/1" "repo/2" "repo/3"]) + ["repo/1 - desc-repo1" "repo/2 - desc-repo2" "repo/3 - desc-repo3"]) (defvar hgs-test/stars-list - ["star/1" "star/2" "star/3"]) + ["star/1 - desc-star1" "star/2 - desc-star2" "star/3 - desc-star3"]) (defvar hgs-test/cache-hash-table (make-hash-table :test 'equal))