Skip to content

Commit 57e7238

Browse files
authored
Merge pull request #12 from PaperMtn/feature/pylint-config
Feature/pylint config
2 parents 671688b + a4fc204 commit 57e7238

23 files changed

+124
-59
lines changed

poetry.lock

+6-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

+17
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,23 @@ pylint = "^3.3.1"
3232
[tool.poetry.scripts]
3333
gitlab-watchman = "gitlab_watchman:main"
3434

35+
[tool.pylint.messages_control]
36+
max-line-length = 120
37+
max-attributes = 10
38+
max-args = 10
39+
disable = [
40+
"missing-module-docstring",
41+
"too-few-public-methods",
42+
"arguments-differ",
43+
"logging-fstring-interpolation",
44+
"no-else-return",
45+
"no-else-raise",
46+
"inconsistent-return-statements",
47+
"broad-exception-caught",
48+
"duplicate-code",
49+
]
50+
51+
3552
[build-system]
3653
requires = ["poetry-core"]
3754
build-backend = "poetry.core.masonry.api"

src/gitlab_watchman/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ def validate_variables() -> bool:
116116
return True
117117

118118

119+
# pylint: disable=too-many-locals, missing-function-docstring, global-variable-undefined
120+
# pylint: disable=too-many-branches, disable=too-many-statements
119121
def main():
120122
global OUTPUT_LOGGER
121123
try:

src/gitlab_watchman/__main__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
from . import main
22

3-
main()
3+
main()

src/gitlab_watchman/clients/gitlab_client.py

-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
GitlabSearchError,
1515
GitlabHttpError
1616
)
17-
1817
from gitlab_watchman.exceptions import (
1918
GitLabWatchmanAuthenticationError,
2019
GitLabWatchmanGetObjectError,

src/gitlab_watchman/exceptions.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
from typing import Dict, Any
2-
31
class GitLabWatchmanError(Exception):
42
""" Base class for exceptions in GitLab Watchman.
53
"""
64

5+
76
class ElasticsearchMissingError(GitLabWatchmanError):
87
""" Exception raised when Elasticsearch is not enabled on the instance.
98
"""

src/gitlab_watchman/loggers.py

+32-19
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,28 @@
1616

1717

1818
class StdoutLogger:
19+
""" Class to log to stdout """
1920
def __init__(self, **kwargs):
2021
self.debug = kwargs.get('debug')
2122
self.print_header()
2223
init()
2324

25+
# pylint: disable=too-many-branches
2426
def log(self,
25-
mes_type: str,
27+
msg_level: str,
2628
message: Any,
2729
**kwargs) -> None:
30+
""" Log to stdout
31+
32+
Args:
33+
msg_level: Level message to log
34+
message: Message data to log
35+
"""
2836

2937
notify_type = kwargs.get('notify_type')
3038
scope = kwargs.get('scope')
3139

32-
if not self.debug and mes_type == 'DEBUG':
40+
if not self.debug and msg_level == 'DEBUG':
3341
return
3442

3543
if dataclasses.is_dataclass(message):
@@ -44,7 +52,7 @@ def log(self,
4452
f' URL: {message.get("kas").get("externalUrl")} \n'\
4553
f' VERSION: {message.get("kas").get("version")} \n' \
4654
f' ENTERPRISE: {message.get("enterprise")}'
47-
mes_type = 'INSTANCE'
55+
msg_level = 'INSTANCE'
4856
if notify_type == "user":
4957
message = f'USER: \n' \
5058
f' ID: {message.get("id")} \n' \
@@ -57,7 +65,7 @@ def log(self,
5765
f' CAN_CREATE_GROUP: {message.get("can_create_group")} \n'\
5866
f' CAN_CREATE_PROJECT: {message.get("can_create_project")} \n' \
5967
f' 2FA_ENABLED: {message.get("two_factor_enabled")}'
60-
mes_type = 'USER'
68+
msg_level = 'USER'
6169
if notify_type == "token":
6270
message = f'PERSONAL_ACCESS_TOKEN: \n' \
6371
f' ID: {message.get("id")} \n' \
@@ -68,7 +76,7 @@ def log(self,
6876
f' LAST_USED_AT: {message.get("last_used_at")} \n' \
6977
f' ACTIVE: {message.get("active")} \n'\
7078
f' EXPIRY: {message.get("expires_at", "Never")}'
71-
mes_type = 'WARNING'
79+
msg_level = 'WARNING'
7280
if notify_type == "result":
7381
if scope == 'blobs':
7482
message = 'SCOPE: Blob' \
@@ -145,12 +153,12 @@ def log(self,
145153
f' URL: {message.get("snippet").get("web_url")} \n' \
146154
f' POTENTIAL_SECRET: {message.get("match_string")} \n' \
147155
f' -----'
148-
mes_type = 'RESULT'
156+
msg_level = 'RESULT'
149157
try:
150-
self.log_to_stdout(message, mes_type)
158+
self.log_to_stdout(message, msg_level)
151159
except Exception as e:
152160
print(e)
153-
self.log_to_stdout(message, mes_type)
161+
self.log_to_stdout(message, msg_level)
154162

155163
def log_to_stdout(self,
156164
message: Any,
@@ -236,7 +244,10 @@ def log_to_stdout(self,
236244
sys.exit(1)
237245
print('Formatting error')
238246

239-
def print_header(self) -> None:
247+
@staticmethod
248+
def print_header() -> None:
249+
""" Prints the header for the logger"""
250+
240251
print(" ".ljust(79) + Style.BRIGHT)
241252

242253
print(Fore.LIGHTRED_EX + Style.BRIGHT +
@@ -265,6 +276,7 @@ def print_header(self) -> None:
265276

266277

267278
class JSONLogger(Logger):
279+
""" Custom logger class for JSON logging"""
268280
def __init__(self, name: str = 'gitlab_watchman', **kwargs):
269281
super().__init__(name)
270282
self.notify_format = logging.Formatter(
@@ -290,41 +302,42 @@ def __init__(self, name: str = 'gitlab_watchman', **kwargs):
290302

291303
def log(self,
292304
level: str,
293-
log_data: str or Dict,
305+
msg: str or Dict,
294306
**kwargs):
295307
if level.upper() == 'NOTIFY':
296308
self.handler.setFormatter(self.notify_format)
297309
self.logger.info(
298310
json.dumps(
299-
log_data,
311+
msg,
300312
cls=EnhancedJSONEncoder),
301313
extra={
302314
'scope': kwargs.get('scope', ''),
303315
'type': kwargs.get('detect_type', ''),
304316
'severity': kwargs.get('severity', '')})
305317
elif level.upper() == 'INFO':
306318
self.handler.setFormatter(self.info_format)
307-
self.logger.info(json.dumps(log_data))
319+
self.logger.info(json.dumps(msg))
308320
elif level.upper() == 'DEBUG':
309321
self.handler.setFormatter(self.info_format)
310-
self.logger.info(json.dumps(log_data))
322+
self.logger.info(json.dumps(msg))
311323
elif level.upper() == 'SUCCESS':
312324
self.handler.setFormatter(self.success_format)
313-
self.logger.info(json.dumps(log_data))
325+
self.logger.info(json.dumps(msg))
314326
elif level.upper() == 'INSTANCE':
315327
self.handler.setFormatter(self.instance_format)
316-
self.logger.info(json.dumps(log_data))
328+
self.logger.info(json.dumps(msg))
317329
elif level.upper() == 'USER':
318330
self.handler.setFormatter(self.user_format)
319-
self.logger.info(json.dumps(log_data))
331+
self.logger.info(json.dumps(msg))
320332
elif level.upper() == 'TOKEN':
321333
self.handler.setFormatter(self.token_format)
322-
self.logger.info(json.dumps(log_data))
334+
self.logger.info(json.dumps(msg))
323335
else:
324336
self.handler.setFormatter(self.info_format)
325-
self.logger.critical(log_data)
337+
self.logger.critical(msg)
326338

327339

340+
# pylint: disable=missing-class-docstring
328341
class IsDataclass(Protocol):
329342
__dataclass_fields__: ClassVar[Dict]
330343

@@ -360,4 +373,4 @@ def init_logger(logging_type: str, debug: bool) -> JSONLogger | StdoutLogger:
360373

361374
if not logging_type or logging_type == 'stdout':
362375
return StdoutLogger(debug=debug)
363-
return JSONLogger(debug=debug)
376+
return JSONLogger(debug=debug)

src/gitlab_watchman/models/blob.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33

44
@dataclass(slots=True)
5-
class Blob(object):
5+
class Blob:
66
""" Class that defines Blob objects for GitLab blobs"""
77

88
basename: str

src/gitlab_watchman/models/commit.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55

66

77
@dataclass(slots=True)
8-
class Commit(object):
8+
# pylint: disable=too-many-instance-attributes
9+
class Commit:
910
""" Class that defines File objects for GitLab files"""
1011

1112
id: str

src/gitlab_watchman/models/file.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33

44
@dataclass(slots=True)
5-
class File(object):
5+
class File:
66
""" Class that defines File objects for GitLab files"""
77

88
file_name: str

src/gitlab_watchman/models/group.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55

66

77
@dataclass(slots=True)
8-
class Group(object):
8+
# pylint: disable=too-many-instance-attributes
9+
class Group:
910
""" Class that defines User objects for GitLab groups"""
1011

1112
id: str

src/gitlab_watchman/models/issue.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66

77

88
@dataclass(slots=True)
9-
class Issue(object):
9+
# pylint: disable=too-many-instance-attributes
10+
class Issue:
1011
""" Class that defines Issues objects for GitLab issues"""
1112

1213
id: str

src/gitlab_watchman/models/merge_request.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66

77

88
@dataclass(slots=True)
9-
class MergeRequest(object):
9+
# pylint: disable=too-many-instance-attributes
10+
class MergeRequest:
1011
""" Class that defines MergeRequest objects for GitLab merge requests"""
1112

1213
id: str

src/gitlab_watchman/models/milestone.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55

66

77
@dataclass(slots=True)
8-
class Milestone(object):
8+
# pylint: disable=too-many-instance-attributes
9+
class Milestone:
910
""" Class that defines Milestone objects for GitLab milestones"""
1011

1112
id: str

src/gitlab_watchman/models/note.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66

77

88
@dataclass(slots=True)
9-
class Note(object):
9+
# pylint: disable=too-many-instance-attributes
10+
class Note:
1011
""" Class that defines User objects for GitLab notes"""
1112

1213
id: str

src/gitlab_watchman/models/project.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77

88

99
@dataclass(slots=True)
10-
class Namespace(object):
10+
class Namespace:
11+
""" Class that defines Namespace objects for GitLab Projects"""
1112
id: str
1213
name: str
1314
path: str
@@ -20,7 +21,7 @@ class Namespace(object):
2021

2122

2223
@dataclass(slots=True)
23-
class Project(object):
24+
class Project:
2425
""" Class that defines User objects for GitLab projects"""
2526

2627
id: str

src/gitlab_watchman/models/signature.py

+7-8
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
import datetime
2-
from typing import Any, Dict
2+
from typing import Any, Dict, List
33
from dataclasses import dataclass
4-
from typing import List
54

65

76
@dataclass(slots=True)
8-
class TestCases(object):
7+
class TestCases:
8+
""" Class that holds test cases for a signature """
99
match_cases: list
1010
fail_cases: list
1111

1212

1313
@dataclass(frozen=True, slots=True)
14+
# pylint: disable=too-many-instance-attributes
1415
class Signature:
1516
""" Class that handles loaded signature objects. Signatures
1617
define what to search for in Slack and where to search for it.
@@ -36,15 +37,13 @@ def __post_init__(self):
3637
raise TypeError(f'Expected `status` to be of type str, received {type(self.status).__name__}')
3738
if self.author and not isinstance(self.author, str):
3839
raise TypeError(f'Expected `author` to be of type str, received {type(self.author).__name__}')
39-
if self.date and not (isinstance(self.date, datetime.date)
40-
or isinstance(self.date, str)
41-
or isinstance(self.date, datetime.datetime)):
40+
if self.date and not isinstance(self.date, (datetime.date, datetime.datetime, str)):
4241
raise TypeError(f'Expected `date` to be of type str, received {type(self.date).__name__}')
4342
if self.version and not isinstance(self.version, str):
4443
raise TypeError(f'Expected `version` to be of type str, received {type(self.version).__name__}')
4544
if self.description and not isinstance(self.description, str):
4645
raise TypeError(f'Expected `description` to be of type str, received {type(self.description).__name__}')
47-
if self.severity and not (isinstance(self.severity, int) or isinstance(self.severity, str)):
46+
if self.severity and not isinstance(self.severity, (int, str)):
4847
raise TypeError(f'Expected `severity` to be of type int or str, received {type(self.severity).__name__}')
4948
if self.scope and not isinstance(self.scope, list):
5049
raise TypeError(f'Expected `scope` to be of type list, received {type(self.scope).__name__}')
@@ -79,4 +78,4 @@ def create_from_dict(signature_dict: Dict[str, Any]) -> Signature:
7978
fail_cases=signature_dict.get('test_cases', {}).get('fail_cases')
8079
),
8180
search_strings=signature_dict.get('watchman_apps', {}).get('gitlab', {}).get('search_strings'),
82-
patterns=signature_dict.get('patterns'))
81+
patterns=signature_dict.get('patterns'))

0 commit comments

Comments
 (0)