first pass at trying to post issue comments from github accountwith 2FA enabled

This commit is contained in:
Rob Culliton 2018-04-11 21:23:59 -04:00
parent d98b26a16c
commit 50083db6ea
2 changed files with 10 additions and 4 deletions

View File

@ -78,6 +78,8 @@ github-client-id | Related to OAuth. Copied from GitHub account Settings->Develo
github-client-secret | Related to OAuth. Copied from GitHub account Settings->Developer settings->OAuth Apps github-client-secret | Related to OAuth. Copied from GitHub account Settings->Developer settings->OAuth Apps
github-user | GitHub username for bot account. It is used for posting bounty comments github-user | GitHub username for bot account. It is used for posting bounty comments
github-password | GitHub password for bot account github-password | GitHub password for bot account
github-token | GitHub token for bot account. (see
https://help.github.com/articles/creating-a-personal-access-token-for-the-command-line/ for details)
webhook-secret | Secret string to be used when creating a GitHub App webhook-secret | Secret string to be used when creating a GitHub App
user-whitelist | Set of GitHub user/org IDs to be whitelisted. E.g. `#{"status-im" "your_org"}` user-whitelist | Set of GitHub user/org IDs to be whitelisted. E.g. `#{"status-im" "your_org"}`
testnet-token-data | Token data map, useful if there are Geth connectivity problems testnet-token-data | Token data map, useful if there are Geth connectivity problems

View File

@ -25,6 +25,7 @@
(defn hook-secret [] (:github-hook-secret env)) (defn hook-secret [] (:github-hook-secret env))
(defn self [] (:github-user env)) (defn self [] (:github-user env))
(defn self-password [] (:github-password env)) (defn self-password [] (:github-password env))
(defn self-token [] (:github-token env))
(defn on-testnet? [] (env :on-testnet)) (defn on-testnet? [] (env :on-testnet))
(defn webhook-secret [] (env :webhook-secret)) (defn webhook-secret [] (env :webhook-secret))
@ -279,14 +280,15 @@
(issues/create-comment owner repo issue-number comment (self-auth-params)))) (issues/create-comment owner repo issue-number comment (self-auth-params))))
(defn make-patch-request [end-point positional query] (defn make-patch-request [end-point positional query]
(let [{:keys [auth oauth-token] (let [{:keys [auth oauth-token x-github-otp]
:as query} query :as query} query
req (merge-with merge req (merge-with merge
{:url (tentacles/format-url end-point positional) {:url (tentacles/format-url end-point positional)
:basic-auth auth :basic-auth auth
:method :patch} :method :patch}
(when oauth-token (when (or oauth-token x-github-otp)
{:headers {"Authorization" (str "token " oauth-token)}})) {:headers {"Authorization" (str "token " oauth-token)
"X-GitHub-OTP" x-github-otp}}))
raw-query (:raw query) raw-query (:raw query)
proper-query (tentacles/query-map (dissoc query :auth proper-query (tentacles/query-map (dissoc query :auth
:oauth-token :oauth-token
@ -310,7 +312,9 @@
" comment #" comment-id " with contents: " comment)) " comment #" comment-id " with contents: " comment))
(let [req (make-patch-request "repos/%s/%s/issues/comments/%s" (let [req (make-patch-request "repos/%s/%s/issues/comments/%s"
[owner repo comment-id] [owner repo comment-id]
(assoc (self-auth-params) :body comment))] (assoc (self-auth-params)
:body comment
:x-github-otp (self-token)))]
(tentacles/safe-parse (http/request req))))) (tentacles/safe-parse (http/request req)))))