Created
November 8, 2017 06:41
-
-
Save tatut/900d62d244d18ca363ef7fefc19afb1a to your computer and use it in GitHub Desktop.
Script for Bitbar (getbitbar.com) to your current work items
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/local/bin/planck | |
(ns pivotal.core | |
(:require [planck.http :as http] | |
[planck.core :refer [spit slurp]] | |
[planck.shell :as sh] | |
[clojure.walk :as walk] | |
[clojure.string :as str])) | |
;; Config section | |
(def pivotal-token "your token here") | |
(def me "your username") | |
(def project "project id") | |
(def pivotal-api-url "https://www.pivotaltracker.com/services/v5/") | |
;; Code | |
(defn keywordize-keys [m] | |
(if (map? m) | |
(reduce-kv (fn [m k v] | |
(assoc m | |
(-> k | |
(str/replace #"_" "-") | |
keyword) | |
v)) | |
{} m) | |
m)) | |
(defn get-pivotal-uri [& path] | |
(let [response (http/get (str pivotal-api-url (str/join "" path)) {:headers {"X-TrackerToken" pivotal-token}})] | |
(try | |
(->> response :body js/JSON.parse js->clj (walk/postwalk keywordize-keys)) | |
(catch :default e | |
(println "Call failed: " (str e)))))) | |
(defn fetch-stories [filter] | |
(get-pivotal-uri "projects/" project "/stories?filter=" (js/encodeURIComponent filter))) | |
(def stories (fetch-stories (str "owner:" me " -state:accepted -state:delivered"))) | |
(count stories) "assigned\n---\n" | |
(str/join "\n" | |
(for [{:keys [id name url current-state] :as story} stories] | |
(str "[#" id "] " name " (" current-state ")| href=" url)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment