Skip to content

Commit 1ec7026

Browse files
author
Paulo Ribeiro
authored
toolchain: Add pagination to check-security-tools.py DOCS-340 (codacy#1256)
* toolchain: Add .idea IDE files to .gitignore * fix: Review ignored tool UUIDs * fix: Implement simple pagination mechanism to fetch all code patterns * fix: Make sure that Pylint is detected
1 parent d7a5026 commit 1ec7026

File tree

3 files changed

+23
-11
lines changed

3 files changed

+23
-11
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ site/
77
# IDE files
88
.vscode
99
.metals
10+
.idea
1011

1112
# Backup files
1213
*.swp

tools/check-security-tools.py

+16-8
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@
88
DOCUMENTATION_PATH = "../docs/repositories/security-monitor.md"
99
ENDPOINT_URL_TOOLS = "https://api.codacy.com/api/v3/tools"
1010
ENDPOINT_URL_CODE_PATTERNS = Template("https://api.codacy.com/api/v3/tools/${toolUuid}/patterns")
11-
IGNORED_TOOL_UUIDS = ["647dddc1-17c4-4840-acea-4c2c2bbecb45", # Codacy Scalameta Pro
12-
"31677b6d-4ae0-4f56-8041-606a8d7a8e61", # Pylint 2 (Python 3)
13-
"cf05f3aa-fd23-4586-8cce-5368917ec3e5"] # ESLint 7 (deprecated)
11+
IGNORED_TOOL_UUIDS = ["34225275-f79e-4b85-8126-c7512c987c0d", # Pylint 1.9 (legacy)
12+
"cf05f3aa-fd23-4586-8cce-5368917ec3e5"] # ESLint 7 (deprecated)
1413

1514

1615
def check_security_tools():
@@ -24,16 +23,25 @@ def check_security_tools():
2423
continue
2524
tool_name = tool["name"]
2625
tool_short_name = tool["shortName"]
26+
# Hack to ensure that Pylint is detected
27+
if tool_short_name == "pylintpython3":
28+
tool_name = "Pylint"
2729
tool_languages = tool["languages"]
28-
code_patterns = requests.get(ENDPOINT_URL_CODE_PATTERNS.substitute(toolUuid=tool["uuid"])).json()["data"]
30+
r = requests.get(ENDPOINT_URL_CODE_PATTERNS.substitute(toolUuid=tool["uuid"]))
31+
code_patterns = r.json()["data"]
32+
cursor = r.json()["pagination"].get("cursor", False)
33+
while cursor:
34+
r = requests.get(ENDPOINT_URL_CODE_PATTERNS.substitute(toolUuid=tool["uuid"]) + f"?cursor={cursor}")
35+
code_patterns += r.json()["data"]
36+
cursor = r.json()["pagination"].get("cursor", False)
2937
for code_pattern in code_patterns:
3038
if code_pattern["category"] == "Security":
3139
if tool_name.lower() in documentation or tool_short_name.lower() in documentation:
32-
print(emoji.emojize(f":check_mark_button: {tool_name} is included "
33-
f"({', '.join(map(str, tool_languages))})"))
40+
print(emoji.emojize(f":check_mark_button: {tool_name} ({', '.join(map(str, tool_languages))}) "
41+
f"is included, checked {len(code_patterns)} patterns"))
3442
else:
35-
print(emoji.emojize(f":cross_mark: {tool_name} ISN'T included "
36-
f"({', '.join(map(str, tool_languages))})"))
43+
print(emoji.emojize(f":cross_mark: {tool_name} ({', '.join(map(str, tool_languages))}) "
44+
f"ISN'T included, checked {len(code_patterns)} patterns"))
3745
count += 1
3846
break
3947
if count:

tools/check-supported-tools.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55

66
DOCUMENTATION_PATH = "../docs/getting-started/supported-languages-and-tools.md"
77
ENDPOINT_URL = "https://api.codacy.com/api/v3/tools"
8-
IGNORED_TOOL_UUIDS = ["647dddc1-17c4-4840-acea-4c2c2bbecb45", # Codacy Scalameta Pro
9-
"31677b6d-4ae0-4f56-8041-606a8d7a8e61", # Pylint 2 (Python 3)
10-
"cf05f3aa-fd23-4586-8cce-5368917ec3e5"] # ESLint 7 (deprecated)
8+
IGNORED_TOOL_UUIDS = ["647dddc1-17c4-4840-acea-4c2c2bbecb45", # Codacy Scalameta Pro
9+
"34225275-f79e-4b85-8126-c7512c987c0d", # Pylint 1.9 (legacy)
10+
"cf05f3aa-fd23-4586-8cce-5368917ec3e5"] # ESLint 7 (deprecated)
1111

1212

1313
def check_supported_tools():
@@ -21,6 +21,9 @@ def check_supported_tools():
2121
continue
2222
tool_name = tool["name"]
2323
tool_short_name = tool["shortName"]
24+
# Hack to ensure that Pylint is detected
25+
if tool_short_name == "pylintpython3":
26+
tool_name = "Pylint"
2427
tool_languages = tool["languages"]
2528
if tool_name.lower() in documentation or tool_short_name.lower() in documentation:
2629
print(emoji.emojize(f":check_mark_button: {tool_name} is included "

0 commit comments

Comments
 (0)