2023-10-10 16:09:33 -07:00
|
|
|
# This configuration is for migrating code from one Git repository to another using Copybara.
|
|
|
|
|
# It selectively copies content, excluding specific paths and preserving authorship.
|
SERVER-90928 Remove lines other than commit title from syncing (#22589)
# Issue
Remove lines other than commit title from syncing
# Description
SERVER-90928 Remove lines other than commit title from syncing to the
public repo
# Testing
This was tested locally. I tested on the commits in this PR and it seems
to be synced correctly. The staging file I used was
```
# This configuration is for migrating code from one Git repository to another using Copybara.
# It selectively copies content, excluding specific paths and preserving authorship.
# To test locally
sourceUrl = "/Users/alexander.neben/workspace/mongo2"
destinationUrl = "/Users/alexander.neben/workspace/mongodb-mongo"
# sourceUrl = "git@github.com:10gen/mongo.git"
# destinationUrl = "git@github.com:10gen/mongo-copybara.git"
core.workflow(
name = "default",
origin = git.origin(
url = sourceUrl,
ref = "IamXander/prune_commit",
),
destination = git.destination(
url = destinationUrl,
fetch = "IamXander/prune_commit",
push = "IamXander/prune_commit",
),
# Change path to the folder you want to publish publicly
origin_files = glob(["**"], exclude = ["src/mongo/db/modules/**"]),
authoring = authoring.pass_thru("MongoDB <mongodb@mongodb.com>"),
mode = "ITERATIVE",
# Change the path here to the folder you want to publish publicly
transformations = [
metadata.scrubber("(^.*?)\n((\n|.)*)", replacement = "$1"),
],
)
```
Running git log on `/Users/alexander.neben/workspace/mongodb-mongo`
returns the following
```
commit 8a4879557893ae942f793ad707d56e255bebc72d (HEAD -> IamXander/prune_commit)
Author: Alex Neben <alex.neben@mongodb.com>
Date: Tue May 28 08:55:38 2024 -0700
fixes
GitOrigin-RevId: 3ffa6b95d44ec3fef7e715a3f24652966861f4e1
commit 66cdb3631be92ced2123c7e3fab39e24bed91b2b
Author: Alex Neben <alex.neben@mongodb.com>
Date: Tue May 28 08:50:07 2024 -0700
SERVER-90928 Remove lines other than commit title from syncing
GitOrigin-RevId: 7d90f0f69a17943fb68ba23e2f135d08c00c4943
commit 0063834a4fa519727cc6b816995ea56d9b3328fe
Author: Alex Neben <alex.neben@mongodb.com>
Date: Tue May 28 08:12:24 2024 -0700
SERVER-XYZ asdasdkjfhaskdf akjdhkjashdkjashd example
GitOrigin-RevId: 298831cd1d55319ea368fdd2f1dc604368d94889
commit fc7f29486d762a740c3ebe01c3b7d69a477abe75
Author: Alex Neben <alex.neben@mongodb.com>
Date: Fri May 24 13:55:21 2024 -0700
prune commit message
GitOrigin-RevId: 43692434bf664fe593ee7eb5f53372ca331ecec9
```
Which shows no data after the newline. It also does not include
enterprise code.
GitOrigin-RevId: f78828e412e3ac510c6e56feb541146c688b7603
2024-05-28 14:22:24 -07:00
|
|
|
|
2024-09-16 18:20:10 +03:00
|
|
|
sourceUrl = "https://github.com/10gen/mongo.git"
|
2025-08-25 10:34:37 -05:00
|
|
|
prodUrl = "https://github.com/mongodb/mongo.git"
|
|
|
|
|
testUrl = "https://github.com/10gen/mongo-copybara.git"
|
|
|
|
|
testBranch = "copybara_test_branch"
|
2026-02-19 09:10:51 -06:00
|
|
|
prodRefForPinnedSourceCommit = "master"
|
2025-08-25 10:34:37 -05:00
|
|
|
|
2026-02-20 11:43:55 -06:00
|
|
|
def make_workflow(workflow_name, destination_url, source_ref, destination_ref):
|
2023-10-10 16:09:33 -07:00
|
|
|
|
2025-08-25 10:34:37 -05:00
|
|
|
core.workflow(
|
|
|
|
|
name = workflow_name,
|
|
|
|
|
origin = git.origin(
|
|
|
|
|
url = "https://github.com/10gen/mongo.git",
|
2026-02-20 11:43:55 -06:00
|
|
|
ref = source_ref,
|
2025-03-04 15:43:49 +11:00
|
|
|
),
|
2025-08-25 10:34:37 -05:00
|
|
|
destination = git.destination(
|
|
|
|
|
url = destination_url,
|
2026-02-20 11:43:55 -06:00
|
|
|
fetch = destination_ref,
|
|
|
|
|
push = destination_ref,
|
2025-06-12 10:55:16 -07:00
|
|
|
),
|
2025-08-25 10:34:37 -05:00
|
|
|
# Change path to the folder you want to publish publicly
|
2026-02-06 10:58:15 -06:00
|
|
|
origin_files = glob(["**"], exclude = [
|
|
|
|
|
"src/mongo/db/modules/**",
|
|
|
|
|
"buildscripts/modules/**",
|
|
|
|
|
".github/workflows/**",
|
|
|
|
|
"src/third_party/private/**",
|
2026-02-26 09:54:52 -05:00
|
|
|
"sbom.private.json",
|
2026-02-06 10:58:15 -06:00
|
|
|
".augment/**",
|
|
|
|
|
".cursor/**",
|
2026-03-04 16:43:10 -05:00
|
|
|
".claude/**",
|
2026-02-06 10:58:15 -06:00
|
|
|
"AGENTS.md",
|
|
|
|
|
".github/CODEOWNERS",
|
2026-02-13 17:40:20 -06:00
|
|
|
"monguard/**",
|
2026-02-06 10:58:15 -06:00
|
|
|
]),
|
2025-08-25 10:34:37 -05:00
|
|
|
authoring = authoring.pass_thru("MongoDB <mongodb@mongodb.com>"),
|
|
|
|
|
mode = "ITERATIVE",
|
|
|
|
|
transformations = [
|
|
|
|
|
# The transformation rules below will remove the commit message's body, while preserving
|
|
|
|
|
# any trailer lines that have acceptable keys (Co-authored-by, etc). The first line of
|
|
|
|
|
# the commit message (ie. the commit's subject/summary line) is also always retained.
|
|
|
|
|
#
|
|
|
|
|
# Achieving this requires a 4 step process.
|
|
|
|
|
#
|
|
|
|
|
# STEP 1: Non-initial lines (ie. those which appear after a newline char) that start with
|
|
|
|
|
# an acceptable trailer key are preserved, but any other lines have their content removed
|
|
|
|
|
# (leaving a blank line).
|
|
|
|
|
#
|
|
|
|
|
# This works because the first .* (inside capture group 1) only matches if the line starts
|
|
|
|
|
# with a trailer key. If it doesn't, then the line is fully consumed by the second .*
|
|
|
|
|
# (which is outside the capture group, and therefore $1 is empty).
|
|
|
|
|
metadata.scrubber(
|
|
|
|
|
"\n((?:Co-authored-by|Signed-off-by|Reviewed-by): .*)?.*",
|
|
|
|
|
replacement = "\n$1",
|
|
|
|
|
),
|
|
|
|
|
#
|
|
|
|
|
# STEP 2: Remove blank lines, ie. sequences of newlines get condensed down to one newline.
|
|
|
|
|
metadata.scrubber("\n+", replacement = "\n"),
|
|
|
|
|
#
|
|
|
|
|
# STEP 3: Remove any trailing newline.
|
|
|
|
|
metadata.scrubber("\n$", replacement = ""),
|
|
|
|
|
#
|
|
|
|
|
# STEP 4: If there are trailer lines (ie. if the first line has a newline followed by more
|
|
|
|
|
# text), then add an extra blank line after the first line, ie. to separate the commit's
|
|
|
|
|
# trailers from the subject line.
|
|
|
|
|
#
|
|
|
|
|
# The first capture group (^.*?\n) is the first line (non-greedily consuming chars until a
|
|
|
|
|
# newline), while the second capture group ((\n|.)*) is the rest of the message (greedily
|
|
|
|
|
# consume all chars, including newlines).
|
|
|
|
|
# If there are no trailers, then there will only be a single line of text, with no newline
|
|
|
|
|
# chars, and so the pattern will fail to match.
|
|
|
|
|
metadata.scrubber("(^.*?\n)((?:\n|.)*)", replacement = "$1\n$2"),
|
|
|
|
|
#
|
|
|
|
|
# STEP 5: Replace any private links with their public equivalent.
|
|
|
|
|
core.replace(
|
|
|
|
|
before = "https://github.com/10gen/mongo",
|
|
|
|
|
after = "https://github.com/mongodb/mongo",
|
|
|
|
|
paths = glob(["**/*.md"]),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# push to the public repo
|
2026-02-20 11:43:55 -06:00
|
|
|
make_workflow("prod", prodUrl, prodRefForPinnedSourceCommit, "master")
|
2025-08-25 10:34:37 -05:00
|
|
|
|
|
|
|
|
# push to private test repo to validate configs
|
2026-02-20 11:43:55 -06:00
|
|
|
make_workflow("test", testUrl, testBranch, testBranch)
|