Skip to content

Commit

Permalink
GODRIVER-2978 Automate syncing code between Go driver v1 and v2
Browse files Browse the repository at this point in the history
  • Loading branch information
blink1073 committed Sep 18, 2023
1 parent 59f7519 commit 6a07a6a
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
12 changes: 12 additions & 0 deletions docs/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@ If any tests do not pass, or relevant tests are not included, the patch will not

If you are working on a bug or feature listed in Jira, please include the ticket number prefixed with GODRIVER in the commit message and GitHub pull request title, (e.g. GODRIVER-123). For the patch commit message itself, please follow the [How to Write a Git Commit Message](https://chris.beams.io/posts/git-commit/) guide.

### Cherry-picking between branches

If a Pull Request needs to be cherry-picked to a new branch, get the sha of the commit in the base branch, and then run

```bash
bash etc/cherry-picker.sh <sha>
```

The cherry-picker script is configured to use `v1` as the base branch and `master` as the target branch.
It will create a new checkout in a temp dir, create a new branch, perform the cherry-pick, and then
prompt before creating a PR to the target branch.

## Testing / Development

The driver tests can be run against several database configurations. The most simple configuration is a standalone mongod with no auth, no ssl, and no compression. To run these basic driver tests, make sure a standalone MongoDB server instance is running at localhost:27017. To run the tests, you can run `make` (on Windows, run `nmake`). This will run coverage, run go-lint, run go-vet, and build the examples.
Expand Down
35 changes: 35 additions & 0 deletions etc/cherry-picker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash

sha=$1
base=v1
target=master
dirname="/tmp/go-driver-$(openssl rand -hex 12)"
mkdir -p $dirname
git clone git@github.com:mongodb/mongo-go-driver.git $dirname
cd $dirname
branch="cherry-pick-$sha"
git fetch origin $base
git fetch origin $target
git checkout -b $branch origin/$target
git cherry-pick -x $sha

old_title=$(git --no-pager log -1 --pretty=%B | head -n 1)
ticket=$(echo $old_title | sed -r 's/([A-Z]+-[0-9]+).*/\1/')
echo "ticket $ticket"
text=$(echo $old_title | sed -r 's/([A-Z]+-[0-9]+) (.*) \(#[0-9]*\)/\2/')
echo "text $text"
pr_number=$(echo $old_title| sed -r 's/.*(#[0-9]*)\)/\1/')
echo "pr number: $pr_number"
title="$ticket [$target] $text"
body="Cherry-pick of $pr_number from $base to $target"

echo
echo "Creating PR..."
echo "Title: $title"
echo "Body: $body"
echo

read -p 'Push changes? (Y/n) ' choice
if [[ "$choice" == "Y" || "$choice" == "y" || -z "$choice" ]]; then
gh pr create --title "$title" --base $target --body "$body"
fi

0 comments on commit 6a07a6a

Please sign in to comment.