|
|
@@ -8,7 +8,9 @@
|
|
|
[goog.dom :as gdom]
|
|
|
[dommy.core :as dom]
|
|
|
[cljs.core.async :as async]
|
|
|
- [lambdaisland.glogi :as log]))
|
|
|
+ [lambdaisland.glogi :as log]
|
|
|
+ [cljs-time.core :as t]
|
|
|
+ [cljs-time.format :as tf]))
|
|
|
|
|
|
(defonce ^:private state
|
|
|
(atom
|
|
|
@@ -513,9 +515,15 @@
|
|
|
(when (seq repos)
|
|
|
(let [set-token-f
|
|
|
(fn [{:keys [installation_id] :as repo}]
|
|
|
- (let [{:keys [token expires_at] :as m} (get tokens installation_id)]
|
|
|
- (if (and token expires_at)
|
|
|
- (merge repo {:token token :expires_at expires_at})
|
|
|
+ (let [{:keys [token] :as m} (get tokens installation_id)]
|
|
|
+ (if (string? token)
|
|
|
+ ;; Github API returns a expires_at key which is a timestamp (expires after 60 minutes at present),
|
|
|
+ ;; however, user's system time may be inaccurate. Here, based on the client system time, we use
|
|
|
+ ;; 60-minutes duration directly.
|
|
|
+ (let [formatter (tf/formatters :date-time-no-ms)
|
|
|
+ expires-at (->> (t/plus (t/now) (t/minutes 60))
|
|
|
+ (tf/unparse formatter))]
|
|
|
+ (merge repo {:token token :expires_at expires-at}))
|
|
|
(do (log/error :token/cannot-set-token {:repo-m repo :token-m m}) repo))))
|
|
|
repos (mapv set-token-f repos)]
|
|
|
(swap! state assoc-in [:me :repos] repos))))))
|