Skip to content

Commit bed62be

Browse files
authored
Merge pull request #56 from GitGuardian/agateau/enforce-precommits
Enforce precommits
2 parents 0c54209 + 37fb9cd commit bed62be

File tree

8 files changed

+43
-47
lines changed

8 files changed

+43
-47
lines changed

.github/workflows/test-lint.yml

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,25 @@ jobs:
2020
uses: actions/setup-python@v1
2121
with:
2222
python-version: 3.9
23+
2324
- name: Install dependencies
2425
run: |
2526
python -m pip install --upgrade pip
26-
python -m pip install --upgrade pipenv==2022.10.4
27-
pipenv install --dev --system --skip-lock
28-
- name: Lint with flake8
29-
run: |
30-
pipenv run flake8
31-
- name: Lint with black
32-
run: |
33-
pipenv run black .
27+
python -m pip install --upgrade pipenv==2022.10.4 pre-commit
28+
pipenv install --system --skip-lock
29+
30+
- uses: actions/cache@v3
31+
with:
32+
path: ~/.cache/pre-commit
33+
key: pre-commit|${{ env.pythonLocation }}|${{ hashFiles('.pre-commit-config.yaml') }}
34+
35+
- name: Install pre-commit hooks
36+
run: pre-commit install --install-hooks
37+
38+
- name: Run pre-commit checks
39+
run: pre-commit run --show-diff-on-failure --all-files
40+
env:
41+
GITGUARDIAN_API_KEY: ${{ secrets.GITGUARDIAN_API_KEY }}
3442

3543
build:
3644
runs-on: ${{ matrix.os }}

Makefile

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,16 @@ SHELL :=/bin/bash
55
test ?= tests
66

77
all:
8-
echo "Usage :"
9-
echo " make test" # Run tests
10-
echo " make coverage" # Run tests and coverage
11-
echo " make black" # Run black formatter on python code
12-
echo " make flake8" # Run flake8 linter on python code
13-
echo " make isort" # Run isort linter on python code
8+
echo "Targets:"
9+
echo " test Run tests"
10+
echo " coverage Run tests with coverage"
11+
echo " lint Run all linters"
1412

1513
test:
1614
pipenv run pytest --disable-pytest-warnings -vvv $(test)
1715

1816
coverage:
1917
pipenv run coverage run --source pygitguardian -m pytest --disable-pytest-warnings && pipenv run coverage report --fail-under=80
2018

21-
black:
22-
pipenv run black .
23-
24-
flake8:
25-
pipenv run flake8
26-
27-
isort:
28-
pipenv run isort **/*.py
19+
lint:
20+
pre-commit run --all
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
### Added
32

43
- Add `GGClient.create_honeytoken()` method.
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
### Changed
32

43
- Add `gitguardian_url` and change id type of `honeytoken`'s model.

pygitguardian/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ def get(
252252
def post(
253253
self,
254254
endpoint: str,
255-
data: Optional[Dict[str, str]] = None,
255+
data: Optional[Dict[str, Any]] = None,
256256
version: str = DEFAULT_API_VERSION,
257257
extra_headers: Optional[Dict[str, str]] = None,
258258
**kwargs: Any,

pygitguardian/models.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def rename_errors(self, data: Dict, many: bool, **kwargs: Any) -> Dict:
118118
return data
119119

120120
@post_load
121-
def make_detail_response(self, data: Dict[str, str], **kwargs: Any) -> "Detail":
121+
def make_detail_response(self, data: Dict[str, Any], **kwargs: Any) -> "Detail":
122122
return Detail(**data)
123123

124124

@@ -132,7 +132,9 @@ class Detail(Base):
132132

133133
SCHEMA = DetailSchema()
134134

135-
def __init__(self, detail: str, status_code: Optional[int] = None, **kwargs: Any) -> None:
135+
def __init__(
136+
self, detail: str, status_code: Optional[int] = None, **kwargs: Any
137+
) -> None:
136138
super().__init__(status_code=status_code)
137139
self.detail = detail
138140

tests/test_client.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -672,8 +672,7 @@ def test_create_honeytoken(
672672
"name": "honeytoken A",
673673
"description": "honeytoken used in the repository AA",
674674
"created_at": "2019-08-22T14:15:22Z",
675-
"gitguardian_url":
676-
"https://dashboard.gitguardian.com/workspace/1/honeytokens/d45a123f-b15d-4fea-abf6-ff2a8479de5b",
675+
"gitguardian_url": "https://dashboard.gitguardian.com/workspace/1/honeytokens/d45a123f-b15d-4fea-abf6-ff2a8479de5b", # noqa: E501
677676
"status": "active",
678677
"triggered_at": "2019-08-22T14:15:22Z",
679678
"revoked_at": None,
@@ -683,18 +682,17 @@ def test_create_honeytoken(
683682
"revoker_id": None,
684683
"creator_api_token_id": None,
685684
"revoker_api_token_id": None,
686-
"token": {
687-
"access_token_id": "AAAA",
688-
"secret_key": "BBB"
689-
},
690-
"tags": ["publicly_exposed"]
685+
"token": {"access_token_id": "AAAA", "secret_key": "BBB"},
686+
"tags": ["publicly_exposed"],
691687
}
692688

693689
request_mock.return_value = mock_response
694690

695-
result = client.create_honeytoken(name="honeytoken A",
696-
description="honeytoken used in the repository AA",
697-
type_="AWS")
691+
result = client.create_honeytoken(
692+
name="honeytoken A",
693+
description="honeytoken used in the repository AA",
694+
type_="AWS",
695+
)
698696

699697
assert request_mock.called
700698
assert isinstance(result, HoneytokenResponse)
@@ -719,9 +717,11 @@ def test_create_honeytoken_error(
719717

720718
request_mock.return_value = mock_response
721719

722-
result = client.create_honeytoken(name="honeytoken A",
723-
description="honeytoken used in the repository AA",
724-
type_="AWS")
720+
result = client.create_honeytoken(
721+
name="honeytoken A",
722+
description="honeytoken used in the repository AA",
723+
type_="AWS",
724+
)
725725

726726
assert request_mock.called
727727
assert isinstance(result, Detail)

tests/test_models.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,7 @@ def test_document_handle_surrogates(self):
145145
"name": "honeytoken A",
146146
"description": "honeytoken used in the repository AA",
147147
"created_at": "2019-08-22T14:15:22Z",
148-
"gitguardian_url":
149-
"https://dashboard.gitguardian.com/workspace/1/honeytokens/d45a123f-b15d-4fea-abf6-ff2a8479de5b",
148+
"gitguardian_url": "https://dashboard.gitguardian.com/workspace/1/honeytokens/d45a123f-b15d-4fea-abf6-ff2a8479de5b", # noqa: E501
150149
"status": "active",
151150
"triggered_at": "2019-08-22T14:15:22Z",
152151
"revoked_at": None,
@@ -156,11 +155,8 @@ def test_document_handle_surrogates(self):
156155
"revoker_id": None,
157156
"creator_api_token_id": None,
158157
"revoker_api_token_id": None,
159-
"token": {
160-
"access_token_id": "AAAA",
161-
"secret_key": "BBB"
162-
},
163-
"tags": ["publicly_exposed"]
158+
"token": {"access_token_id": "AAAA", "secret_key": "BBB"},
159+
"tags": ["publicly_exposed"],
164160
},
165161
),
166162
],

0 commit comments

Comments
 (0)