Skip to content

Instantly share code, notes, and snippets.

@souenzzo
Created November 20, 2019 20:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save souenzzo/f82c572666d6126cb6873e1f0ba43b76 to your computer and use it in GitHub Desktop.
Save souenzzo/f82c572666d6126cb6873e1f0ba43b76 to your computer and use it in GitHub Desktop.
Run with "clj -A:dev -m user.pr" or "clj -A:pr"
(ns user.pr
(:require [cognitect.aws.client.api :as aws]
[clj-http.client :as http]
[clojure.java.io :as io])
(:import (org.eclipse.jgit.api Git)))
(defn slack->request
[text]
{:method :post
:url "https://hooks.slack.com/services/XX/YY/ZZ"
:content-type :json
:form-params {:text text}})
(defn -main
[& _]
(let [f (io/file ".")
branch (-> f
Git/open
.getRepository
.getBranch)
repository-name (-> f .getCanonicalFile .getName)
codecommit (aws/client {:api :codecommit})
{:keys [pullRequestId]} (-> (aws/invoke codecommit {:op :CreatePullRequest
:request {:title branch
:targets [{:repositoryName repository-name
:sourceReference branch}]}})
:pullRequest)]
(-> (str "Novo PR:"
"https://console.aws.amazon.com/codesuite/codecommit/repositories/"
repository-name
"/pull-requests/"
pullRequestId
"/changes?region=us-east-1")
slack->request
http/request
:body
prn)
(System/exit 0)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment