Skip to content

Commit

Permalink
Update github with comment method
Browse files Browse the repository at this point in the history
  • Loading branch information
FieryCod committed Dec 27, 2018
1 parent 3ceaae8 commit b174c63
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
4 changes: 2 additions & 2 deletions project.clj
@@ -1,4 +1,4 @@
(defproject codcheck "0.0.1"
(defproject codcheck "0.0.2"

:description "Core/Common code of the codcheck platform"
:url "https://github.com/FieryCod/codcheck"
Expand All @@ -8,7 +8,7 @@

:global-vars {*warn-on-reflection* true}

:dependencies [[org.clojure/clojure "1.10.0-beta8"]
:dependencies [[org.clojure/clojure "1.10.0"]
[com.taoensso/timbre "4.10.0"]
[org.clojure/core.async "0.4.474"]
[clj-time "0.14.4"]
Expand Down
24 changes: 23 additions & 1 deletion src/codcheck/github.clj
@@ -1,7 +1,29 @@
(ns codcheck.github)
(ns codcheck.github
(:require
[cheshire.core :as cheshire]
[clj-http.client :as http]))

(def api-url "https://api.github.com/")

(defn installation-token-url
[installation-id]
(str api-url "app/installations/" installation-id "/access_tokens"))

(defn comment-pr-url
[repo-owner repo-name pr-number]
(str api-url "repos/" repo-owner "/" repo-name "/issues/" pr-number "/comments"))

(defn comment-on-pr
([installation-token repo-owner repo-name pr-number comment-message]
(comment-on-pr installation-token repo-owner repo-name pr-number comment-message false))

([installation-token repo-owner repo-name pr-number comment-message async?]
(let [comment-url (comment-pr-url repo-owner repo-name pr-number)
headers {:authorization (str "token " installation-token)}
opts {:headers headers
:async? async?
:accept "application/vnd.github.machine-man-preview+json"
:body (cheshire/encode {:body comment-message})}]
(http/post comment-url opts))))

;; (comment (comment-on-pr "some-token" "FieryCod" "codcheck-lint-demo" 1 "a-message"))
11 changes: 7 additions & 4 deletions src/codcheck/rmq.clj
Expand Up @@ -5,13 +5,16 @@
[codcheck.envs :refer [envs]]))

(def exchanges
{:gh-pr-code-check "gh_pr_code_check_ex"})
{:pr-code-check "pr_code_check_ex"
:pr-code-checked "pr_code_checked_ex"})

(def queues
{:gh-pr-code-check "gh_pr_code_check_q"})
{:pr-code-check "pr_code_check_q"
:pr-code-checked "pr_code_checked_q"})

(def routing-keys
{:gh-pr-code-check ""})
{:pr-code-check ""
:pr-code-checked ""})

(def conn (atom nil))

Expand All @@ -28,6 +31,6 @@
(defn open-chan!
[]
(when (nil? @conn)
(throw (Exception. "Connection does not exists")))
(throw (Exception. "Connection for RabbitMQ does not exists. @Codcheck")))
(when (nil? @chan)
(reset! chan (langohr-chan/open @conn))))

0 comments on commit b174c63

Please sign in to comment.