Skip to content

Instantly share code, notes, and snippets.

@souenzzo

souenzzo/pr.clj

Created Nov 20, 2019
Embed
What would you like to do?
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
You can’t perform that action at this time.