Commit 329171e 1 parent 0d3a12e commit 329171e Copy full SHA for 329171e
File tree 3 files changed +13
-5
lines changed
src/eamonnsullivan/github_api_lib
test/eamonnsullivan/github_api_lib
3 files changed +13
-5
lines changed Original file line number Diff line number Diff line change 3
3
<modelVersion >4.0.0</modelVersion >
4
4
<groupId >eamonnsullivan</groupId >
5
5
<artifactId >github-api-lib</artifactId >
6
- <version >0.1.18 </version >
6
+ <version >0.1.19 </version >
7
7
<name >github-api-lib</name >
8
8
<description >Library of Github API calls that I happen to need.</description >
9
9
<url >https://github.com/eamonnsullivan/github-api-lib</url >
Original file line number Diff line number Diff line change 1
1
(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]))
3
4
4
5
(def ^:dynamic *default-page-size* 10 )
5
6
6
7
(defn parse-repo
7
8
" Parse a repository url (a full url or just the owner/name part) and
8
9
return a map with :owner and :name keys."
9
10
[url]
10
- (let [matches (re-matches #"(https://github.com/)?([^/]*)/([^/]*).*$" url)
11
- [_ _ owner name] matches]
11
+ (
let [matches (
re-matches #"(https://github.com/|[email protected] : )?([^/]*)/([^/]*)(.git)? .*$" url)
12
+ [_ _ owner name _ ] matches]
12
13
(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)}
14
18
(throw (ex-info (format " Could not parse repository from url: %s" url) {})))))
15
19
16
20
(defn get-repo-id
Original file line number Diff line number Diff line change 19
19
(is (= {:owner " eamonnsullivan" :name " github-search" } (sut/parse-repo " eamonnsullivan/github-search/blob/master/src/eamonnsullivan/github_search.clj" )))
20
20
(is (= {:owner " eamonnsullivan" :name " github-pr-lib" } (sut/parse-repo " eamonnsullivan/github-pr-lib/pull/1" )))
21
21
(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 " [email protected] :eamonnsullivan/emacs.d.git" )))
24
+ (
is (
= {
:owner " eamonnsullivan" :name " github-search" } (
sut/parse-repo " [email protected] :eamonnsullivan/github-search.git" )))
25
+ (
is (
= {
:owner " eamonnsullivan" :name " github-pr-lib" } (
sut/parse-repo " [email protected] :eamonnsullivan/github-pr-lib.git" ))))
22
26
(testing " Throws an exception when the url is incomplete or unrecognised"
23
27
(is (thrown-with-msg? RuntimeException
24
28
#"Could not parse repository from url: something else"
You can’t perform that action at this time.
0 commit comments