From 50083db6ea07c27d8c192c36a2ac95e819587e69 Mon Sep 17 00:00:00 2001 From: Rob Culliton Date: Wed, 11 Apr 2018 21:23:59 -0400 Subject: [PATCH] first pass at trying to post issue comments from github accountwith 2FA enabled --- README.md | 2 ++ src/clj/commiteth/github/core.clj | 12 ++++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index ced4f88..ef7151b 100644 --- a/README.md +++ b/README.md @@ -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-user | GitHub username for bot account. It is used for posting bounty comments 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 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 diff --git a/src/clj/commiteth/github/core.clj b/src/clj/commiteth/github/core.clj index e51ce95..f49b5c8 100644 --- a/src/clj/commiteth/github/core.clj +++ b/src/clj/commiteth/github/core.clj @@ -25,6 +25,7 @@ (defn hook-secret [] (:github-hook-secret env)) (defn self [] (:github-user env)) (defn self-password [] (:github-password env)) +(defn self-token [] (:github-token env)) (defn on-testnet? [] (env :on-testnet)) (defn webhook-secret [] (env :webhook-secret)) @@ -279,14 +280,15 @@ (issues/create-comment owner repo issue-number comment (self-auth-params)))) (defn make-patch-request [end-point positional query] - (let [{:keys [auth oauth-token] + (let [{:keys [auth oauth-token x-github-otp] :as query} query req (merge-with merge {:url (tentacles/format-url end-point positional) :basic-auth auth :method :patch} - (when oauth-token - {:headers {"Authorization" (str "token " oauth-token)}})) + (when (or oauth-token x-github-otp) + {:headers {"Authorization" (str "token " oauth-token) + "X-GitHub-OTP" x-github-otp}})) raw-query (:raw query) proper-query (tentacles/query-map (dissoc query :auth :oauth-token @@ -310,7 +312,9 @@ " comment #" comment-id " with contents: " comment)) (let [req (make-patch-request "repos/%s/%s/issues/comments/%s" [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)))))