Debian Codegraph @

docs/contributing.md

raw symbols SCIP
1 # Contributing
2
3 We'd love for you to contribute to gitlint. Thanks for your interest!
4 The [source-code and issue tracker](https://github.com/jorisroovers/gitlint) are hosted on Github.
5
6 !!! note
7 Often it takes a while for us (well, actually just [me](https://github.com/jorisroovers)) to get back to you
8 (sometimes up to a few months, this is a hobby project), but rest assured that we read your message and appreciate
9 your interest!
10 We maintain a [loose project plan on github projects](https://github.com/users/jorisroovers/projects/1/), but
11 that's open to a lot of change and input.
12
13 ## Overall Guidelines
14
15 When contributing code, please consider all the parts that are typically required:
16
17 - [Unit tests](https://github.com/jorisroovers/gitlint/tree/main/gitlint-core/gitlint/tests) (automatically
18 [enforced by CI](https://github.com/jorisroovers/gitlint/actions)). Please consider writing
19 new ones for your functionality, not only updating existing ones to make the build pass.
20 - [Integration tests](https://github.com/jorisroovers/gitlint/tree/main/qa) (also automatically
21 [enforced by CI](https://github.com/jorisroovers/gitlint/actions)). Again, please consider writing new ones
22 for your functionality, not only updating existing ones to make the build pass.
23 - [Documentation](https://github.com/jorisroovers/gitlint/tree/main/docs).
24
25 Since we want to maintain a high standard of quality, all of these things will have to be done regardless before code
26 can make it as part of a release. **Gitlint commits and pull requests are gated on all of our tests and checks as well as
27 code-review**. If you can already include them as part of your PR, it's a huge timesaver for us
28 and it's likely that your PR will be merged and released a lot sooner.
29
30 !!! important
31 It's a good idea to open an issue before submitting a PR for non-trivial changes, so we can discuss what you have
32 in mind before you spend the effort. Thanks!
33
34 ## Releases
35 Gitlint releases typically go out when there's either enough new features and fixes
36 to make it worthwhile or when there's a critical fix for a bug that fundamentally breaks gitlint.
37
38 While the amount of overhead of doing a release isn't huge, it's also not zero. In practice this means that it might
39 take weeks or months before merged code actually gets released - we know that can be frustrating but please
40 understand it's a well-considered trade-off based on available time.
41
42 ### Dev Builds
43 While final releases are usually months apart, we do dev builds on every commit to `main`:
44
45 - **gitlint**: [https://pypi.org/project/gitlint/#history](https://pypi.org/project/gitlint/#history)
46 - **gitlint-core**: [https://pypi.org/project/gitlint-core/#history](https://pypi.org/project/gitlint-core/#history)
47
48 It usually takes about 5 min after merging a PR to `main` for new dev builds to show up. Note that the installation
49 of a recently published version can still fail for a few minutes after a new version shows up on PyPI while the package
50 is replicated to all download mirrors.
51
52 To install a dev build of gitlint:
53 ```sh
54 # Find latest dev build on https://pypi.org/project/gitlint/#history
55 pip install gitlint=="0.19.0.dev68"
56 ```
57
58
59 ## Environment setup
60 ### Local setup
61
62 Gitlint uses [hatch](https://hatch.pypa.io/latest/) for project management.
63 You do not need to setup a `virtualenv`, hatch will take care of that for you.
64
65 ```sh
66 pip install hatch
67 ```
68
69 ### Github Devcontainer
70
71 We provide a devcontainer on github to make it easier to get started with gitlint development using VSCode.
72
73 To start one, click the plus button under the *Code* dropdown on
74 [the gitlint repo on github](https://github.com/jorisroovers/gitlint).
75
76 **It can take ~15min for all post installation steps to finish.**
77
78 ![Gitlint Dev Container Instructions](images/dev-container.png)
79
80
81 By default we have python 3.11 installed in the dev container, but you can also use [asdf](https://asdf-vm.com/)
82 (preinstalled) to install additional python versions:
83
84 ```sh
85 # Ensure ASDF overrides system python in PATH
86 # You can also append this line to your ~/.bash_profile in the devcontainer to have this happen automatically on login
87 source "$(brew --prefix asdf)/libexec/asdf.sh"
88
89 # Install python 3.9.15
90 asdf install python 3.9.15
91 # List all available python versions
92 asdf list all python
93 # List installed python versions
94 asdf list python
95 ```
96
97 ## Running tests
98 ```sh
99 # Gitlint
100 hatch run dev:gitlint # run the local source copy of gitlint
101 hatch run dev:gitlint --version # This is just the gitlint binary, any flag will work
102 hatch run dev:gitlint --debug
103
104 # Unit tests
105 hatch run test:unit-tests # run unit tests
106 hatch run test:unit-tests gitlint-core/gitlint/tests/rules/test_body_rules.py::BodyRuleTests::test_body_missing # run a single test
107 hatch run test:unit-tests -k test_body_missing_merge_commit # Run a specific tests using a pytest keyword expression
108 hatch run test:unit-tests-no-cov # run unit tests without test coverage
109
110 # Integration tests
111 hatch run qa:install-local # One-time install: install the local gitlint source copy for integration testing
112 hatch run qa:integration-tests # Run integration tests
113
114 # Formatting check (black)
115 hatch run test:format # Run formatting checks
116
117 # Linting (ruff)
118 hatch run test:lint # Run Ruff
119
120 # Project stats
121 hatch run test:stats
122 ```
123 ## Autoformatting and autofixing
124
125 We use [black](https://black.readthedocs.io/en/stable/) for code formatting.
126
127 ```sh
128 hatch run test:autoformat # format all python code
129 hatch run test:autoformat gitlint-core/gitlint/lint.py # format a specific file
130 ```
131
132 We use [ruff](https://github.com/charliermarsh/ruff) for linting, it can autofix many of the issue it finds
133 (although not always perfect).
134 ```sh
135 hatch run test:autofix # Attempt to fix linting issues
136 ```
137
138 ## Documentation
139 We use [mkdocs](https://www.mkdocs.org/) for generating our documentation from markdown.
140
141 To use it:
142 ```sh
143 hatch run docs:serve
144 ```
145
146 Then access the documentation website on [http://localhost:8000]().
147
148 ## Packaging
149
150 Gitlint consists of 2 python packages: [gitlint](https://pypi.org/project/gitlint/)
151 and [gitlint-core](https://pypi.org/project/gitlint-core/).
152
153 The `gitlint` package is just a wrapper package around `gitlint-core[trusted-deps]` which strictly pins gitlint
154 dependencies to known working versions.
155
156 There are scenarios where users (or OS package managers) may want looser dependency requirements.
157 In these cases, users can just install `gitlint-core` directly (`pip install gitlint-core`).
158
159 [Issue 162](https://github.com/jorisroovers/gitlint/issues/162) has all the background of how we got to the decision
160 to split gitlint in 2 packages.
161
162 ![Gitlint package structure](images/gitlint-packages.png)
163
164 To build the packages locally:
165 ```sh
166 # gitlint
167 hatch build
168 hatch clean # cleanup
169
170 # gitlint-core
171 cd gitlint-core
172 hatch build
173 hatch clean # cleanup
174 ```
175
176 ## Tools
177 We keep a small set of scripts in the `tools/` directory:
178
179 ```sh
180 tools/create-test-repo.sh # Create a test git repo in your /tmp directory
181 tools/windows/create-test-repo.bat # Windows: create git test repo
182 tools/windows/run_tests.bat # Windows run unit tests
183 ```
184
185 ## Contrib rules
186 Since gitlint 0.12.0, we support [Contrib rules](contrib_rules.md): community contributed rules that are part of gitlint
187 itself. Thanks for considering to add a new one to gitlint!
188
189 Before starting, please read all the other documentation on this page about contributing first.
190 Then, we suggest taking the following approach to add a Contrib rule:
191
192 1. **Write your rule as a [user-defined rule](user_defined_rules.md)**. In terms of code, Contrib rules are identical to
193 user-defined rules, they just happen to have their code sit within the gitlint codebase itself.
194 2. **Add your user-defined rule to gitlint**. You should put your file(s) in the [gitlint/contrib/rules](https://github.com/jorisroovers/gitlint/tree/main/gitlint-core/gitlint/contrib/rules) directory.
195 3. **Write unit tests**. The gitlint codebase contains [Contrib rule test files you can copy and modify](https://github.com/jorisroovers/gitlint/tree/main/gitlint-core/gitlint/tests/contrib/rules).
196 4. **Write documentation**. In particular, you should update the [gitlint/docs/contrib_rules.md](https://github.com/jorisroovers/gitlint/blob/main/docs/contrib_rules.md) file with details on your Contrib rule.
197 5. **Create a Pull Request**: code review typically requires a bit of back and forth. Thanks for your contribution!
198
199
200 ### Contrib rule requirements
201 If you follow the steps above and follow the existing gitlint conventions wrt naming things, you should already be fairly close to done.
202
203 In case you're looking for a slightly more formal spec, here's what gitlint requires of Contrib rules.
204
205 - Since Contrib rules are really just user-defined rules that live within the gitlint code-base, all the [user-rule requirements](user_defined_rules.md#rule-requirements) also apply to Contrib rules.
206 - All contrib rules **must** have associated unit tests. We *sort of* enforce this by a unit test that verifies that there's a
207 test file for each contrib file.
208 - All contrib rules **must** have names that start with `contrib-`. This is to easily distinguish them from default gitlint rules.
209 - All contrib rule ids **must** start with `CT` (for LineRules targeting the title), `CB` (for LineRules targeting the body) or `CC` (for CommitRules). Again, this is to easily distinguish them from default gitlint rules.
210 - All contrib rules **must** have unique names and ids.
211 - You **can** add multiple rule classes to the same file, but classes **should** be logically grouped together in a single file that implements related rules.
212 - Contrib rules **should** be meaningfully different from one another. If a behavior change or tweak can be added to an existing rule by adding options, that should be considered first. However, large [god classes](https://en.wikipedia.org/wiki/God_object) that implement multiple rules in a single class should obviously also be avoided.
213 - Contrib rules **should** use [options](user_defined_rules.md#options) to make rules configurable.