mirror of https://github.com/logseq/logseq
Personal token
parent
94851966e9
commit
e7712cf5a7
|
@ -140,7 +140,7 @@
|
|||
(rum/defcc diff < rum/reactive
|
||||
{:will-mount
|
||||
(fn [state]
|
||||
(let [repo (state/get-current-repo)]
|
||||
(when-let [repo (state/get-current-repo)]
|
||||
(handler/get-latest-commit
|
||||
repo
|
||||
(fn [commit]
|
||||
|
|
|
@ -27,11 +27,10 @@
|
|||
:on-click
|
||||
#(handler/set-preferred-format! :org))]])
|
||||
|
||||
(rum/defcs add-repo < rum/reactive
|
||||
(rum/local "" ::repo-url)
|
||||
[state]
|
||||
(let [repo-url (state/sub :git/clone-repo)
|
||||
git-ask-private-grant? (state/sub :git/ask-for-private-repo-grant)]
|
||||
(rum/defc add-repo < rum/reactive
|
||||
[]
|
||||
(let [access-token (state/sub [:me :access-token])
|
||||
repo-url (state/sub :git/clone-repo)]
|
||||
[:div.p-8.flex.items-center.justify-center
|
||||
[:div.w-full.mx-auto
|
||||
[:div
|
||||
|
@ -39,13 +38,24 @@
|
|||
[:h1.title.mb-1
|
||||
"Import your notes"]
|
||||
[:p.text-sm.text-gray-500.pl-1 "You can import your notes from a repo on Github."]
|
||||
[:div.mt-2.mb-2.relative.rounded-md.shadow-sm.max-w-xs
|
||||
[:div.mt-4.mb-2.relative.rounded-md.shadow-sm.max-w-xs
|
||||
[:div.font-bold.text-gray-600.mb-1 "Repo url:"]
|
||||
[:input#repo.form-input.block.w-full.sm:text-sm.sm:leading-5
|
||||
{:autoFocus true
|
||||
:placeholder "https://github.com/username/repo"
|
||||
:value repo-url
|
||||
:on-change (fn [e]
|
||||
(state/set-git-clone-repo! (util/evalue e)))}]]]]
|
||||
(state/set-git-clone-repo! (util/evalue e)))}]]
|
||||
|
||||
[:div.mt-2.mb-2.relative.rounded-md.shadow-sm.max-w-xs
|
||||
[:div.font-bold.text-gray-600.mb-1 "Personal access token (optional):"]
|
||||
[:input#repo.form-input.block.w-full.sm:text-sm.sm:leading-5
|
||||
{:value access-token
|
||||
:on-change (fn [e]
|
||||
(let [value (util/evalue e)]
|
||||
(when-not (string/blank? value)
|
||||
(state/set-github-token! value))))}]]]]
|
||||
|
||||
(ui/button
|
||||
"Clone"
|
||||
:on-click
|
||||
|
@ -54,21 +64,22 @@
|
|||
(handler/clone-and-pull repo-url)
|
||||
(handler/redirect! {:to :home}))))
|
||||
|
||||
(when git-ask-private-grant?
|
||||
[:div
|
||||
[:hr]
|
||||
[:div
|
||||
[:h3.text-red-700.mb-2 "Git clone failed, it might be two reasons:"]
|
||||
[:ol
|
||||
[:li.mb-1 "Please check the repo link is correct."]
|
||||
[:li
|
||||
[:div.mb-1
|
||||
"You're cloning a "
|
||||
[:b "private"]
|
||||
" repo, we need your permission grants for that.
|
||||
We promise that our server will never store your github oauth token, it'll be stored securely and only in the "
|
||||
[:a.underline {:title "Which has a HttpOnly flag"}
|
||||
"browser cookie"]
|
||||
"."]
|
||||
[:a {:href "/auth/github_ask_repo_permission"}
|
||||
(ui/button "Grant us your private repo permission")]]]]])]]))
|
||||
;; (when git-ask-private-grant?
|
||||
;; [:div
|
||||
;; [:hr]
|
||||
;; [:div
|
||||
;; [:h3.text-red-700.mb-2 "Git clone failed, it might be two reasons:"]
|
||||
;; [:ol
|
||||
;; [:li.mb-1 "Please check the repo link is correct."]
|
||||
;; [:li
|
||||
;; [:div.mb-1
|
||||
;; "You're cloning a "
|
||||
;; [:b "private"]
|
||||
;; " repo, we need your permission grants for that.
|
||||
;; We promise that our server will never store your github oauth token, it'll be stored securely and only in the "
|
||||
;; [:a.underline {:title "Which has a HttpOnly flag"}
|
||||
;; "browser cookie"]
|
||||
;; "."]
|
||||
;; [:a {:href "/auth/github_ask_repo_permission"}
|
||||
;; (ui/button "Grant us your private repo permission")]]]]])
|
||||
]]))
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
[promesa.core :as p]))
|
||||
|
||||
(set! (.-fs js/window) (js/LightningFS. "logseq"))
|
||||
(js/git.plugins.set "fs" js/window.fs)
|
||||
(set! (.-pfs js/window) js/window.fs.promises)
|
||||
|
||||
(defn mkdir
|
||||
|
|
|
@ -12,43 +12,33 @@
|
|||
;; TODO: move to a js worker
|
||||
|
||||
(defonce default-branch "master")
|
||||
|
||||
(defn with-fs-http
|
||||
[m]
|
||||
(clojure.core/merge
|
||||
m
|
||||
{:fs js/window.fs
|
||||
:http js/window.GitHttp}))
|
||||
|
||||
;; only support Github now
|
||||
(defn auth
|
||||
[token]
|
||||
{:onAuth (fn [_url]
|
||||
(clj->js
|
||||
{:username token
|
||||
:password "x-oauth-basic"}))})
|
||||
{:username token
|
||||
:password "x-oauth-basic"})
|
||||
|
||||
(defn set-username-email
|
||||
[dir username email]
|
||||
(p/let [_ (js/git.setConfig
|
||||
(clj->js
|
||||
(with-fs-http
|
||||
{:dir dir
|
||||
:path "user.name"
|
||||
:value username})))]
|
||||
(js/git.setConfig
|
||||
(clj->js
|
||||
(with-fs-http
|
||||
{:dir dir
|
||||
:path "user.email"
|
||||
:value email})))))
|
||||
(util/p-handle (js/git.config (clj->js
|
||||
{:global true
|
||||
:dir dir
|
||||
:path "user.name"
|
||||
:value username}))
|
||||
(fn [result]
|
||||
(js/git.config (clj->js
|
||||
{:global true
|
||||
:dir dir
|
||||
:path "user.email"
|
||||
:value email})))
|
||||
(fn [error]
|
||||
(prn "error:" error))))
|
||||
|
||||
(defn with-auth
|
||||
[token m]
|
||||
(clj->js
|
||||
(clojure.core/merge
|
||||
m
|
||||
(auth token))))
|
||||
(clojure.core/merge (auth token)
|
||||
m)))
|
||||
|
||||
(defn get-repo-dir
|
||||
[repo-url]
|
||||
|
@ -56,102 +46,87 @@
|
|||
|
||||
(defn clone
|
||||
[repo-url token]
|
||||
(let [m (with-fs-http
|
||||
{:dir (get-repo-dir repo-url)
|
||||
:url repo-url
|
||||
:corsProxy "https://cors.isomorphic-git.org"
|
||||
:ref default-branch
|
||||
:singleBranch true
|
||||
:username (get-in @state/state [:me :name] "logseq-demo")
|
||||
:depth 1})]
|
||||
(js/git.clone (if token
|
||||
(with-auth token m)
|
||||
(clj->js m)))))
|
||||
(js/git.clone (with-auth token
|
||||
{:dir (get-repo-dir repo-url)
|
||||
:url repo-url
|
||||
:corsProxy "https://cors.isomorphic-git.org"
|
||||
:singleBranch true
|
||||
:depth 1})))
|
||||
|
||||
(defn list-files
|
||||
[repo-url]
|
||||
(js/git.listFiles (clj->js
|
||||
(with-fs-http
|
||||
{:dir (get-repo-dir repo-url)
|
||||
:ref "HEAD"}))))
|
||||
{:dir (get-repo-dir repo-url)
|
||||
:ref "HEAD"})))
|
||||
|
||||
(defn fetch
|
||||
[repo-url token]
|
||||
(js/git.fetch (with-auth token
|
||||
(with-fs-http
|
||||
{:dir (get-repo-dir repo-url)
|
||||
:ref default-branch
|
||||
:singleBranch true
|
||||
:depth 100
|
||||
:tags false}))))
|
||||
{:dir (get-repo-dir repo-url)
|
||||
:ref default-branch
|
||||
:singleBranch true
|
||||
:depth 100
|
||||
:tags false})))
|
||||
|
||||
(defn merge
|
||||
[repo-url]
|
||||
(js/git.merge (clj->js
|
||||
(with-fs-http
|
||||
{:dir (get-repo-dir repo-url)
|
||||
:ours default-branch
|
||||
:theirs (str "remotes/origin/" default-branch)
|
||||
:fastForwardOnly true}))))
|
||||
{:dir (get-repo-dir repo-url)
|
||||
:ours default-branch
|
||||
:theirs (str "remotes/origin/" default-branch)
|
||||
:fastForwardOnly true})))
|
||||
|
||||
(defn checkout
|
||||
[repo-url]
|
||||
(js/git.checkout (clj->js
|
||||
(with-fs-http
|
||||
{:dir (get-repo-dir repo-url)
|
||||
:ref default-branch}))))
|
||||
{:dir (get-repo-dir repo-url)
|
||||
:ref default-branch})))
|
||||
|
||||
(defn log
|
||||
[repo-url token depth]
|
||||
(js/git.log (with-auth token
|
||||
(with-fs-http
|
||||
{:dir (get-repo-dir repo-url)
|
||||
:ref default-branch
|
||||
:depth depth
|
||||
:singleBranch true}))))
|
||||
{:dir (get-repo-dir repo-url)
|
||||
:ref default-branch
|
||||
:depth depth
|
||||
:singleBranch true})))
|
||||
|
||||
(defn pull
|
||||
[repo-url token]
|
||||
(js/git.pull (with-auth token
|
||||
(with-fs-http
|
||||
{:dir (get-repo-dir repo-url)
|
||||
:ref default-branch
|
||||
:singleBranch true
|
||||
:fast true}))))
|
||||
{:dir (get-repo-dir repo-url)
|
||||
:ref default-branch
|
||||
:singleBranch true
|
||||
:fast true})))
|
||||
(defn add
|
||||
[repo-url file]
|
||||
(js/git.add (clj->js
|
||||
(with-fs-http
|
||||
{:dir (get-repo-dir repo-url)
|
||||
:filepath file}))))
|
||||
{:dir (get-repo-dir repo-url)
|
||||
:filepath file})))
|
||||
|
||||
(defn commit
|
||||
[repo-url message]
|
||||
(let [{:keys [name email]} (:me @state/state)]
|
||||
(js/git.commit (clj->js
|
||||
(with-fs-http
|
||||
{:dir (get-repo-dir repo-url)
|
||||
:message message
|
||||
:author {:name name
|
||||
:email email}})))))
|
||||
{:dir (get-repo-dir repo-url)
|
||||
:message message
|
||||
:author {:name name
|
||||
:email email}}))))
|
||||
|
||||
(defn read-commit
|
||||
[repo-url oid]
|
||||
(js/git.readCommit (clj->js
|
||||
(with-fs-http
|
||||
{:dir (get-repo-dir repo-url)
|
||||
:oid oid}))))
|
||||
{:dir (get-repo-dir repo-url)
|
||||
:oid oid})))
|
||||
|
||||
(defn push
|
||||
([repo-url token]
|
||||
(push repo-url token false))
|
||||
([repo-url token force?]
|
||||
(js/git.push (with-auth token
|
||||
(with-fs-http
|
||||
{:dir (get-repo-dir repo-url)
|
||||
:remote "origin"
|
||||
:ref default-branch
|
||||
:force force?})))))
|
||||
{:dir (get-repo-dir repo-url)
|
||||
:remote "origin"
|
||||
:ref default-branch
|
||||
:force force?}))))
|
||||
|
||||
(defn add-commit
|
||||
[repo-url file message commit-ok-handler commit-error-handler]
|
||||
|
@ -183,9 +158,8 @@
|
|||
([repo-url branch]
|
||||
(p/let [matrix (js/git.statusMatrix
|
||||
(clj->js
|
||||
(with-fs-http
|
||||
{:dir (get-repo-dir repo-url)
|
||||
:ref "HEAD"})))]
|
||||
{:dir (get-repo-dir repo-url)
|
||||
:ref "HEAD"}))]
|
||||
(let [matrix (bean/->clj matrix)]
|
||||
;; added, modified, deleted
|
||||
{:added (->> (filter (fn [[_file head-status _workdir-status _stage-status]]
|
||||
|
@ -227,11 +201,10 @@
|
|||
(defn read-blob
|
||||
[repo-url oid path]
|
||||
(js/git.readBlob (clj->js
|
||||
(with-fs-http
|
||||
{:dir (get-repo-dir repo-url)
|
||||
:gitdir (str (get-repo-dir repo-url) ".git")
|
||||
:oid oid
|
||||
:path path}))))
|
||||
{:dir (get-repo-dir repo-url)
|
||||
:gitdir (str (get-repo-dir repo-url) ".git")
|
||||
:oid oid
|
||||
:path path})))
|
||||
|
||||
;; * await git.writeRef({
|
||||
;; * fs,
|
||||
|
@ -242,8 +215,7 @@
|
|||
(defn write-ref!
|
||||
[repo-url oid]
|
||||
(js/git.writeRef (clj->js
|
||||
(with-fs-http
|
||||
{:dir (get-repo-dir repo-url)
|
||||
:ref (str "refs/heads/" default-branch)
|
||||
:value oid
|
||||
:force true}))))
|
||||
{:dir (get-repo-dir repo-url)
|
||||
:ref (str "refs/heads/" default-branch)
|
||||
:value oid
|
||||
:force true})))
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
// move to cljs
|
||||
// copied from https://github.com/kpj/GitViz/blob/83dfc65624f5dae41ffb9e8a97d2ee61512c1365/src/git-handler.js
|
||||
export var getFileStateChanges = async function (commitHash1, commitHash2, dir) {
|
||||
return git.walk({
|
||||
return git.walkBeta1({
|
||||
trees: [
|
||||
git.TREE({ dir: dir, ref: commitHash1 }),
|
||||
git.TREE({ dir: dir, ref: commitHash2 })
|
||||
|
|
|
@ -484,11 +484,11 @@
|
|||
(defn periodically-pull-and-push
|
||||
[repo-url {:keys [pull-now?]
|
||||
:or {pull-now? true}}]
|
||||
;; (periodically-pull repo-url pull-now?)
|
||||
;; (periodically-push-tasks repo-url)
|
||||
(when-not config/dev?
|
||||
(periodically-pull repo-url pull-now?)
|
||||
(periodically-push-tasks repo-url))
|
||||
(periodically-pull repo-url pull-now?)
|
||||
(periodically-push-tasks repo-url)
|
||||
;; (when-not config/dev?
|
||||
;; (periodically-pull repo-url pull-now?)
|
||||
;; (periodically-push-tasks repo-url))
|
||||
)
|
||||
|
||||
(defn render-local-images!
|
||||
|
|
|
@ -241,3 +241,7 @@
|
|||
(defn logged?
|
||||
[]
|
||||
(get-in @state [:me :email]))
|
||||
|
||||
(defn set-github-token!
|
||||
[token]
|
||||
(swap! state assoc-in [:me :access-token] token))
|
||||
|
|
Loading…
Reference in New Issue