nicokosi / hubstats

🧪 Command-line for GitHub pull request statistics
5 stars 0 forks source link

Use hato as a HTTP client #49

Closed nicokosi closed 3 years ago

nicokosi commented 3 years ago

Let's try another HTTP client ans see if it's easier to fix #48. 🤷

nicokosi commented 3 years ago

It works if no token:

lein run --organization nicokosi --repository hubstats
pull requests for nicokosi/hubstats ->
    since 2021-02-24T06:02:10Z
        1 opened / 0 closed / 0 commented (0 comments)
        opened per author:  {nicokosi 1}
        comments per author:  {}
        closed per author:  {}

But fails with a GitHub token:

lein run --organization softwarevidal --repository arthur --token $GITHUB_TOKEN
Exception in thread "async-dispatch-1" clojure.lang.ExceptionInfo: status: 404 {:request-time 591, :request {:user-info nil, :as :json, :headers {"accept-encoding" "gzip, deflate", "authorization" "Basic Og=="}, :server-port nil, :url "https://api.github.com/repos/softwarevidal/arthur/events?page=1", :http-request #object[jdk.internal.net.http.HttpRequestImpl 0x3f34caf1 "https://api.github.com/repos/softwarevidal/arthur/events?page=1 GET"], :uri "/repos/softwarevidal/arthur/events", :server-name "api.github.com", :query-string "page=1", "Accept" "application/vnd.github.v3+json", :scheme :https, :request-method :get}, :http-client #object[jdk.internal.net.http.HttpClientFacade 0x5c3caa7b "jdk.internal.net.http.HttpClientImpl@4b694078(1)"], :headers {"access-control-expose-headers" "ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, Deprecation, Sunset", "referrer-policy" "origin-when-cross-origin, strict-origin-when-cross-origin", "content-encoding" "gzip", "server" "GitHub.com", "content-type" "application/json; charset=utf-8", "access-control-allow-origin" "*", "x-content-type-options" "nosniff", "x-frame-options" "deny", "strict-transport-security" "max-age=31536000; includeSubdomains; preload", "x-ratelimit-limit" "60", "x-ratelimit-remaining" "35", "x-ratelimit-reset" "1614753382", "x-github-request-id" "734C:9CE8:1868CFD:18C4D1B:603F254B", "x-ratelimit-used" "25", "x-github-media-type" "github.v3; format=json", ":status" "404", "date" "Wed, 03 Mar 2021 05:57:31 GMT", "vary" "Accept-Encoding, Accept, X-Requested-With", "x-xss-protection" "1; mode=block", "content-security-policy" "default-src 'none'"}, :status 404, :content-type :application/json, :uri "https://api.github.com/repos/softwarevidal/arthur/events?page=1", :content-type-params {:charset "utf-8"}, :version :http-2, :body "{\"message\":\"Not Found\",\"documentation_url\":\"https://docs.github.com/rest/reference/activity#list-repository-events\"}"}
    at hato.middleware$exceptions_response.invokeStatic(middleware.clj:149)
    at hato.middleware$exceptions_response.invoke(middleware.clj:140)
    at hato.middleware$wrap_exceptions$fn__369.invoke(middleware.clj:158)
    at hato.middleware$wrap_accept$fn__477.invoke(middleware.clj:315)
    at hato.middleware$wrap_accept_encoding$fn__484.invoke(middleware.clj:337)
    at hato.middleware$wrap_multipart$fn__660.invoke(middleware.clj:705)
    at hato.middleware$wrap_content_type$fn__471.invoke(middleware.clj:298)
    at hato.middleware$wrap_form_params$fn__582.invoke(middleware.clj:536)
    at hato.middleware$wrap_nested_params$fn__654.invoke(middleware.clj:685)
    at hato.middleware$wrap_method$fn__540.invoke(middleware.clj:470)
    at hato.client$request.invokeStatic(client.clj:314)
    at hato.client$request.doInvoke(client.clj:308)
    at clojure.lang.RestFn.invoke(RestFn.java:439)
    at hato.client$configure_and_execute.invokeStatic(client.clj:319)
    at hato.client$configure_and_execute.doInvoke(client.clj:316)
    at clojure.lang.RestFn.invoke(RestFn.java:442)
    at clojure.core$partial$fn__5858.invoke(core.clj:2629)
    at hubstats.github$github_api_events.invokeStatic(github.clj:15)
    at hubstats.github$github_api_events.invoke(github.clj:12)
    at hubstats.github$events.invokeStatic(github.clj:25)
    at hubstats.github$events.invoke(github.clj:21)
    at hubstats.github$events.invokeStatic(github.clj:28)
    at hubstats.github$events.invoke(github.clj:21)
    at hubstats.github$events.invokeStatic(github.clj:33)
    at hubstats.github$events.invoke(github.clj:21)
    at hubstats.github$pr_stats.invokeStatic(github.clj:76)
    at hubstats.github$pr_stats.invoke(github.clj:67)
    at hubstats.core$_main$fn__835$state_machine__8696__auto____852$fn__854.invoke(core.clj:60)
    at hubstats.core$_main$fn__835$state_machine__8696__auto____852.invoke(core.clj:59)
    at clojure.core.async.impl.ioc_macros$run_state_machine.invokeStatic(ioc_macros.clj:978)
    at clojure.core.async.impl.ioc_macros$run_state_machine.invoke(ioc_macros.clj:977)
    at clojure.core.async.impl.ioc_macros$run_state_machine_wrapped.invokeStatic(ioc_macros.clj:982)
    at clojure.core.async.impl.ioc_macros$run_state_machine_wrapped.invoke(ioc_macros.clj:980)
    at hubstats.core$_main$fn__835.invoke(core.clj:59)
    at clojure.lang.AFn.run(AFn.java:22)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at clojure.core.async.impl.concurrent$counted_thread_factory$reify__4081$fn__4082.invoke(concurrent.clj:29)
    at clojure.lang.AFn.run(AFn.java:22)
    at java.base/java.lang.Thread.run(Thread.java:834)
nicokosi commented 3 years ago

Native image still works 🎉 :

$ ./generate-executable.sh

$ ./hubstats --organization softwarevidal --repository nemo --token $GITHUB_TOKEN
pull requests for softwarevidal/nemo ->
    since 2021-02-27T16:29:30Z
        5 opened / 4 closed / 1 commented (1 comments)
        opened per author:  {vidal-rm 3, s-petit 1, nicokosi 1}
        comments per author:  {nicokosi 1}
        closed per author:  {nicokosi 4}