generated from nginx/template-repository
-
Notifications
You must be signed in to change notification settings - Fork 120
Add precommit and git conventions #775
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 8 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
1ed29a0
feat: Update git conventions, add initial pre-commit hooks
ADubhlaoich 2785740
Merge branch 'main' into docs/git-conventions
ADubhlaoich a21d280
feat: Add conventional commits hook
ADubhlaoich 86504e0
feat: Add pre-commit instructions
ADubhlaoich be83c81
feat: Finalize conventions documentation
ADubhlaoich 754dc20
Merge branch 'main' into docs/git-conventions
ADubhlaoich 53c922e
feat: Update precommit configuration and docs
ADubhlaoich 4e488eb
feat: Update CONTRIBUTING.md
ADubhlaoich 524bcab
Update documentation/git-conventions.md
ADubhlaoich 336bf35
Merge branch 'main' into docs/git-conventions
ADubhlaoich d7d41b9
Merge branch 'main' into docs/git-conventions
ADubhlaoich d7f6652
Merge branch 'main' into docs/git-conventions
ADubhlaoich File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
[general] | ||
ignore = body-is-missing | ||
contrib = contrib-title-conventional-commits | ||
|
||
[title-max-length] | ||
line-length = 50 | ||
|
||
[title-min-length] | ||
min-length = 5 | ||
|
||
[body-max-line-length] | ||
line-length= 72 | ||
|
||
[body-min-length] | ||
min-length = 5 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
default_install_hook_types: | ||
- pre-commit | ||
- commit-msg | ||
|
||
repos: | ||
- repo: https://github.com/pre-commit/pre-commit-hooks | ||
rev: v5.0.0 | ||
hooks: | ||
- id: no-commit-to-branch | ||
- repo: https://github.com/jorisroovers/gitlint | ||
rev: v0.19.1 | ||
hooks: | ||
- id: gitlint |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
# Git conventions | ||
|
||
For consistency, we have a handful of git conventions: | ||
|
||
- We follow a [GitHub flow model](https://githubflow.github.io/) for branch management | ||
- We follow [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/#summary) formatting | ||
- We write [good commit messages](https://cbea.ms/git-commit/), treating them as a source of truth | ||
|
||
Many of these conventions are suggested or enforced in tooling: for local development, [set up pre-commit](/documentation/pre-commit.md). | ||
|
||
We encourage small, tightly-scoped pull requests: this makes managing reviews simpler, allowing us to iterate on documentation quickly. | ||
|
||
## Branch management | ||
|
||
We continuously deploy from the [`main`](https://github.com/nginx/documentation/tree/main) branch. | ||
|
||
To make changes, [fork the repository](https://github.com/nginx/documentation/fork) then branch from `main`, giving your branch a prefix and descriptive name. | ||
|
||
Prefixes are typically a three letter acronym for the product it affects: | ||
- `nic/`, `ngf/`, `nim`/, `waf/`, and so forth | ||
- Use `docs/` if the change is related to the repository or not product-specific | ||
|
||
A descriptive name usually concerns what the branch actually updates: | ||
- `nic/update-helm-links` Tells someone at a glance that the branch relates to NGINX Ingress Controller and links related to Helm | ||
- `patch-27` Tells someone almost nothing at a glance: it does not include a prefix or any details about a possible topic | ||
|
||
The exception to this branch naming convention is release branches for products. These are named `<product>-<release>-<version>`: | ||
- `agent-release-2.2` | ||
- `n1c-release-1.5` | ||
- `dos-release-5.1` | ||
|
||
Typically, the technical writer for a given product will ensure that branches are kept in sync with `main`, to minimize the risk of merge conflicts. | ||
|
||
If you need to rename a branch, here's the syntax: | ||
|
||
```shell | ||
git branch -m <current-branch-name> <new-branch-name> | ||
``` | ||
|
||
## Commit messages | ||
|
||
When opening a pull request on GitHub, the very first commit from a branch is automatically pulled to populate the description. | ||
|
||
This provides an opportunity to re-use a good commit message to provide context to reviewers for the changes in a branch. | ||
|
||
The first line of a git commit message becomes the subject line, with the contents after a line break becoming the body. | ||
|
||
A subject line begins with a [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/#summary) prefix, and should be written in present imperative. | ||
- _feat: Update ConfigMap reference page_ | ||
- _fix: Remove links to missing website_ | ||
|
||
Keep the subject line around 50 characters or less: imagine the reader is using `git reflog` or `git log --oneline` to review changes. | ||
|
||
The body of the git message should have its lines kept around 72 characters or less, and can be structured as follows: | ||
|
||
- What was changed and why | ||
- How the changes were implement | ||
- What else the changes might affect, and what may change in the future | ||
|
||
This provides enough context for a reader to get a strong impression of what the commit accomplishes, which in turn makes reviewing pull requests easier | ||
|
||
An example of a full commit message following the above conventions is as follows: | ||
|
||
``` | ||
feat: Move and update process documentation | ||
|
||
This commit moves and updates some of the process documentation for the | ||
repository. This is an iterative process, which will continue to improve | ||
as time goes on. Some of the changes include: | ||
|
||
- Moving the closed contributions document into the documentation folder | ||
- Moving and reframing the F5/NGINX document as "Maintainers etiquette" | ||
- Moving and renaming the "Managing content with Hugo" document | ||
- Moving the style guide from the templates folder | ||
|
||
These files will likely be updated in a subsequent PR as we clarify the | ||
contribution process and user flow of other process artefacts, such as | ||
the pull request and issue templates. | ||
|
||
Although we do not draw attention to it, the templates folder is being | ||
retained for reference until the style guide and Hugo archetypes contain | ||
the relevant, useful information. | ||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Set up pre-commit | ||
|
||
[pre-commit](https://pre-commit.com/) is a command-line tool used for automatic linting. | ||
|
||
It is currently *optional*, and used for consistent [Git conventions](/documentation/git-conventions.md), but will be used for more in the future. | ||
|
||
The configuration file is located at the root of the repository, [pre-commit-config.yaml](/.pre-commit-config.yaml). | ||
|
||
## Install pre-commit | ||
|
||
To install pre-commit, you need [pip](https://pypi.org/project/pip/), which is bundled with most contemporary Python installations. | ||
|
||
After ensuring you have pip installed, follow the [Installation steps](https://pre-commit.com/#install): | ||
|
||
```shell | ||
pip install pre-commit | ||
``` | ||
|
||
Then install the git hook scripts with the following command: | ||
|
||
```shell | ||
pre-commit install | ||
``` | ||
|
||
It will then run every time you use `git commit`. | ||
|
||
If you encounter an error about a missing configuration file, you are likely working in a branch that has not synced changes from `main`. | ||
|
||
You will need to sync changes from `main` or temporarily uninstall pre-commit to address the error. | ||
|
||
```shell | ||
pre-commit uninstall | ||
``` |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.