Skip to content
Mathieu Gauthron edited this page Aug 6, 2013 · 1 revision

(ns jiraextraction.core (:use [clojure.string :only (split triml trim trim-newline)]) ) (require '[clojure.data.json :as json]) (require '[clj-http.lite.client :as client])

(defn retrieve-jira [jira] ;;(println "retrieving:" jira) (client/get (str "http://unity.apps.csintra.net/jira/rest/api/2/issue/" jira) {:basic-auth ["myuser" "mypassword"]}))

(def retrieve-jira-memoized (memoize retrieve-jira))

(defn retrieve-jira-msg [jira] (let [body (json/read-str (:body (retrieve-jira-memoized jira)))] (-> body (get "fields") (get "summary")))) (defn retrieve-jira-status [jira] (let [body (json/read-str (:body (retrieve-jira-memoized jira)))] (-> body (get "fields") (get "status") (get "name"))))

(defn retrieve-jira-components [jira] (let [body (json/read-str (:body (retrieve-jira-memoized jira))) components (-> body (get "fields") (get "components"))] (apply str (interpose "," (map #(get % "name") components))))) ;; (-> (json/read-str (:body (retrieve-jira-memoized "SRPDEV-1330"))) (get "fields") (get "status") (get "name"))

(defn write-file "Writes a value to a file" [value out-file] (spit out-file "" :append false) (with-open [out-data (clojure.java.io/writer out-file)] (.write out-data (str value))))

(defn read-file [in-file] (with-open [rdr (clojure.java.io/reader in-file)] (reduce conj [] (line-seq rdr))))

(defn perl-split [s] (split (triml s) #"\s+"))

;;(defn log-split-alt [line] ;; (map (comp triml trim-newline) (rest (re-find #"(MATDEV-\d+)\s+(.*)" line))))

(defn log-split [line] (let [[jira & msg] (split (trim line) #"\s+") jira-found? #(re-find #"MATDEV-\d+" %) jira-found (jira-found? jira) msg (trim (apply str (map #(apply str % " ") msg))) msg2 (if jira-found msg line)] [jira-found msg2]))

(defn parse-log-debug [log] [(nth (map log-split log) 14)])

(defn parse-log [log] (map log-split log))

(defn substitute-jira-in-log-line jira msg ;;(println "substitute-jira-in-log-line:" jira) {:jira jira :title (retrieve-jira-msg jira) :msg msg :status (retrieve-jira-status jira) :components (retrieve-jira-components jira)})

(defn substitute-jira [parsed-log] (map substitute-jira-in-log-line parsed-log))

(defn export-csv [log] (->> log parse-log substitute-jira (map #(str (:jira %) "\t" (:status %) "\t" (:components %) "\t" (:title %) "\t" (:msg %) "\n")) (apply str)))

(defn -main "I don't do a whole lot." [] (println "starting!\n") (println (export-csv (read-file "svnlog.txt"))))


MATDEV-1144 - Enable foo proc monitoring for bar MATDEV-1145 - improve runtime verify. MATDEV-1145 - improve runtime verify. MATDEV-1144 - Enable foo proc monitoring for bar MATDEV-1135 - Monitoring Server for foo Systems MATDEV-1135 - Monitoring Server for foo Systems


(def body {"issuelinks" [{"id" "175801", "self" "http://jirahost/jira/rest/api/2/issueLink/175801", "type" {"id" "10001", "name" "Reference", "inward" "is referenced by", "outward" "references", "self" "http://jirahost/jira/rest/api/2/issueLinkType/10001"}, "outwardIssue" {"id" "485843", "key" "MATDEV-119", "self" "http://jirahost/jira/rest/api/2/issue/485843", "fields" {"summary" "NettyPublisher should allow multiple publishers on same port", "status" {"self" "http://jirahost/jira/rest/api/2/status/1", "description" "The issue is open and ready for the assignee to start work on it.", "iconUrl" "http://jirahost/jira/images/icons/statuses/open.png", "name" "Open", "id" "1"}, "priority" {"self" "http://jirahost/jira/rest/api/2/priority/4", "iconUrl" "http://jirahost/jira/images/icons/priorities/minor.png", "name" "Minor", "id" "4"}, "issuetype" {"self" "http://jirahost/jira/rest/api/2/issuetype/15", "id" "15", "description" "The sub-task of the issue", "iconUrl" "http://jirahost/jira/images/icons/issuetypes/subtask_alternate.png", "name" "Sub-task", "subtask" true}}}}], "customfield_11611" nil, "customfield_16903" nil, "reporter" {"self" "http://jirahost/jira/rest/api/2/user?username=bob1", "name" "bob1", "emailAddress" "bob@host.com", "avatarUrls" {"16x16" "http://jirahost/jira/secure/useravatar?size=small&userId=bob1&avatarId=10422", "48x48" "http://jirahost/jira/secure/useravatar?userId=bob1&avatarId=10422"}, "displayName" "Bob Dylan", "active" true}, "timespent" nil, "customfield_10359" nil, "customfield_16904" nil, "duedate" nil, "aggregatetimespent" nil, "customfield_16905" nil, "attachment" [], "customfield_16906" nil, "timetracking" {}, "priority" {"self" "http://jirahost/jira/rest/api/2/priority/4", "iconUrl" "http://jirahost/jira/images/icons/priorities/minor.png", "name" "Minor", "id" "4"}, "customfield_10625" nil, "customfield_11428" nil, "customfield_16907" nil, "aggregatetimeoriginalestimate" nil, "timeoriginalestimate" nil, "summary" "Add multiplexing to the RDA comm layer", "created" "2013-07-05T14:50:38.000+0100", "votes" {"self" "http://jirahost/jira/rest/api/2/issue/MATDEV-1120/votes", "votes" 0, "hasVoted" false}, "resolution" nil, "aggregateprogress" {"progress" 0, "total" 0}, "progress" {"progress" 0, "total" 0}, "subtasks" [], "assignee" {"self" "http://jirahost/jira/rest/api/2/user?username=bob1", "name" "bob1", "emailAddress" "bob@host.com", "avatarUrls" {"16x16" "http://jirahost/jira/secure/useravatar?size=small&userId=bob1&avatarId=10422", "48x48" "http://jirahost/jira/secure/useravatar?userId=bob1&avatarId=10422"}, "displayName" "Bob Dylan", "active" true}, "customfield_16390" nil, "fixVersions" [], "customfield_16490" "497183", "customfield_16491" "336411", "customfield_12290" "192482", "customfield_11080" nil, "customfield_16492" nil, "status" {"self" "http://jirahost/jira/rest/api/2/status/1", "description" "The issue is open and ready for the assignee to start work on it.", "iconUrl" "http://jirahost/jira/images/icons/statuses/open.png", "name" "Open", "id" "1"}, "environment" nil, "customfield_16493" nil, "worklog" {"startAt" 0, "maxResults" 0, "total" 0, "worklogs" []}, "issuetype" {"self" "http://jirahost/jira/rest/api/2/issuetype/141", "id" "141", "description" "", "iconUrl" "http://jirahost/jira/images/icons/issuetypes/newfeature.png", "name" "Enhancement", "subtask" false}, "customfield_16890" nil, "aggregatetimeestimate" nil, "customfield_11061" "", "customfield_16891" nil, "timeestimate" nil, "customfield_10171" nil, "customfield_16991" nil, "customfield_11062" "", "customfield_11073" nil, "customfield_16892" nil, "components" [{"self" "http://jirahost/jira/rest/api/2/component/26248", "id" "26248", "name" "RDA", "description" "Realtime Distributed Aggregation"}], "customfield_16893" nil, "customfield_16993" nil, "customfield_16894" nil, "customfield_16895" nil, "project" {"self" "http://jirahost/jira/rest/api/2/project/MATDEV", "id" "16762", "key" "MATDEV", "name" "MATDEV", "avatarUrls" {"16x16" "http://jirahost/jira/secure/projectavatar?size=small&pid=16762&avatarId=10011", "48x48" "http://jirahost/jira/secure/projectavatar?pid=16762&avatarId=10011"}}, "customfield_10790" nil, "lastViewed" nil, "resolutiondate" nil, "workratio" -1, "customfield_11660" nil, "updated" "2013-07-05T15:03:22.000+0100", "versions" [], "description" "Currently, there is a foo in our comm layer. This is inefficient and also introduces a significant startup delay (especially with something like SSL on each one of those sockets, which makes it unacceptable).\r\n\r\nWe need to change our comm layer.", "watches" {"self" "http://jirahost/jira/rest/api/2/issue/MATDEV-1120/watchers", "watchCount" 2, "isWatching" false}, "customfield_16900" nil, "customfield_11620" nil, "customfield_16901" nil, "comment" {"startAt" 0, "maxResults" 0, "total" 0, "comments" []}, "customfield_11610" nil, "labels" []} )

Clone this wiki locally