Browse code

gerrit-send-mail: add missing Signed-off-by

Our development documentation says we add this
automatically when it is missing. So let's do that
here as well.

Change-Id: If9cb7d66f079fe1c87fcb5b4e59bc887533d77fa
Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20240308120557.9065-1-gert@greenie.muc.de>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg28362.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>

Frank Lichtenheld authored on 2024/03/08 21:05:57
Showing 1 changed files
... ...
@@ -50,6 +50,12 @@ def get_details(args):
50 50
                 ack = f"{reviewer_name} <{reviewer_mail}>"
51 51
                 print(f"Acked-by: {ack}")
52 52
                 acked_by.append(ack)
53
+    # construct Signed-off-by in case it is missing
54
+    owner = json_data["owner"]
55
+    owner_name = owner.get("display_name", owner["name"])
56
+    owner_mail = owner.get("email", owner["name"])
57
+    sign_off = f"{owner_name} <{owner_mail}>"
58
+    print(f"Signed-off-by: {sign_off}")
53 59
     change_id = json_data["change_id"]
54 60
     # assumes that the created date in Gerrit is in UTC
55 61
     utc_stamp = (
... ...
@@ -67,6 +73,7 @@ def get_details(args):
67 67
         "target": json_data["branch"],
68 68
         "msg_id": msg_id,
69 69
         "acked_by": acked_by,
70
+        "sign_off": sign_off,
70 71
     }
71 72
 
72 73
 
... ...
@@ -81,10 +88,14 @@ def get_patch(details, args):
81 81
 
82 82
 def apply_patch_mods(patch_text, details, args):
83 83
     comment_start = patch_text.index("\n---\n") + len("\n---\n")
84
+    signed_off_text = ""
85
+    signed_off_comment = ""
84 86
     try:
85 87
         signed_off_start = patch_text.rindex("\nSigned-off-by: ")
86 88
         signed_off_end = patch_text.index("\n", signed_off_start + 1) + 1
87 89
     except ValueError:  # Signed-off missing
90
+        signed_off_text = f"Signed-off-by: {details['sign_off']}\n"
91
+        signed_off_comment = "\nSigned-off-by line for the author was added as per our policy.\n"
88 92
         signed_off_end = patch_text.index("\n---\n") + 1
89 93
     assert comment_start > signed_off_end
90 94
     acked_by_text = ""
... ...
@@ -94,6 +105,7 @@ def apply_patch_mods(patch_text, details, args):
94 94
         acked_by_names += f"{ack}\n"
95 95
     patch_text_mod = (
96 96
         patch_text[:signed_off_end]
97
+        + signed_off_text
97 98
         + acked_by_text
98 99
         + patch_text[signed_off_end:comment_start]
99 100
         + f"""
... ...
@@ -102,6 +114,7 @@ developer. I request to merge it to {details["target"]}.
102 102
 
103 103
 Gerrit URL: {args.url}/c/{details["project"]}/+/{args.changeid}
104 104
 This mail reflects revision {details["revision"]} of this Change.
105
+{signed_off_comment}
105 106
 Acked-by according to Gerrit (reflected above):
106 107
 {acked_by_names}
107 108
         """