File tree Expand file tree Collapse file tree 3 files changed +13
-5
lines changed
src/eamonnsullivan/github_api_lib
test/eamonnsullivan/github_api_lib Expand file tree Collapse file tree 3 files changed +13
-5
lines changed Original file line number Diff line number Diff line change 33 <modelVersion >4.0.0</modelVersion >
44 <groupId >eamonnsullivan</groupId >
55 <artifactId >github-api-lib</artifactId >
6- <version >0.1.18 </version >
6+ <version >0.1.19 </version >
77 <name >github-api-lib</name >
88 <description >Library of Github API calls that I happen to need.</description >
99 <url >https://github.com/eamonnsullivan/github-api-lib</url >
Original file line number Diff line number Diff line change 11(ns eamonnsullivan.github-api-lib.repos
2- (:require [eamonnsullivan.github-api-lib.core :as core]))
2+ (:require [clojure.string :as string]
3+ [eamonnsullivan.github-api-lib.core :as core]))
34
45(def ^:dynamic *default-page-size* 10 )
56
67(defn parse-repo
78 " Parse a repository url (a full url or just the owner/name part) and
89 return a map with :owner and :name keys."
910 [url]
10- (let [matches (re-matches #"(https://github.com/)?([^/]*)/([^/]*).*$" url)
11- [_ _ owner name] matches]
11+ (let [matches (re-matches #"(https://github.com/|git@github.com: )?([^/]*)/([^/]*)(.git)? .*$" url)
12+ [_ _ owner name _ ] matches]
1213 (if (and owner name (not-empty owner) (not-empty name))
13- {:owner owner :name name}
14+ {:owner owner
15+ :name (if (string/ends-with? name " .git" )
16+ (string/replace name #".git$" " " )
17+ name)}
1418 (throw (ex-info (format " Could not parse repository from url: %s" url) {})))))
1519
1620(defn get-repo-id
Original file line number Diff line number Diff line change 1919 (is (= {:owner " eamonnsullivan" :name " github-search" } (sut/parse-repo " eamonnsullivan/github-search/blob/master/src/eamonnsullivan/github_search.clj" )))
2020 (is (= {:owner " eamonnsullivan" :name " github-pr-lib" } (sut/parse-repo " eamonnsullivan/github-pr-lib/pull/1" )))
2121 (is (= {:owner " bbc" :name " optimo" } (sut/parse-repo " bbc/optimo/pull/1277" ))))
22+ (testing " handles ssh urls as well"
23+ (is (= {:owner " eamonnsullivan" :name " emacs.d" } (sut/parse-repo " git@github.com:eamonnsullivan/emacs.d.git" )))
24+ (is (= {:owner " eamonnsullivan" :name " github-search" } (sut/parse-repo " git@github.com:eamonnsullivan/github-search.git" )))
25+ (is (= {:owner " eamonnsullivan" :name " github-pr-lib" } (sut/parse-repo " git@github.com:eamonnsullivan/github-pr-lib.git" ))))
2226 (testing " Throws an exception when the url is incomplete or unrecognised"
2327 (is (thrown-with-msg? RuntimeException
2428 #"Could not parse repository from url: something else"
You can’t perform that action at this time.
0 commit comments