Skip to content

Commit 0d5a1a3

Browse files
committed
merge
2 parents 5995b07 + 44ebe9a commit 0d5a1a3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+1523
-1003
lines changed

.gitattributes

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
*.gz filter=lfs diff=lfs merge=lfs -text
1+
*.gz filter=lfs diff=lfs merge=lfs -text

.github/workflows/analisys.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@ name: Python analisys
33
on: [push, pull_request]
44

55
jobs:
6-
prospector:
6+
ruff:
77
runs-on: ubuntu-latest
88
steps:
99
- uses: actions/checkout@v2
10-
- name: Set up Python 3.11
10+
- name: Set up Python 3.12
1111
uses: actions/setup-python@v2
1212
with:
13-
python-version: '3.11'
13+
python-version: '3.12'
1414
- name: Install dependencies
1515
run: |
1616
python -m pip install --upgrade pip
1717
pip install -r requirements.txt
18-
pip install prospector[with_everything]==1.10.2
19-
- name: Analysing the code with prospector
18+
pip install ruff==0.1.5
19+
- name: Analysing the code with ruff
2020
run: |
21-
prospector
21+
ruff check .

.github/workflows/github-release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,4 @@ jobs:
3535
token: ${{secrets.GIT_TOKEN}}
3636
prerelease: ${{steps.get_variables.outputs.IS_PRERELEASE}}
3737
tag_name: ${{steps.get_variables.outputs.VERSION}}
38-
body: ${{steps.changelog.outputs.changes}}
38+
body: ${{steps.changelog.outputs.changes}}

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,4 +130,4 @@ venv.bak/
130130
dmypy.json
131131

132132
# Pyre type checker
133-
.pyre/
133+
.pyre/

.prospector.yaml

Lines changed: 0 additions & 27 deletions
This file was deleted.

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ RUN pip install -r requirements.txt
1212

1313
EXPOSE 8000
1414

15-
CMD uvicorn app.main:app --host 0.0.0.0 --port 8000
15+
CMD uvicorn app.main:app --host 0.0.0.0 --port 8000

app/apis/__init__.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
from .github_service import get_last_commit_date_github, get_repo_data
2+
from .gitlab_service import get_last_commit_date_gitlab
13
from .manager_service import get_all_versions, requires_packages
2-
from .git_service import get_repo_data, get_last_commit_date
34

45
__all__ = [
5-
'get_all_versions',
6-
'requires_packages',
7-
'get_repo_data',
8-
'get_last_commit_date'
9-
]
6+
"get_all_versions",
7+
"requires_packages",
8+
"get_repo_data",
9+
"get_last_commit_date_github",
10+
"get_last_commit_date_gitlab",
11+
]

app/apis/git_service.py

Lines changed: 0 additions & 96 deletions
This file was deleted.

app/apis/github_service.py

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
from datetime import datetime
2+
from time import sleep
3+
from typing import Any
4+
5+
from dateutil.parser import parse
6+
from requests import ConnectionError, ConnectTimeout, post
7+
8+
from app.config import settings
9+
from app.utils import get_manager, parse_pip_constraints
10+
11+
headers_github = {
12+
"Accept": "application/vnd.github.hawkgirl-preview+json",
13+
"Authorization": f"Bearer {settings.GITHUB_GRAPHQL_API_KEY}",
14+
}
15+
16+
17+
async def get_repo_data(
18+
owner: str,
19+
name: str,
20+
all_packages: dict[str, Any] | None = None,
21+
end_cursor: str | None = None,
22+
) -> dict[str, Any]:
23+
if not all_packages:
24+
all_packages = {}
25+
if not end_cursor:
26+
query = f"""
27+
{{
28+
repository(owner: "{owner}", name: "{name}") {{
29+
dependencyGraphManifests {{
30+
nodes {{
31+
filename
32+
dependencies {{
33+
pageInfo {{
34+
hasNextPage
35+
endCursor
36+
}}
37+
nodes {{
38+
packageName
39+
requirements
40+
}}
41+
}}
42+
}}
43+
}}
44+
}}
45+
}}
46+
"""
47+
else:
48+
query = f"""
49+
{{
50+
repository(owner: "{owner}", name: "{name}") {{
51+
dependencyGraphManifests {{
52+
nodes {{
53+
filename
54+
dependencies (after: "{end_cursor}") {{
55+
pageInfo {{
56+
hasNextPage
57+
endCursor
58+
}}
59+
nodes {{
60+
packageName
61+
requirements
62+
}}
63+
}}
64+
}}
65+
}}
66+
}}
67+
}}
68+
"""
69+
while True:
70+
try:
71+
response = post(
72+
"https://api.github.com/graphql",
73+
json={"query": query},
74+
headers=headers_github,
75+
).json()
76+
break
77+
except (ConnectTimeout, ConnectionError):
78+
sleep(5)
79+
page_info, all_packages = await json_reader(response, all_packages)
80+
if not page_info["hasNextPage"]:
81+
return all_packages
82+
return await get_repo_data(owner, name, all_packages, page_info["endCursor"])
83+
84+
85+
async def json_reader(
86+
response: Any, all_packages: dict[str, Any]
87+
) -> tuple[dict[str, Any], dict[str, Any]]:
88+
page_info = {"hasNextPage": None}
89+
for file_node in response["data"]["repository"]["dependencyGraphManifests"][
90+
"nodes"
91+
]:
92+
requirement_file_name = file_node["filename"]
93+
if requirement_file_name == "package-lock.json":
94+
continue
95+
page_info = file_node["dependencies"]["pageInfo"]
96+
requirement_file_manager = await get_manager(requirement_file_name)
97+
if not requirement_file_manager:
98+
continue
99+
if requirement_file_name not in all_packages:
100+
all_packages[requirement_file_name] = {
101+
"package_manager": requirement_file_manager,
102+
"dependencies": {},
103+
}
104+
for depependency_node in file_node["dependencies"]["nodes"]:
105+
if requirement_file_manager == "MVN":
106+
if "=" in depependency_node["requirements"]:
107+
depependency_node["requirements"] = (
108+
"["
109+
+ depependency_node["requirements"]
110+
.replace("=", "")
111+
.replace(" ", "")
112+
+ "]"
113+
)
114+
if requirement_file_manager == "PIP":
115+
depependency_node["requirements"] = await parse_pip_constraints(
116+
depependency_node["requirements"]
117+
)
118+
all_packages[requirement_file_name]["dependencies"].update(
119+
{depependency_node["packageName"]: depependency_node["requirements"]}
120+
)
121+
return (page_info, all_packages)
122+
123+
124+
async def get_last_commit_date_github(owner: str, name: str) -> datetime:
125+
query = f"""
126+
{{
127+
repository(owner: "{owner}", name: "{name}") {{
128+
defaultBranchRef {{
129+
target {{
130+
... on Commit {{
131+
history(first: 1) {{
132+
edges {{
133+
node {{
134+
author {{
135+
date
136+
}}
137+
}}
138+
}}
139+
}}
140+
}}
141+
}}
142+
}}
143+
}}
144+
}}
145+
"""
146+
while True:
147+
try:
148+
response = post(
149+
"https://api.github.com/graphql",
150+
json={"query": query},
151+
headers=headers_github,
152+
).json()
153+
break
154+
except (ConnectTimeout, ConnectionError):
155+
sleep(5)
156+
return parse(
157+
response["data"]["repository"]["defaultBranchRef"]["target"]["history"][
158+
"edges"
159+
][0]["node"]["author"]["date"]
160+
)

app/apis/gitlab_service.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
from datetime import datetime
2+
from time import sleep
3+
4+
from dateutil.parser import parse
5+
from requests import ConnectionError, ConnectTimeout, post
6+
7+
from app.config import settings
8+
9+
headers_gitlab = {
10+
"Content-Type": "application/json",
11+
"Authorization": f"Bearer {settings.GITLAB_GRAPHQL_API_KEY}",
12+
}
13+
14+
15+
async def get_last_commit_date_gitlab(owner: str, name: str) -> datetime:
16+
query = f"""
17+
{{
18+
project(fullPath: "{owner}/{name}") {{
19+
lastActivityAt
20+
}}
21+
}}
22+
"""
23+
while True:
24+
try:
25+
response = post(
26+
"https://gitlab.com/api/graphql",
27+
json={"query": query},
28+
headers=headers_gitlab,
29+
).json()
30+
break
31+
except (ConnectTimeout, ConnectionError):
32+
sleep(5)
33+
return parse(response["data"]["project"]["lastActivityAt"])

0 commit comments

Comments
 (0)