File tree Expand file tree Collapse file tree 2 files changed +14
-4
lines changed Expand file tree Collapse file tree 2 files changed +14
-4
lines changed Original file line number Diff line number Diff line change 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
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)}
Original file line number Diff line number Diff line change 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" }}
You can’t perform that action at this time.
0 commit comments