Skip to content

Commit

Permalink
More specific message when github auth fails (#238)
Browse files Browse the repository at this point in the history
* More specific message when github auth fails

* Changelog entry

* Update latest Clojure version
  • Loading branch information
teodorlu authored Aug 4, 2024
1 parent b07e2ce commit 6728367
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ See the [New Clojure project quickstart](https://blog.michielborkent.nl/new-cloj
## Unreleased

- [#230](https://github.com/babashka/neil/issues/230): neil dep upgrade inserts git/url into upgraded dep ([@teodorlu](https://github.com/teodorlu))
- [#237](https://github.com/babashka/neil/issues/230): more specific error reporting on invalid github token ([@teodorlu](https://github.com/teodorlu))

## 0.3.66

Expand Down
24 changes: 19 additions & 5 deletions src/babashka/neil/curl.clj
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,17 @@

(defn url-encode [s] (URLEncoder/encode s "UTF-8"))

(def github-user (or (System/getenv "NEIL_GITHUB_USER")
(System/getenv "BABASHKA_NEIL_DEV_GITHUB_USER")))
(def github-token (or (System/getenv "NEIL_GITHUB_TOKEN")
(System/getenv "BABASHKA_NEIL_DEV_GITHUB_TOKEN")))
(def github-user-envvars ["NEIL_GITHUB_USER" "BABASHKA_NEIL_DEV_GITHUB_USER"])
(def github-token-envvars ["NEIL_GITHUB_TOKEN" "BABASHKA_NEIL_DEV_GITHUB_TOKEN"])

(def github-user (some #(System/getenv %) github-user-envvars))
(def github-token (some #(System/getenv %) github-token-envvars))

(def github-basic-auth-enabled? (and github-user github-token))

(def curl-opts
(merge {:throw false}
(when (and github-user github-token)
(when github-basic-auth-enabled?
{:basic-auth [github-user github-token]})))

(defn curl-get-json
Expand All @@ -43,6 +46,17 @@
See neil's README for details.")
nil #_(System/exit 1))

(and (= 401 (:status response))
(string/includes? url "api.github")
(string/includes? (:message parsed-body) "Bad credentials")
github-basic-auth-enabled?)
(binding [*out* *err*]
(println "Your neil github token is invalid or expired.")
(when-let [token-envvar (first (filter #(System/getenv %) github-token-envvars))]
(println "Please double check your " token-envvar " environment variable."))
(println "See neil's README for more details.")
nil #_(System/exit 1))

(contains? unexceptional-statuses (:status response))
parsed-body
(= 404 (:status response))
Expand Down
2 changes: 1 addition & 1 deletion test/babashka/neil/dep_add_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
(deftest latest-version-test
(is (= "1.0.5" (neil/latest-stable-clojars-version 'hiccup/hiccup)))
(is (= "2.0.0-RC3" (neil/latest-clojars-version 'hiccup/hiccup)))
(is (= "1.11.3" (neil/latest-stable-mvn-version 'org.clojure/clojure))))
(is (= "1.11.4" (neil/latest-stable-mvn-version 'org.clojure/clojure))))

0 comments on commit 6728367

Please sign in to comment.