Skip to content

Commit

Permalink
fixes #2
Browse files Browse the repository at this point in the history
- figures out org/user name from remote origin url
- [refactor] collapses commit-url and compare-url
- releases jar
  • Loading branch information
Benedek Fazekas committed Jan 6, 2015
1 parent 7235a4f commit 107d3cc
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 17 deletions.
Binary file modified bin/gargamel.jar
Binary file not shown.
31 changes: 22 additions & 9 deletions src/gargamel/git.clj
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
(ns gargamel.git
(:require [clojure.java.shell :as sh]
[gargamel.util :as util]))
[gargamel.util :as util]
[clojure.string :as str]))

(defn changelog [from to dir]
(:out (sh/sh "git" "log" "--date=short" "--format=%h%;%cN;%d;%ad;%s;%b;" (format "%s..%s" from to) :dir dir)))
Expand All @@ -21,14 +22,26 @@

(def remote-url (memoize remote-url*))

(defn org-or-username
"figures out organisation or gitusername based on remote origin url"
[rurl]
(let [https-prefix "https://"
url (if (.startsWith rurl https-prefix)
(str/replace rurl (re-pattern https-prefix) "")
rurl)]
(-> url
(str/split #"[:/]")
second)))

(defn c-url [source-dir project-name bb-url gh-url & args]
(let [project-name (real-project-name project-name)
r-url (remote-url source-dir)
org-name (org-or-username r-url)
url (if (re-find #"bitbucket" r-url) bb-url gh-url)]
(apply (partial format url org-name project-name) args)))

(defn commit-url [source-dir project-name hash]
(let [project-name (real-project-name project-name)]
(if (re-find #"bitbucket" (remote-url source-dir) )
(format "https://bitbucket.org/MailOnline/%s/commits/%s" project-name hash)
(format "https://github.com/MailOnline/%s/commit/%s" project-name hash))))
(c-url source-dir project-name "https://bitbucket.org/%s/%s/commits/%s" "https://github.com/%s/%s/commit/%s" hash))

(defn compare-url [source-dir project-name from to]
(let [project-name (real-project-name project-name)]
(if (re-find #"bitbucket" (remote-url source-dir))
(format "https://bitbucket.org/MailOnline/%s/branches/compare/%s..%s" project-name from to)
(format "http://github.com/MailOnline/%s/compare/%s...%s" project-name from to))))
(c-url source-dir project-name "https://bitbucket.org/%s/%s/branches/compare/%s..%s" "http://github.com/%s/%s/compare/%s...%s" from to))
17 changes: 9 additions & 8 deletions src/leiningen/gargamel.clj
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

(def ^:dynamic target-path nil)

(defn- github-issue-link [proj-name]
(format "<a href=\"https://github.com/MailOnline/%s/issues/$1\"> #$1</a>" proj-name))
(defn- github-issue-link [org-name proj-name]
(format "<a href=\"https://github.com/%s/%s/issues/$1\"> #$1</a>" org-name proj-name))

(def ^:private github-issue-link-external "<a href=\"https://github.com/$2/issues/$3\">$2: $3</a>")

Expand Down Expand Up @@ -64,10 +64,11 @@
:compare-url (git/compare-url source-dir proj-name from to)}
from-params to-params))))

(defn issues->links [commit]
(let [i->l (fn [t] (-> t
(defn issues->links [source-dir commit]
(let [org-name (git/org-or-username (git/remote-url source-dir))
i->l (fn [t] (-> t
(str/replace github-external-issue-regexp github-issue-link-external)
(str/replace github-issue-regexp (github-issue-link proj-name))
(str/replace github-issue-regexp (github-issue-link org-name proj-name))
(str/replace jira-issue-regex jira-issue-link)))
subject (-> commit
:subject
Expand Down Expand Up @@ -103,9 +104,9 @@
(sort-by #(.indexOf (keys titles) (first %)))
(into (array-map))))

(defn enrich-changelog [log]
(defn enrich-changelog [log source-dir]
(->> log
(map issues->links)
(map (partial issues->links source-dir))
(group-by create-section)
section-titles))

Expand All @@ -122,7 +123,7 @@
target-path path]
(let [proj-dir (or project-dir ".")]
(println (format "Generating changelog for project %s between %s and %s" project-name from to))
(create-html-changelog (enrich-changelog (changelog from to {:name project-name :dir proj-dir}))
(create-html-changelog (enrich-changelog (changelog from to {:name project-name :dir proj-dir}) proj-dir)
from to proj-dir))))

(defn gargamel
Expand Down

0 comments on commit 107d3cc

Please sign in to comment.