Skip to content

Commit 5dd9b23

Browse files
committed
Add information about commit message length
1 parent 49bdced commit 5dd9b23

File tree

3 files changed

+53
-16
lines changed

3 files changed

+53
-16
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ All notable changes to this project will be documented in this file. This change
1010
- File change statistics
1111
- Information about comitter/author emails and corresponding date information for commit
1212
- Log output using logback
13+
- Information about commit message length
1314
### Changed
1415
- Rework commit lists, now displayed as table
1516
- Rework contributor list, now displayed as table

src/repo_analyzer/analyze.clj

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
(ns repo-analyzer.analyze
22
(:import (java.time LocalDateTime))
3-
(:require [clojure.tools.logging :as log])
3+
(:require [clojure.tools.logging :as log]
4+
[clojure.string :as string]
5+
)
46
)
57

68
(use 'clj-jgit.porcelain)
@@ -121,6 +123,15 @@
121123
)
122124
))
123125

126+
(defn compute-commit-message-length-ranking
127+
"Computes a ranking regarding the length of the commit messages"
128+
[logs]
129+
(->> logs
130+
(map #(hash-map :message (:msg %) :length (count (:msg %)) :author (get-in % [:author :email])))
131+
(sort-by :length #(compare %2 %1))
132+
)
133+
)
134+
124135
(defn compute-commit-statistics
125136
"Computes overall commit statistics"
126137
[logs]
@@ -131,19 +142,20 @@
131142
committed-by-different-dev (filter #(not (= (:name (:author %)) (:name (:committer %)))) logs)
132143
commit-statistics
133144
{
134-
:commits logs
135-
:count (count logs)
136-
:self-committed {
137-
:commits self-committed-commits
138-
:count (count self-committed-commits)
139-
:percentage (* 100 (double (/ (count self-committed-commits) (count logs))))
140-
}
141-
:committed-by-different-dev {
142-
:commits committed-by-different-dev
143-
:count (count committed-by-different-dev)
144-
:percentage (* 100 (double (/ (count committed-by-different-dev) (count logs))))
145-
}
146-
:time-distribution (compute-commit-time-distribution logs)
145+
:commits logs
146+
:count (count logs)
147+
:self-committed {
148+
:commits self-committed-commits
149+
:count (count self-committed-commits)
150+
:percentage (* 100 (double (/ (count self-committed-commits) (count logs))))
151+
}
152+
:committed-by-different-dev {
153+
:commits committed-by-different-dev
154+
:count (count committed-by-different-dev)
155+
:percentage (* 100 (double (/ (count committed-by-different-dev) (count logs))))
156+
}
157+
:time-distribution (compute-commit-time-distribution logs)
158+
:commit-message-length-ranking (compute-commit-message-length-ranking logs)
147159
}
148160
]
149161
(log/info "Computation of commit statistics finished")

src/repo_analyzer/render.clj

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
(spit filename site-html))
5858
)
5959

60-
(deftrace create-commit-list-html
60+
(defn create-commit-list-html
6161
"Creates HTML for a list of commits"
6262
[list-of-commits]
6363
(html
@@ -163,7 +163,6 @@
163163
contributor-names (keys contributor-list)
164164
]
165165
(html
166-
167166
[:h1 "Contributors"]
168167
[:table {:class "table table-striped"}
169168
[:thead
@@ -241,6 +240,29 @@
241240
)
242241
))
243242

243+
(defn create-commit-length-statistics-html
244+
[commit-length-statistics]
245+
(let [
246+
top5-longest-messages (take 5 commit-length-statistics)
247+
top5-shortest-messages (take-last 5 commit-length-statistics)
248+
]
249+
(html
250+
[:h2 "Commit message length"]
251+
[:h3 "Top 5 longest commit messages"]
252+
[:ol
253+
(map
254+
#(vector :li (string/join [(:author %) ": " (:message %) " (" (:length %) " characters)"])) top5-longest-messages
255+
)
256+
]
257+
[:h3 "Top 5 shortest commit messages"]
258+
[:ol
259+
(map
260+
#(vector :li (string/join [(:author %) ": " (:message %) " (" (:length %) " characters)"])) top5-shortest-messages
261+
)
262+
]
263+
)
264+
)
265+
)
244266

245267
(defn create-commit-statistics
246268
"Creates commit statistics HTML and subpages. Returns the created HTML"
@@ -259,6 +281,7 @@
259281
line-chart-data-authored (string/join "," (map #(:authored (second %)) (get-in analysis [:commit-statistics :time-distribution])))
260282
line-chart-data-committed (string/join "," (map #(:committed (second %)) (get-in analysis [:commit-statistics :time-distribution])))
261283
file-change-statistics-html (create-file-change-statistics base-path (:file-change-statistics analysis))
284+
commit-length-statistics-html (create-commit-length-statistics-html (get-in analysis [:commit-statistics :commit-message-length-ranking]))
262285
]
263286
(create-site all-commits-filename "All commits" commit-list-html)
264287
(create-site self-commits-filename "Self committed commits" self-commit-list-html)
@@ -291,6 +314,7 @@
291314
(:count (:commit-statistics analysis)) "(" (get-in analysis [:commit-statistics :committed-by-different-dev :percentage]) "%)"
292315
[:a {:href "different-committer-list.html"} " See list of all commits where author and committer are different"]
293316
]
317+
commit-length-statistics-html
294318
file-change-statistics-html
295319
)
296320
))

0 commit comments

Comments
 (0)