Skip to content

Commit b8004e6

Browse files
authored
GODRIVER-3018 Use pre-commit for development (#1443)
1 parent 3a07cb1 commit b8004e6

File tree

79 files changed

+249
-140
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+249
-140
lines changed

.evergreen/ocsp-requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
asn1crypto==1.3.0
22
bottle==0.12.20
3-
oscrypto==1.2.0
3+
oscrypto==1.2.0

.evergreen/run-fuzz.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ do
4444
for CORPUS_FILE in $PARENTDIR/testdata/fuzz/$FUNC/*
4545
do
4646
# Check to see if the value for CORPUS_FILE is in cset.
47-
if [[ ! " ${cset[@]} " =~ " ${CORPUS_FILE} " ]]; then
47+
if [[ ! " ${cset[*]} " =~ " ${CORPUS_FILE} " ]]; then
4848
# Create the directory if it doesn't exist.
4949
if [ ! -d $PROJECT_DIRECTORY/fuzz/$FUNC ]; then
5050
mkdir -p $PROJECT_DIRECTORY/fuzz/$FUNC
@@ -69,4 +69,3 @@ if [ -d $PROJECT_DIRECTORY/fuzz ]; then
6969
# This will trigger a notification to be sent to the Go Driver team.
7070
exit 1
7171
fi
72-

.evergreen/run-tests.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export GOCACHE="$(pwd)/.cache"
77
export DRIVERS_TOOLS=${DRIVERS_TOOLS:-""}
88

99
if [ -z $DRIVERS_TOOLS ]; then
10-
export DRIVERS_TOOLS=="$(dirname $(dirname $(dirname `pwd`)))/drivers-tools"
10+
export DRIVERS_TOOLS="$(dirname $(dirname $(dirname `pwd`)))/drivers-tools"
1111
fi
1212

1313
if [ "Windows_NT" = "$OS" ]; then
@@ -49,7 +49,7 @@ fi
4949
# Using python3-venv in Ubuntu 14.04 (an OS required for legacy server version
5050
# tasks) requires the use of apt-get, which we wish to avoid. So, we do not set
5151
# a python3 binary on Ubuntu 14.04. Setting AWS temp credentials for legacy
52-
# server version tasks is unneccesary, as temp credentials are only needed on 4.2+.
52+
# server version tasks is unnecessary, as temp credentials are only needed on 4.2+.
5353
if [ ! -z ${PYTHON3_BINARY} ]; then
5454
export AWS_ACCESS_KEY_ID="${AWS_ACCESS_KEY_ID}"
5555
export AWS_SECRET_ACCESS_KEY="${AWS_SECRET_ACCESS_KEY}"

.github/workflows/test.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: GoDriver Tests
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
concurrency:
8+
group: test-${{ github.ref }}
9+
cancel-in-progress: true
10+
11+
defaults:
12+
run:
13+
shell: bash -eux {0}
14+
15+
jobs:
16+
pre_commit:
17+
runs-on: ubuntu-latest
18+
steps:
19+
- uses: actions/checkout@v4
20+
- uses: actions/setup-python@v4
21+
- uses: pre-commit/[email protected]

.pre-commit-config.yaml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
2+
repos:
3+
- repo: https://github.com/pre-commit/pre-commit-hooks
4+
rev: v4.5.0
5+
hooks:
6+
- id: check-case-conflict
7+
- id: check-executables-have-shebangs
8+
- id: check-added-large-files
9+
- id: check-case-conflict
10+
- id: check-merge-conflict
11+
- id: check-json
12+
- id: end-of-file-fixer
13+
exclude: ^vendor/
14+
exclude_types: [json,yaml]
15+
- id: trailing-whitespace
16+
exclude: ^(vendor/|internal/assert/assertions_test.go)
17+
exclude_types: [json,yaml]
18+
19+
- repo: https://github.com/executablebooks/mdformat
20+
rev: 0.7.17
21+
hooks:
22+
- id: mdformat
23+
exclude: ^vendor/
24+
25+
- repo: https://github.com/python-jsonschema/check-jsonschema
26+
rev: 0.27.0
27+
hooks:
28+
- id: check-github-workflows
29+
30+
# We use the Python version instead of the original version which seems to require Docker
31+
# https://github.com/koalaman/shellcheck-precommit
32+
- repo: https://github.com/shellcheck-py/shellcheck-py
33+
rev: v0.9.0.6
34+
hooks:
35+
- id: shellcheck
36+
name: shellcheck
37+
args: ["--severity=error"]
38+
39+
- repo: https://github.com/codespell-project/codespell
40+
rev: "v2.2.6"
41+
hooks:
42+
- id: codespell
43+
args: ["-L", "te,fo,fle,alo,nin,compres,wil,collone,asess,sav,ot,wll,dne,nulll,hellow"]
44+
exclude: ^(vendor/|benchmark/operation_test.go)
45+
exclude_types: [json,yaml,pem]
46+
47+
- repo: https://github.com/golangci/golangci-lint
48+
rev: v1.55.1
49+
hooks:
50+
- id: golangci-lint

README.md

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,17 @@
1010

1111
The MongoDB supported driver for Go.
1212

13-
-------------------------
13+
______________________________________________________________________
14+
1415
## Requirements
1516

1617
- Go 1.13 or higher. We aim to support the latest versions of Go.
1718
- `go mod tidy` will error when importing the Go Driver using Go versions older than 1.15 due to dependencies that import [io/fs](https://pkg.go.dev/io/fs). See golang/go issue [#44557](https://github.com/golang/go/issues/44557) for more information.
1819
- Go 1.20 or higher is required to run the driver test suite.
1920
- MongoDB 3.6 and higher.
2021

21-
-------------------------
22+
______________________________________________________________________
23+
2224
## Installation
2325

2426
The recommended way to get started using the MongoDB Go driver is by using Go modules to install the dependency in
@@ -35,7 +37,8 @@ When using a version of Go that does not support modules, the driver can be inst
3537
dep ensure -add "go.mongodb.org/mongo-driver/mongo"
3638
```
3739

38-
-------------------------
40+
______________________________________________________________________
41+
3942
## Usage
4043

4144
To get started with the driver, import the `mongo` package and create a `mongo.Client` with the `Connect` function:
@@ -150,13 +153,13 @@ Additional examples and documentation can be found under the examples directory
150153

151154
### Network Compression
152155

153-
Network compression will reduce bandwidth requirements between MongoDB and the application.
156+
Network compression will reduce bandwidth requirements between MongoDB and the application.
154157

155158
The Go Driver supports the following compression algorithms:
156159

157160
1. [Snappy](https://google.github.io/snappy/) (`snappy`): available in MongoDB 3.4 and later.
158-
2. [Zlib](https://zlib.net/) (`zlib`): available in MongoDB 3.6 and later.
159-
3. [Zstandard](https://github.com/facebook/zstd/) (`zstd`): available in MongoDB 4.2 and later.
161+
1. [Zlib](https://zlib.net/) (`zlib`): available in MongoDB 3.6 and later.
162+
1. [Zstandard](https://github.com/facebook/zstd/) (`zstd`): available in MongoDB 4.2 and later.
160163

161164
#### Specify Compression Algorithms
162165

@@ -176,35 +179,41 @@ If compressors are set, the Go Driver negotiates with the server to select the f
176179

177180
Messages compress when both parties enable network compression; otherwise, messages remain uncompressed
178181

179-
-------------------------
182+
______________________________________________________________________
183+
180184
## Feedback
181185

182186
For help with the driver, please post in the [MongoDB Community Forums](https://developer.mongodb.com/community/forums/tag/golang/).
183187

184188
New features and bugs can be reported on jira: https://jira.mongodb.org/browse/GODRIVER
185189

186-
-------------------------
190+
______________________________________________________________________
191+
187192
## Contribution
188193

189194
Check out the [project page](https://jira.mongodb.org/browse/GODRIVER) for tickets that need completing. See our [contribution guidelines](docs/CONTRIBUTING.md) for details.
190195

191-
-------------------------
196+
______________________________________________________________________
197+
192198
## Continuous Integration
193199

194200
Commits to master are run automatically on [evergreen](https://evergreen.mongodb.com/waterfall/mongo-go-driver).
195201

196-
-------------------------
202+
______________________________________________________________________
203+
197204
## Frequently Encountered Issues
198205

199206
See our [common issues](docs/common-issues.md) documentation for troubleshooting frequently encountered issues.
200207

201-
-------------------------
208+
______________________________________________________________________
209+
202210
## Thanks and Acknowledgement
203211

204212
- The Go Gopher artwork by [@ashleymcnamara](https://github.com/ashleymcnamara)
205213
- The original Go Gopher was designed by [Renee French](http://reneefrench.blogspot.com/)
206214

207-
-------------------------
215+
______________________________________________________________________
216+
208217
## License
209218

210219
The MongoDB Go Driver is licensed under the [Apache License](LICENSE).

THIRD-PARTY-NOTICES

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,13 +192,13 @@ Copyright (c) 2010-2013 - Gustavo Niemeyer <[email protected]>
192192
All rights reserved.
193193

194194
Redistribution and use in source and binary forms, with or without
195-
modification, are permitted provided that the following conditions are met:
195+
modification, are permitted provided that the following conditions are met:
196196

197197
1. Redistributions of source code must retain the above copyright notice, this
198-
list of conditions and the following disclaimer.
198+
list of conditions and the following disclaimer.
199199
2. Redistributions in binary form must reproduce the above copyright notice,
200200
this list of conditions and the following disclaimer in the documentation
201-
and/or other materials provided with the distribution.
201+
and/or other materials provided with the distribution.
202202

203203
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
204204
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED

bson/bsonrw/copier.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ func (c Copier) CopyBytesToDocumentWriter(dst DocumentWriter, src []byte) error
124124
}
125125

126126
func (c Copier) copyBytesToValueWriter(src []byte, wef writeElementFn) error {
127-
// TODO(skriptble): Create errors types here. Anything thats a tag should be a property.
127+
// TODO(skriptble): Create errors types here. Anything that is a tag should be a property.
128128
length, rem, ok := bsoncore.ReadLength(src)
129129
if !ok {
130130
return fmt.Errorf("couldn't read length from src, not enough bytes. length=%d", len(src))

bson/mgocompat/bson_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -916,13 +916,13 @@ func TestUnmarshalAllItemsWithPtrSetter(t *testing.T) {
916916
if i == 0 {
917917
assert.Nil(t, field, "expected field to be nil, got: %v", field)
918918
} else {
919-
assert.Nil(t, field.Received, "expected field.recieved to be nil, got: %v", field.Received)
919+
assert.Nil(t, field.Received, "expected field.received to be nil, got: %v", field.Received)
920920
}
921921
} else {
922922
expected := item.obj.(bson.M)["_"]
923923
assert.NotNil(t, field, "Pointer not initialized (%#v)", expected)
924924

925-
assert.True(t, reflect.DeepEqual(expected, field.Received), "expected field.recieved to be: %v, got: %v", expected, field.Received)
925+
assert.True(t, reflect.DeepEqual(expected, field.Received), "expected field.received to be: %v, got: %v", expected, field.Received)
926926
}
927927
}
928928
})
@@ -933,7 +933,7 @@ func TestUnmarshalWholeDocumentWithSetter(t *testing.T) {
933933
obj := &setterType{}
934934
err := bson.UnmarshalWithRegistry(Registry, []byte(sampleItems[0].data), obj)
935935
assert.Nil(t, err, "expected nil error, got: %v", err)
936-
assert.True(t, reflect.DeepEqual(bson.M{"hello": "world"}, obj.Received), "expected obj.recieved to be: %v, got: %v", bson.M{"hello": "world"}, obj.Received)
936+
assert.True(t, reflect.DeepEqual(bson.M{"hello": "world"}, obj.Received), "expected obj.received to be: %v, got: %v", bson.M{"hello": "world"}, obj.Received)
937937
}
938938

939939
func TestUnmarshalSetterErrors(t *testing.T) {

docs/CONTRIBUTING.md

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ The Go Driver team uses GitHub to manage and review all code changes. Patches sh
1818
applicable.
1919

2020
Code should compile and tests should pass under all Go versions which the driver currently supports. Currently the Go Driver supports a minimum version of Go 1.13 and requires Go 1.20 for development. Please run the following Make targets to validate your changes:
21+
2122
- `make fmt`
2223
- `make lint` (requires [golangci-lint](https://github.com/golangci/golangci-lint) and [lll](https://github.com/walle/lll) to be installed and available in the `PATH`)
2324
- `make test`
@@ -29,6 +30,23 @@ If any tests do not pass, or relevant tests are not included, the patch will not
2930

3031
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.
3132

33+
### Linting on commit
34+
35+
The Go team uses [pre-commit](https://pre-commit.com/#installation) to lint both source and text files.
36+
37+
To install locally, run:
38+
39+
```bash
40+
brew install pre-commit
41+
pre-commit install
42+
```
43+
44+
After that, the checks will run on any changed files when committing. To manually run the checks on all files, run:
45+
46+
```bash
47+
pre-commit run --all-files
48+
```
49+
3250
### Cherry-picking between branches
3351

3452
You must first install the `gh` cli (`brew install gh`), then set your GitHub username:
@@ -77,6 +95,7 @@ mongod \
7795
```
7896

7997
To run the tests with `make`, set:
98+
8099
- `MONGO_GO_DRIVER_CA_FILE` to the location of the CA file used by the database
81100
- `MONGO_GO_DRIVER_KEY_FILE` to the location of the client key file
82101
- `MONGO_GO_DRIVER_PKCS8_ENCRYPTED_KEY_FILE` to the location of the pkcs8 client key file encrypted with the password string: `password`
@@ -98,6 +117,7 @@ make
98117
```
99118

100119
Notes:
120+
101121
- The `--tlsAllowInvalidCertificates` flag is required on the server for the test suite to work correctly.
102122
- The test suite requires the auth database to be set with `?authSource=admin`, not `/admin`.
103123

@@ -120,7 +140,7 @@ The requirements for testing FaaS implementations in the Go Driver vary dependin
120140
The following are the requirements for running the AWS Lambda tests locally:
121141

122142
1. [AWS SAM CLI](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/install-sam-cli.html)
123-
2. [Docker](https://www.docker.com/products/docker-desktop/)
143+
1. [Docker](https://www.docker.com/products/docker-desktop/)
124144

125145
Local testing requires exporting the `MONGODB_URI` environment variables. To build the AWS Lambda image and invoke the `MongoDBFunction` lambda function use the `build-faas-awslambda` make target:
126146

@@ -134,15 +154,15 @@ There is currently no arm64 support for the go1.x runtime, see [here](https://do
134154

135155
### Testing in Docker
136156

137-
We support local testing in Docker. Ensure ``docker`` is installed and running, and then run:
157+
We support local testing in Docker. Ensure `docker` is installed and running, and then run:
138158

139159
```bash
140160
bash etc/run_docker.sh
141161
```
142162

143-
The script takes an optional argument for the ``MAKEFILE_TARGET`` and allows for some environment variable overrides.
163+
The script takes an optional argument for the `MAKEFILE_TARGET` and allows for some environment variable overrides.
144164
The docker container has the required binaries, including libmongocrypt.
145-
The entry script starts a MongoDB topology, and then executes the desired ``MAKEFILE_TARGET``.
165+
The entry script starts a MongoDB topology, and then executes the desired `MAKEFILE_TARGET`.
146166

147167
For example, to test against a sharded cluster, using enterprise auth, run:
148168

docs/common-issues.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ When connecting to a MongoDB deployment with password authentication enabled, if
5858
> connection() error occurred during connection handshake: auth error: sasl conversation error: unable to authenticate using mechanism "SCRAM-SHA-256": (AuthenticationFailed) Authentication failed.
5959
6060
That error can be caused by a number of issues. The error message intentionally omits the exact authentication failure reason (see the [OWASP Authentication and Error Messages guidelines](https://cheatsheetseries.owasp.org/cheatsheets/Authentication_Cheat_Sheet.html#authentication-and-error-messages) for an explanation). Possible causes of the error include:
61+
6162
- Incorrect password.
6263
- Incorrect username.
6364
- Incorrect authentication database (i.e. [authSource](https://www.mongodb.com/docs/manual/reference/connection-string/#mongodb-urioption-urioption.authSource)).

docs/pull_request_template.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
<!--- If applicable, issue number goes here, e.g. GODRIVER-ABCD -->
22

33
## Summary
4+
45
<!--- A summary of the changes proposed by this pull request. -->
56

67
## Background & Motivation
7-
<!--- Rationale for the pull request. -->
88

9+
<!--- Rationale for the pull request. -->

etc/api_report.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ if [ "$BASE_SHA" == "$HEAD_SHA" ]; then
88
echo "Skipping API Report"
99
exit 0
1010
fi
11-
11+
1212
# Ensure a clean checkout.
1313
git checkout -b test-api-report
1414
git add .

etc/assets/docs-mongodb-green.svg

Lines changed: 1 addition & 1 deletion
Loading

etc/assets/godev-bson-blue.svg

Lines changed: 1 addition & 1 deletion
Loading

0 commit comments

Comments
 (0)