@@ -23,12 +23,40 @@ core.workflow(
23
23
origin_files = glob(["**"], exclude = ["src/mongo/db/modules/**"]),
24
24
authoring = authoring.pass_thru("MongoDB <
[email protected] >"),
25
25
mode = "ITERATIVE",
26
- # Change the path here to the folder you want to publish publicly
27
26
transformations = [
28
- # (^.*?) - matches the first line (without the newline char)
29
- # \n - matches the first newline (or nothing at all if there is no newline). If there is no match then nothing happens
30
- # ((\n|.)*) - matches everything after
31
- # Overall, this copies only the first line of the commit rather than the body
32
- metadata.scrubber("(^.*?)\n((\n|.)*)", replacement = "$1"),
27
+ # The transformation rules below will remove the commit message's body, while preserving
28
+ # any trailer lines that have acceptable keys (Co-authored-by, etc). The first line of
29
+ # the commit message (ie. the commit's subject/summary line) is also always retained.
30
+ #
31
+ # Achieving this requires a 4 step process.
32
+ #
33
+ # STEP 1: Non-initial lines (ie. those which appear after a newline char) that start with
34
+ # an acceptable trailer key are preserved, but any other lines have their content removed
35
+ # (leaving a blank line).
36
+ #
37
+ # This works because the first .* (inside capture group 1) only matches if the line starts
38
+ # with a trailer key. If it doesn't, then the line is fully consumed by the second .*
39
+ # (which is outside the capture group, and therefore $1 is empty).
40
+ metadata.scrubber(
41
+ "\n((?:Co-authored-by|Signed-off-by|Reviewed-by): .*)?.*",
42
+ replacement = "\n$1",
43
+ ),
44
+ #
45
+ # STEP 2: Remove blank lines, ie. sequences of newlines get condensed down to one newline.
46
+ metadata.scrubber("\n+", replacement = "\n"),
47
+ #
48
+ # STEP 3: Remove any trailing newline.
49
+ metadata.scrubber("\n$", replacement = ""),
50
+ #
51
+ # STEP 4: If there are trailer lines (ie. if the first line has a newline followed by more
52
+ # text), then add an extra blank line after the first line, ie. to separate the commit's
53
+ # trailers from the subject line.
54
+ #
55
+ # The first capture group (^.*?\n) is the first line (non-greedily consuming chars until a
56
+ # newline), while the second capture group ((\n|.)*) is the rest of the message (greedily
57
+ # consume all chars, including newlines).
58
+ # If there are no trailers, then there will only be a single line of text, with no newline
59
+ # chars, and so the pattern will fail to match.
60
+ metadata.scrubber("(^.*?\n)((?:\n|.)*)", replacement = "$1\n$2"),
33
61
],
34
62
)
0 commit comments