File tree 2 files changed +14
-4
lines changed
2 files changed +14
-4
lines changed Original file line number Diff line number Diff line change 11
11
(defn get-installation-token [{:keys [token-fn]}]
12
12
(token-fn ))
13
13
14
+ (defn- append-url-path [baseurl path]
15
+ (str baseurl (when-not (or (.endsWith baseurl " /" )
16
+ (.startsWith path " /" ))
17
+ " /" ) path))
18
+
14
19
(defn- prepare
15
- [{:keys [token-fn]} {:keys [path method body] :or {method :get } :as request}]
20
+ [{:keys [token-fn]} {:keys [path method body] :or {method :get path " " } :as request}]
16
21
(-> request
17
22
(assoc :method method)
18
23
(assoc-some :body (and body (cheshire/generate-string body)))
19
- (assoc :url (str github-url path))
24
+ (assoc :url (append-url-path github-url path))
20
25
(assoc-in [:headers " Content-Type" ] " application/json" )
21
26
(assoc-in [:headers " Authorization" ] (str " Bearer " (token-fn )))))
22
27
30
35
(get-in response [:headers " Content-Type" ])))
31
36
32
37
(defn request [client req-map]
33
- (let [response @(httpkit/request (prepare client req-map))]
38
+ (let [request (prepare client req-map)
39
+ response @(httpkit/request request)]
34
40
(if (success-codes (:status response))
35
41
(update response :body (partial parse-body (content-type response)))
36
42
(throw (ex-info " Request to GitHub failed" {:response (select-keys response [:status :body ])})))))
37
43
38
- (defn new-client [{:keys [app-id private-key token org] :as opts}]
44
+ (defn new-client [{:keys [app-id private-key token org token-fn ] :as opts}]
39
45
(cond
40
46
token
41
47
{:token-fn (constantly token)}
Original file line number Diff line number Diff line change 24
24
(with-fake-http [{:url " https://api.github.com/path" }
25
25
{:status 200 }]
26
26
(is (match? {:status 200 } (sut/request client {:path " /path" })))))
27
+ (testing " path is appended to url with optional slash"
28
+ (with-fake-http [{:url " https://api.github.com/path" }
29
+ {:status 200 }]
30
+ (is (match? {:status 200 } (sut/request client {:path " path" })))))
27
31
(testing " github token is added to authorization header"
28
32
(with-fake-http [{:headers {" Authorization" " Bearer token"
29
33
" Content-Type" " application/json" }}
You can’t perform that action at this time.
0 commit comments