Skip to content

Commit

Permalink
fixes #4
Browse files Browse the repository at this point in the history
- [refactor] uses more concise data structure for sections generation
- gargamel expects gargamel.edn config file in project root
- if :sections is not found in edn file sections-defaults is used
- sections closer to the top in the generated html have precedence
- later a section is defined in :sections in config the higher
  precedence it has tho
  • Loading branch information
Benedek Fazekas committed Jan 6, 2015
1 parent 7566f41 commit 8b9092d
Show file tree
Hide file tree
Showing 4 changed files with 327 additions and 35 deletions.
Binary file modified bin/gargamel.jar
Binary file not shown.
66 changes: 31 additions & 35 deletions src/leiningen/gargamel.clj
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
(ns leiningen.gargamel
(:require [clojure.string :as str]
[gargamel.git :as git]
[stencil.core :as st])
[stencil.core :as st]
[clojure.java.io :as io]
[clojure.edn :as edn])
(:import java.io.File))

(def ^:dynamic proj-name nil)
Expand All @@ -25,11 +27,15 @@

(def ^:private jira-issue-regex (re-pattern jira-issue-regex-string))

(def ^:private title-keys [:other :refactor :technical :business])
(def ^:private sections-defaults
[{:key :refactor :regex ".*refactor.*" :title "Refactorings, improvements"}
{:key :technical :regex ".*#(\\d+).*" :title "Internal changes"}
{:key :business :regex ".*(MOL-\\d+).*" :title "Business related changes"}])

(def ^:private title-vals ["Other changes" "Refactorings, improvements" "Internal changes" "Business related changes"])

(def ^:private titles (zipmap title-keys title-vals))
(def project-config
(let [proj-config-name "gargamel.edn"]
(when (.exists (io/file proj-config-name))
(edn/read-string (slurp proj-config-name)))))

(defn changelog [from to project]
{:pre [from]}
Expand Down Expand Up @@ -76,39 +82,29 @@
body (-> commit :body i->l)]
(assoc commit :linked-body (str/replace body #"\n" "<br/>") :linked-subject subject)))

(defn- create-section [commit]
(defn- create-section [sections-config commit]
(let [subject (:subject commit)
body (:body commit)
jira-pattern (re-pattern (format ".*%s.*" jira-issue-regex-string))
github-pattern (re-pattern (format ".*%s.*" github-issue-regexp-string))
refactor-pattern #".*refactor.*"]
(cond (or (re-matches jira-pattern subject)
(re-matches jira-pattern body))
:business

(or (re-matches github-pattern subject)
(re-matches github-pattern body))
:technical

(or (re-matches refactor-pattern subject)
(re-matches refactor-pattern body))
:refactor

:default
:other)))

(defn- section-titles [changes]
(->> (map (fn [[k commits]] [k {:title (get titles k) :commits commits}])
changes)
identity
(sort-by #(.indexOf (keys titles) (first %)))
(into (array-map))))
body (:body commit)]
(or (->> sections-config
reverse
(some #(when (or (re-matches (-> % :regex re-pattern) subject)
(re-matches (-> % :regex re-pattern) body)) (:key %))))
:other)))

(defn- section-titles [sections-config changes]
(let [titles (zipmap (vec (cons :other (map :key sections-config))) (vec (cons "Other changes" (map :title sections-config))))]
(->> changes
(map (fn [[k commits]] [k {:title (get titles k) :commits commits}]))
identity
(sort-by #(.indexOf (keys titles) (first %)))
(into (array-map)))))

(defn enrich-changelog [log source-dir]
(->> log
(map (partial issues->links source-dir))
(group-by create-section)
section-titles))
(let [sections-config (or (:sections project-config) sections-defaults)]
(->> log
(map (partial issues->links source-dir))
(group-by (partial create-section sections-config))
((partial section-titles sections-config)))))

(defn create-html-changelog [changes from to source-dir]
(let [to (or to "HEAD")
Expand Down
Loading

0 comments on commit 8b9092d

Please sign in to comment.