Skip to content

Commit c023b24

Browse files
committed
feat: Add mailmap.edn for canonical display names at export
1 parent 753a93f commit c023b24

5 files changed

Lines changed: 42 additions & 5 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ data/
88
.clj-kondo/
99
config.edn
1010
config_history/
11+
mailmap.edn
1112
todo.org
1213
public/
1314
logs/

README.org

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,18 @@ The full tenure history (active and closed) is exported in
252252
command processing on archived emails even when maintainers have
253253
changed over time.
254254

255+
*** Canonical display names (=mailmap.edn=)
256+
257+
To unify display names across addresses belonging to the same person,
258+
create =mailmap.edn= at the repo root:
259+
260+
#+begin_src clojure
261+
{"Bastien Guerry" ["bzg@gnu.org" "bzg@bzg.fr"]}
262+
#+end_src
263+
264+
Applied at export time only (DB untouched) to maintainers, authors,
265+
and owners. Unlisted emails keep their last observed =From:= name.
266+
255267
For sources whose maintainer list or vocabulary evolved over time,
256268
declare the history inline via =:periods= on the source (see
257269
=docs/bark-manual.org §Source periods=).

scripts/bark-docs.clj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
'[bark.common :refer [default-labels default-commands
2020
resolve-labels-map resolve-commands-map
2121
resolve-command-syntax
22-
parse-cli-args load-config db-path build-source-map
22+
parse-cli-args load-config load-mailmap db-path build-source-map
2323
format-date-iso bark-schema lead-maintainer]]
2424
'[bark.common-bb :refer [load-datalevin-pod! get-tenures]]
2525
'[bark.html-bb :refer [pico-cdn resolved-theme set-theme!
@@ -394,7 +394,8 @@
394394
(when source-name
395395
(let [tenures (get-tenures db source-name)
396396
lead (lead-maintainer tenures)
397-
names (participant-names-for-source db source-name)
397+
names (merge (participant-names-for-source db source-name)
398+
(load-mailmap))
398399
;; Sort: lead first, then alphabetical by email (case-insensitive).
399400
sort-key (fn [{:keys [email to]}]
400401
[(if (and (nil? to) (= email lead)) 0 1)

scripts/bark-export.clj

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
format-date format-date-iso
5454
report-priority report-status report-descendant-count
5555
parse-cli-args parse-delay parse-cutoff-date
56-
load-config db-path build-source-map
56+
load-config load-mailmap db-path build-source-map
5757
bark-schema bark-format
5858
report-type-spec type->plural
5959
votes-by-report vote-counts
@@ -426,7 +426,8 @@
426426
(reset! export-ctx {:db db
427427
:votes votes
428428
:config config
429-
:author-names (build-author-names db)}))
429+
:author-names (merge (build-author-names db)
430+
(load-mailmap))}))
430431

431432
(defn- ctx-db [] (:db @export-ctx))
432433
(defn- ctx-votes [] (:votes @export-ctx))
@@ -505,6 +506,8 @@
505506
(fetch-attachment-data db (:report/message-id report))))
506507
att-email (delay (:report/email @att-data))
507508
from (or (:email/author-address email) "")
509+
from-name (or (get (ctx-author-names) (str/lower-case from))
510+
(:email/author-name email))
508511
arch (archive-url report email source-map)
509512
src-type (get-in source-map [source-name :source-type])
510513
relations (group-relations report src-type)
@@ -526,7 +529,7 @@
526529
(assoc-from-addresses report)
527530
(assoc-owned-name (ctx-author-names))
528531
(cond->
529-
(:email/author-name email) (assoc :from-name (:email/author-name email))
532+
from-name (assoc :from-name from-name)
530533
role (assoc :role role)
531534
(:report/message-id report) (assoc :message-id (:report/message-id report))
532535
(:report/version report) (assoc :version (:report/version report))

src/bark/common.clj

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,26 @@
680680
(when (.exists f)
681681
(edn/read-string (slurp f))))))
682682

683+
(defn load-mailmap
684+
"Load ./mailmap.edn (or `path`) and return `{email-lc -> canonical-name}`.
685+
Input shape: `{\"Canonical Name\" [\"e1@x\" \"e2@y\"]}`. Multiple
686+
emails per person are inverted to a flat lookup. Returns `{}` if
687+
the file is absent. Used at export time only -- never read by the
688+
ingest path, so the DB stays the single source of truth for what
689+
each address sent under what name."
690+
([] (load-mailmap "mailmap.edn"))
691+
([path]
692+
(let [f (io/file path)]
693+
(if (.exists f)
694+
(let [m (edn/read-string (slurp f))]
695+
(reduce-kv
696+
(fn [acc nm emails]
697+
(reduce (fn [a e] (assoc a (str/lower-case e) nm))
698+
acc
699+
emails))
700+
{} m))
701+
{}))))
702+
683703
(defn db-path
684704
"Resolve the Datalevin DB path: prefer :db {:path …} from the
685705
config, fall back to BARK_DB env var, then default \"data/bark-db\"."

0 commit comments

Comments
 (0)