Skip to content

Commit

Permalink
Merge pull request #28 from two-inc/brtkwr/t-18443-add-atlas-and-infr…
Browse files Browse the repository at this point in the history
…a-teams

T-18443/fix: Add atlas and infra teams
  • Loading branch information
brtkwr authored Jul 26, 2024
2 parents 70eeb64 + fde424f commit add9239
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 51 deletions.
5 changes: 4 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
default_install_hook_types: [commit-msg, prepare-commit-msg]
minimum_pre_commit_version: "3.2.0"
default_install_hook_types: [pre-commit, commit-msg, prepare-commit-msg]
default_stages:
- pre-commit
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
Expand Down
44 changes: 29 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
# git-hooks

This repo contains custom git hooks we use at Two. To add a hook to a repo you have to add it to the repo's `.pre-commit-config.yaml` file
This repo contains custom git hooks we use at Two. To add a hook to a repo you
have to add it to the repo's `.pre-commit-config.yaml` file

## Add Hook To Repo

First make sure you have installed pre-commit in your repo with `brew install pre-commit` and installed the relevant hooks with `pre-commit install --hook-type <type>`. See `stages` in [.pre-commit-hooks.yaml](.pre-commit-hooks.yaml) for relevant hook types. For more information on pre-commit usage, refer to [docs](https://pre-commit.com/#developing-hooks-interactively).
First make sure you have installed pre-commit in your repo with `brew install
pre-commit` and installed the relevant hooks with `pre-commit install
--hook-type <type>`. See `stages` in
[.pre-commit-hooks.yaml](.pre-commit-hooks.yaml) for relevant hook types. For
more information on pre-commit usage, refer to
[docs](https://pre-commit.com/#developing-hooks-interactively).

### Example Config

Expand All @@ -18,7 +24,9 @@ To only check for a reference to a Linear issue in your commit message, add this
- id: linear-ref
```
To check for both a reference to a Linear issue as well as a conventional commit type (`<Linear ref>/<conventional commit type>[!]: <description>`), add this:
To check for both a reference to a Linear issue as well as a conventional
commit type (`<Linear ref>/<conventional commit type>[!]: <description>`), add
this:

```yaml
# .pre-commit-config.yaml
Expand All @@ -38,22 +46,28 @@ Alternatively, you can use ssh
- id: commit-type-with-linear-ref
```

## Developmment

## Setup
1. Create virtual environment:
### 1. Create virtual environment

python3 -m venv venv
```bash
python3 -m venv venv
```

2. Install requirements:
### 2. Install requirements

pip3 install '.[dev]'
```bash
pip3 install -e '.[dev]'
```

## Release Process (git-hooks repo)
### 3. Release

1. If you have permission to push to main directly, skip to step 2. Otherwise create a new Linear ticket with a title "git-hooks release X.Y.Z" and a new branch based on that Linear ticket branching off of main.
1. If you have permission to push to main directly, skip to step 2. Otherwise
create a new Linear ticket with a title "git-hooks release X.Y.Z" and a new
branch based on that Linear ticket branching off of main.
2. Run `bumpver update --dry` to check version update will be as expected.
5. Run `bumpver update` to update git-hooks version. This creates a bump commit.
6. Push directly to `main` if you have permission to do so or via a PR if not.
8. Check out `main` branch and set tag with `git tag X.Y.Z` based on [CalVer](https://calver.org/) convention.
9. Push tags with `git push --tags`.
10. Go to GH and draft a new release - choose tag and select "generate release notes".
3. Run `bumpver update` to update git-hooks version. This creates a bump commit.
4. Push directly to `main` if you have permission to do so or via a PR if not.
5. Check out `main` branch and set tag with `git tag X.Y.Z` based on [CalVer](https://calver.org/) convention.
6. Push tags with `git push --tags`.
7. Go to GH and draft a new release - choose tag and select "generate release notes".
2 changes: 1 addition & 1 deletion git_hooks/commit_msg.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
See https://github.com/two-inc/git-hooks/blob/24.06.24/README.md for more info.
{ENDC}
{common.commit_type_doc}
{common.commit_types_doc}
"""


Expand Down
84 changes: 52 additions & 32 deletions git_hooks/common.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,59 @@
commit_types = [
"build updating build configuration, development tools",
"chore updating grunt tasks etc.",
"ci updating deployment configuration",
"docs changes to documentation",
"fix patching a bug in the codebase",
"feat adding a new feature to the code",
"feat! adding a new feature that introduces breaking API change",
"hotfix updating a bug in production",
"perf updating code to make performance enhancements",
"refactor updating code without any functional change",
"revert updating code to earlier change",
"style formatting changes, missing semicolons, etc.",
"test for adding missing tests, refactoring tests; no production code change",
]

commit_type_doc = (
"""Valid conventional commit types are:
commit_types: dict[str, str] = {
"build": "updating build configuration, development tools",
"chore": "updating grunt tasks etc.",
"ci": "updating deployment configuration",
"docs": "changes to documentation",
"fix": "patching a bug in the codebase",
"feat": "adding a new feature to the code",
"feat!": "adding a new feature that introduces breaking API change",
"hotfix": "updating a bug in production",
"perf": "updating code to make performance enhancements",
"refactor": "updating code without any functional change",
"revert": "updating code to earlier change",
"style": "formatting changes, missing semicolons, etc.",
"test": "for adding missing tests, refactoring tests; no production code change",
}

\t"""
+ "\n\t".join(commit_types)
+ "\n"
commit_types_title: str = "Valid conventional commit types are:"
commit_types_block: str = "\t" + "\n\t".join(
[f"{k.ljust(10)}{v}" for k, v in commit_types.items()]
)
commit_types_doc: str = f"""
{commit_types_title}
commented_commit_type_doc = "# " + commit_type_doc.replace("\n", "\n#")
{commit_types_block}
"""
commit_types_doc_commented: str = "\n".join(
[
f"# {commit_types_title}",
"#" + commit_types_block.replace("\n", "\n#"),
]
)

commit_type_regex = (
"(?:build|chore|ci|docs|feat|fix|hotfix|perf|refactor|revert|style|test)"
commit_type_regex: str = f"(?:{'|'.join(commit_types.keys())})"
teams: list[str] = [
"ATL",
"CET",
"DEL",
"INF",
"KNA",
"L2",
"NOR",
"T",
]
linear_ref: str = (
"(?:"
f"{'|'.join(t for t in teams)}"
"|"
f"{'|'.join(t.lower() for t in teams)}"
")-[0-9]{1,5}"
)
linear_ref = "(?:t|T|kna|KNA|cet|CET|nor|NOR|l2|L2|del|DEL)-[0-9]{1,5}"
valid_commit_regex = (
valid_commit_regex: str = (
f"^{linear_ref}/{commit_type_regex}!?: |Merge .+|Revert .+|Bump version .+"
)
partial_branch_regex = f"({linear_ref})[-|_](.*)"
branch_regex = f"^(.*)/{partial_branch_regex}"
commit_msg_title_regex = f"^({commit_type_regex}!?):? (.*)"
commit_msg_issue_regex = f"^({linear_ref})/(.*)"
issue_regex = f"^{linear_ref}$"
prefix_regex = f"^({commit_type_regex})"
partial_branch_regex: str = f"({linear_ref})[-|_](.*)"
branch_regex: str = f"^(.*)/{partial_branch_regex}"
commit_msg_title_regex: str = f"^({commit_type_regex}!?):? (.*)"
commit_msg_issue_regex: str = f"^({linear_ref})/(.*)"
issue_regex: str = f"^{linear_ref}$"
prefix_regex: str = f"^({commit_type_regex})"
2 changes: 1 addition & 1 deletion git_hooks/prepare_commit_msg.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def prepare_commit_msg(raw_commit_msg: str, branch: str) -> str:
commit_msg_title = (
commit_msg_title_data["commit_msg_title"] or branch_data["commit_msg_title"]
)
commit_type_lines = [common.commented_commit_type_doc] if edit_mode else []
commit_type_lines = [common.commit_types_doc_commented] if edit_mode else []
linear_commit_msg_lines = (
[linear_data["commit_msg_body"]] if linear_data.get("commit_msg_body") else []
)
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ dependencies = [
dev = [
"bumpver==2022.1119",
"pytest==6.2.5",
"coverage==7.5.3"
"coverage==7.5.3",
"pre-commit==3.7.1",
]

[project.scripts]
Expand Down

0 comments on commit add9239

Please sign in to comment.