Skip to content

Commit 4b57030

Browse files
authored
feat: Add precommit and git conventions (#775)
This commit moves our git conventions to their own discrete page, and adds information that was previously not written down anywhere, such as our general branch management strategy. Beyond documenting these conventions, an initial pre-commit configuration has been added, which can be used as a guardrail to enforce some of the conventions, such as requirements around commit message length. A hook provided by the pre-commit maintainers is also configured to prevent commits directly to the main branch. These configurations may be adjusted in the future based on feedback, and there is additional follow-up work to add a template for the git commit message. I had a working implementation but decided to scrap it in favour of minimising the number of dependencies.
1 parent 664c1ab commit 4b57030

File tree

6 files changed

+156
-37
lines changed

6 files changed

+156
-37
lines changed

.gitlint

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[general]
2+
ignore = body-is-missing
3+
contrib = contrib-title-conventional-commits
4+
5+
[title-max-length]
6+
line-length = 50
7+
8+
[title-min-length]
9+
min-length = 5
10+
11+
[body-max-line-length]
12+
line-length= 72
13+
14+
[body-min-length]
15+
min-length = 5

.pre-commit-config.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
default_install_hook_types:
2+
- pre-commit
3+
- commit-msg
4+
5+
repos:
6+
- repo: https://github.com/pre-commit/pre-commit-hooks
7+
rev: v5.0.0
8+
hooks:
9+
- id: no-commit-to-branch
10+
- repo: https://github.com/jorisroovers/gitlint
11+
rev: v0.19.1
12+
hooks:
13+
- id: gitlint

CONTRIBUTING.md

Lines changed: 9 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Contributing guidelines
22

3-
The following is a set of guidelines for community contributions to this project.
3+
The following is a set of guidelines for community contributions to this project.
44

55
We really appreciate your desire to contribute!
66

@@ -11,10 +11,7 @@ If you are an F5 employee, see the following additional guidance on [Maintainers
1111
- [Report a Bug](#report-a-bug)
1212
- [Suggest a Feature or Enhancement](#suggest-a-feature-or-enhancement)
1313
- [Open a Discussion](#open-a-discussion)
14-
- [Submit a Pull Request](#submit-a-pull-request)
15-
- Review our [Git style guide](#git-style-guide)
16-
- Review the [Writing style guide](/documentation/style-guide.md)
17-
- Review [Managing content with Hugo](/documentation/writing-hugo.md)
14+
- [Submit a pull request](#submit-a-pull-request)
1815
- [Issue Lifecycle](#issue-lifecycle)
1916
- [Additional NGINX documentation](#additional-nginx-documentation)
2017
- [F5 Contributor License Agreement (CLA)](#f5-contributor-license-agreement)
@@ -37,44 +34,20 @@ If you want to start a conversation with the community and maintainers,
3734
we encourage you to use
3835
[GitHub Discussions](https://github.com/nginx/documentation/discussions).
3936

40-
## Submit a Pull Request
37+
## Submit a pull request
4138

42-
To contribute to F5 NGINX documentation, follow these steps:
39+
Before making documentation changes, you should view the [documentation style guide](/documentation/style-guide.md) and [Managing content with Hugo](/documentation/writing-hugo.md).
40+
41+
To understand how we use Git in this repository, read our [Git conventions](/documentation/git-conventions.md) documentation.
42+
43+
The broad workflow is as follows:
4344

4445
- Fork the NGINX repository
4546
- Create a branch
4647
- Implement your changes in your branch
4748
- Submit a pull request (PR) when your changes are ready for review
4849

49-
Alternatively, you're welcome to suggest improvements to highlight problems with
50-
our documentation as described in our [support](./SUPPORT.md) page.
51-
52-
### Git style guide
53-
54-
- Keep a clean, concise and meaningful Git commit history on your branch, rebasing locally and squashing before you submit a PR
55-
- We use [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/#summary) formatting.
56-
- Follow the guidelines of writing a good commit message as described here <https://chris.beams.io/posts/git-commit/>
57-
and summarized in the next few points:
58-
59-
- In the subject line, use the present tense ("Add feature" not "Added feature")
60-
- In the subject line, use the imperative mood ("Move cursor to..." not "Moves cursor to...")
61-
- Limit the subject line to 72 characters or less
62-
- Reference issues and pull requests liberally after the subject line
63-
- Add more detailed description in the body of the git message (`git commit -a` to give you more space and time in
64-
your text editor to write a good message instead of `git commit -am`)
65-
66-
#### Branch protection rules
67-
68-
This repository has the following branch protection rules in place:
69-
70-
- **Pushing branches that contain the "internal/" prefix is not allowed.** This ensures internal development branches are not accidentally or purposefully pushed to this repo.
71-
- **Two approvers are required for all merges to main and release branches.** This ensures all code that is approved for release to production is appropriately reviewed. This rule applies to all branches with `*release*` in the branch name.
72-
- **Only NGINX DocOps Team members can create release branches.** This ensures the docs team is aware of all branches supporting specific product releases. This rule applies to all branches with `*release*` in the branch name.
73-
- **Pushes (force or otherwise) directly to main or release branches is not allowed.** Release branches serve as "main" for the release they are associated with. Restricting pushes directly to main and release branches ensures all content changes are reviewed and approved. This rule applies to all branches with `*release*` in the branch name and to "main".
74-
75-
### Documentation style guide
76-
77-
For detailed guidance, see our documentation [style guide](./templates/style-guide.md).
50+
Alternatively, you're welcome to suggest improvements to highlight problems with our documentation as described in our [support](./SUPPORT.md) page.
7851

7952
## Issue lifecycle
8053

documentation/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# NGINX Documentation repository
1+
# NGINX Documentation repository
22

33
This directory contains the documentation for the NGINX Documentation repository.
44

@@ -13,8 +13,10 @@ If you're interested in contributing to the [NGINX documentation website](https:
1313
## Topics
1414

1515
- [Contributing closed content](/documentation/closed-contributions.md)
16+
- [Git conventions](/documentation/git-conventions.md)
1617
- [Information architecture heuristics](/documentation/ia-heuristics.md)
1718
- [Maintainers etiquette](/documentation/maintainers-etiquette.md)
1819
- [Managing content with Hugo](/documentation/writing-hugo.md)
1920
- [Proposals](/documentation/proposals/README.md)
21+
- [Set up pre-commit](/documentation/pre-commit.md)
2022
- [Writing style guide](/documentation/style-guide.md)

documentation/git-conventions.md

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# Git conventions
2+
3+
For consistency, we have a handful of git conventions:
4+
5+
- We follow a [GitHub flow model](https://githubflow.github.io/) for branch management
6+
- We follow [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/#summary) formatting
7+
- We write [good commit messages](https://cbea.ms/git-commit/), treating them as a source of truth
8+
9+
Many of these conventions are suggested or enforced in tooling: for local development, [set up pre-commit](/documentation/pre-commit.md).
10+
11+
We encourage small, tightly-scoped pull requests: this makes managing reviews simpler, allowing us to iterate on documentation quickly.
12+
13+
## Branch management
14+
15+
We continuously deploy from the [`main`](https://github.com/nginx/documentation/tree/main) branch.
16+
17+
To make changes, [fork the repository](https://github.com/nginx/documentation/fork) then branch from `main`, giving your branch a prefix and descriptive name.
18+
19+
Prefixes are typically a three letter acronym for the product it affects:
20+
- `nic/`, `ngf/`, `nim`/, `waf/`, and so forth
21+
- Use `docs/` if the change is related to the repository or not product-specific
22+
23+
A descriptive name usually concerns what the branch actually updates:
24+
- `nic/update-helm-links` Tells someone at a glance that the branch relates to NGINX Ingress Controller and links related to Helm
25+
- `patch-27` Tells someone almost nothing at a glance: it does not include a prefix or any details about a possible topic
26+
27+
The exception to this branch naming convention is release branches for products. These are named `<product>-<release>-<version>`:
28+
- `agent-release-2.2`
29+
- `n1c-release-1.5`
30+
- `dos-release-5.1`
31+
32+
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.
33+
34+
If you need to rename a branch, here's the syntax:
35+
36+
```shell
37+
git branch -m <current-branch-name> <new-branch-name>
38+
```
39+
40+
## Commit messages
41+
42+
When opening a pull request on GitHub, the very first commit from a branch is automatically pulled to populate the description.
43+
44+
This provides an opportunity to re-use a good commit message to provide context to reviewers for the changes in a branch.
45+
46+
The first line of a git commit message becomes the subject line, with the contents after a line break becoming the body.
47+
48+
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.
49+
- _feat: Update ConfigMap reference page_
50+
- _fix: Remove links to missing website_
51+
52+
Keep the subject line around 50 characters or less: imagine the reader is using `git reflog` or `git log --oneline` to review changes.
53+
54+
The body of the git message should have its lines kept around 72 characters or less, and can be structured as follows:
55+
56+
- What was changed and why
57+
- How the changes were implemented
58+
- What else the changes might affect, and what may change in the future
59+
60+
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
61+
62+
An example of a full commit message following the above conventions is as follows:
63+
64+
```
65+
feat: Move and update process documentation
66+
67+
This commit moves and updates some of the process documentation for the
68+
repository. This is an iterative process, which will continue to improve
69+
as time goes on. Some of the changes include:
70+
71+
- Moving the closed contributions document into the documentation folder
72+
- Moving and reframing the F5/NGINX document as "Maintainers etiquette"
73+
- Moving and renaming the "Managing content with Hugo" document
74+
- Moving the style guide from the templates folder
75+
76+
These files will likely be updated in a subsequent PR as we clarify the
77+
contribution process and user flow of other process artefacts, such as
78+
the pull request and issue templates.
79+
80+
Although we do not draw attention to it, the templates folder is being
81+
retained for reference until the style guide and Hugo archetypes contain
82+
the relevant, useful information.
83+
```

documentation/pre-commit.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Set up pre-commit
2+
3+
[pre-commit](https://pre-commit.com/) is a command-line tool used for automatic linting.
4+
5+
It is currently *optional*, and used for consistent [Git conventions](/documentation/git-conventions.md), but will be used for more in the future.
6+
7+
The configuration file is located at the root of the repository, [pre-commit-config.yaml](/.pre-commit-config.yaml).
8+
9+
## Install pre-commit
10+
11+
To install pre-commit, you need [pip](https://pypi.org/project/pip/), which is bundled with most contemporary Python installations.
12+
13+
After ensuring you have pip installed, follow the [Installation steps](https://pre-commit.com/#install):
14+
15+
```shell
16+
pip install pre-commit
17+
```
18+
19+
Then install the git hook scripts with the following command:
20+
21+
```shell
22+
pre-commit install
23+
```
24+
25+
It will then run every time you use `git commit`.
26+
27+
If you encounter an error about a missing configuration file, you are likely working in a branch that has not synced changes from `main`.
28+
29+
You will need to sync changes from `main` or temporarily uninstall pre-commit to address the error.
30+
31+
```shell
32+
pre-commit uninstall
33+
```

0 commit comments

Comments
 (0)