Subject: [PATCH] teams: Fix script to produce a single X-Debbugs-Cc header.

From: Maxim Cournoyer <[email-masked]>
Date: Mon, 8 May 2023 14:29:42 -0400

Fixes <https://issues.guix.gnu.org/63378>.

* etc/teams.scm.in (cc): Adjust format pattern.
(team->members, member->string): New procedures.
(list-members): Refactor in terms of the above procedures.
(main): Adjust the output of the 'cc-members-header-cmd' and
'cc-mentors-header-cmd' actions.
---
 etc/teams.scm.in | 35 ++++++++++++++++++++---------------
 1 file changed, 20 insertions(+), 15 deletions(-)

diff --git a/etc/teams.scm.in b/etc/teams.scm.in
index dec175f630..50bfbca22e 100644
--- a/etc/teams.scm.in
+++ b/etc/teams.scm.in
@@ -605,23 +605,27 @@ (define (cc . teams)
   "Return arguments for `git send-email' to notify the members of the given
 TEAMS when a patch is received by Debbugs."
   (format #true
-          "~{--add-header=\"X-Debbugs-Cc: ~a\"~^ ~}"
+          "--add-header=\"X-Debbugs-Cc: ~{~a~^,~}\""
           (map person-email
                (delete-duplicates (append-map team-members teams) equal?))))
 
+(define (team->members team)
+  "Return the list of members in TEAM."
+  (sort (team-members team)
+        (lambda (m1 m2)
+          (string<? (person-name m1) (person-name m2)))))
+
+(define (member->string member)
+  "Return the 'email <name>' string representation of MEMBER."
+  (format #false "~a <~a>" (person-name member) (person-email member)))
+
 (define* (list-members team #:optional port (prefix ""))
   "Print the members of the given TEAM."
   (define port* (or port (current-output-port)))
   (for-each
    (lambda (member)
-     (format port*
-             "~a~a <~a>~%"
-             prefix
-             (person-name member)
-             (person-email member)))
-   (sort
-    (team-members team)
-    (lambda (m1 m2) (string<? (person-name m1) (person-name m2))))))
+     (format port* "~a~a~%" prefix (member->string member)))
+   (team->members team)))
 
 (define (list-teams)
   "Print all teams, their scope and their members."
@@ -715,13 +719,14 @@ (define (main . args)
      (apply cc (find-team-by-scope
                 (diff-revisions rev-start rev-end))))
     (("cc-members-header-cmd" patch-file)
-     (for-each (lambda (team-name)
-                 (list-members (find-team team-name) (current-output-port)
-                               "X-Debbugs-Cc: "))
-               (patch->teams patch-file)))
+     (format #true "X-Debbugs-Cc: ~{~a~^,~}"
+             (append-map (compose (cut map member->string <>)
+                                  team->members
+                                  find-team)
+                         (patch->teams patch-file))))
     (("cc-mentors-header-cmd" patch-file)
-     (list-members (find-team "mentors") (current-output-port)
-                   "X-Debbugs-Cc: "))
+     (format #true "X-Debbugs-Cc: ~{~a~^,~}"
+             (map member->string (team->members (find-team "mentors")))))
     (("get-maintainer" patch-file)
      (apply main "list-members" (patch->teams patch-file)))
     (("list-teams" . args)

base-commit: 4228d3c358669f5d15f01d3ba466f3356ecb6546
-- 
2.39.2