Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Append the path to the github url with slash when necessary #10

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

phmeier-nubank
Copy link
Contributor

@phmeier-nubank phmeier-nubank commented Jul 9, 2021

  • Join path with baseurl using a / where necessary

@phmeier-nubank phmeier-nubank force-pushed the phmeier/join-path-with-slash branch 2 times, most recently from 7883ac3 to 96eba1b Compare July 9, 2021 12:51
@gabrielgiussi
Copy link
Contributor

Join path with baseurl using a / where necessary

This is to avoid having to pass {:path "/path"} ?

(if (success-codes (:status response))
(update response :body (partial parse-body (content-type response)))
(throw (ex-info "Request to GitHub failed"
{:response (select-keys response [:status :body])}
(:error response))))))

(defn new-client [{:keys [app-id private-key token org] :as opts}]
(defn new-client [{:keys [app-id private-key token org token-fn] :as opts}]
{:pre [(or token app-id token-fn)]}
Copy link
Contributor

@gabrielgiussi gabrielgiussi Jul 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of just app-id shouldn't be (and app-id private-key org)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, I think it's actually (or token token-fn (and app-id private-key)).

@gabrielgiussi
Copy link
Contributor

Allow to specify the Content-Type and Authorization request headers manually

Do you have a use case for this already?

@@ -11,14 +11,20 @@
(defn get-installation-token [{:keys [token-fn]}]
(token-fn))

(defn- append-url-path [baseurl path]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wdyt about adding some unit tests for these cases

(append-url-path "github.com" "path")
(append-url-path "github.com/" "path")
(append-url-path "github.com" "/path")

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

baseurl -> base-url

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gabrielgiussi this is a private function and implicitly tested in https://github.com/nubank/clj-github/pull/10/files#diff-3d82479c9bb9ffd50aac8b0bc3dacf8754ae47fb4c95de6794a0f7d25e870a4cR27. Also the github base url is defined as a constant, I don't think adding these tests add much value.

@rfhayashi
Copy link
Contributor

I'm ok with allowing overwriting the headers but would like to better understand what's the use case for allowing the path without the initial slash.

@@ -11,14 +11,20 @@
(defn get-installation-token [{:keys [token-fn]}]
(token-fn))

(defn- append-url-path [baseurl path]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

baseurl -> base-url

(defn- append-url-path [baseurl path]
(str baseurl (when-not (or (.endsWith baseurl "/")
(.startsWith path "/"))
"/") path))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To help make it distinguishable that path has nothing to do with the when-not expression could you either have one arg per line for the str function, or let-bind the when-not expr?

@phmeier-nubank
Copy link
Contributor Author

Allow to specify the Content-Type and Authorization request headers manually

Do you have a use case for this already?

I'm going to update the PR desc, this was part of the PR initially until I removed it. I had trouble with the github authorization before and specifying the Authorization header manually was what did it for me. Now that this code is no longer included the PR desc actually does not make sense.

@phmeier-nubank
Copy link
Contributor Author

Allow to specify the Content-Type and Authorization request headers manually

Do you have a use case for this already?

I'm going to update the PR desc, this was part of the PR initially until I removed it. I had trouble with the github authorization before and specifying the Authorization header manually was what did it for me. Now that this code is no longer included the PR desc actually does not make sense.

I'm going to remove the tests as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants