Skip to content

Commit 7883ac3

Browse files
Append the path to the github url with slash when necessary
1 parent 91edb17 commit 7883ac3

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

Diff for: src/clj_github/httpkit_client.clj

+10-4
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,17 @@
1111
(defn get-installation-token [{:keys [token-fn]}]
1212
(token-fn))
1313

14+
(defn- append-url-path [baseurl path]
15+
(str baseurl (when-not (or (.endsWith baseurl "/")
16+
(.startsWith path "/"))
17+
"/") path))
18+
1419
(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}]
1621
(-> request
1722
(assoc :method method)
1823
(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))
2025
(assoc-in [:headers "Content-Type"] "application/json")
2126
(assoc-in [:headers "Authorization"] (str "Bearer " (token-fn)))))
2227

@@ -30,12 +35,13 @@
3035
(get-in response [:headers "Content-Type"])))
3136

3237
(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)]
3440
(if (success-codes (:status response))
3541
(update response :body (partial parse-body (content-type response)))
3642
(throw (ex-info "Request to GitHub failed" {:response (select-keys response [:status :body])})))))
3743

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}]
3945
(cond
4046
token
4147
{:token-fn (constantly token)}

Diff for: test/clj_github/httpkit_client_test.clj

+4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
(with-fake-http [{:url "https://api.github.com/path"}
2525
{:status 200}]
2626
(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"})))))
2731
(testing "github token is added to authorization header"
2832
(with-fake-http [{:headers {"Authorization" "Bearer token"
2933
"Content-Type" "application/json"}}

0 commit comments

Comments
 (0)