commons-metrics 0.0.22__py3-none-any.whl → 0.0.24__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- commons_metrics/__init__.py +1 -1
- commons_metrics/azure_devops_client.py +3 -3
- commons_metrics/github_api_client.py +53 -5
- {commons_metrics-0.0.22.dist-info → commons_metrics-0.0.24.dist-info}/METADATA +1 -1
- {commons_metrics-0.0.22.dist-info → commons_metrics-0.0.24.dist-info}/RECORD +8 -8
- {commons_metrics-0.0.22.dist-info → commons_metrics-0.0.24.dist-info}/WHEEL +0 -0
- {commons_metrics-0.0.22.dist-info → commons_metrics-0.0.24.dist-info}/licenses/LICENSE +0 -0
- {commons_metrics-0.0.22.dist-info → commons_metrics-0.0.24.dist-info}/top_level.txt +0 -0
commons_metrics/__init__.py
CHANGED
|
@@ -12,4 +12,4 @@ from .text_simplifier import TextSimplifier
|
|
|
12
12
|
from .variable_finder import VariableFinder
|
|
13
13
|
|
|
14
14
|
__all__ = ['Util', 'DatabaseConnection', 'ComponentRepository', 'UpdateDesignSystemComponents', 'GitHubAPIClient', 'AzureDevOpsClient', 'S3FileManager', 'CacheManager', 'CommonsReposClient', 'DateUtils', 'TextSimplifier', 'VariableFinder']
|
|
15
|
-
__version__ = '0.0.
|
|
15
|
+
__version__ = '0.0.24'
|
|
@@ -5,7 +5,7 @@ import re
|
|
|
5
5
|
from typing import List, Dict, Optional
|
|
6
6
|
from requests.exceptions import HTTPError, Timeout, ConnectionError
|
|
7
7
|
import urllib3
|
|
8
|
-
from .commons_repos_client import
|
|
8
|
+
from .commons_repos_client import CommonsReposClient
|
|
9
9
|
|
|
10
10
|
# Suprimir warnings de SSL para Azure DevOps con certificados corporativos
|
|
11
11
|
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
|
|
@@ -383,11 +383,11 @@ class AzureDevOpsClient:
|
|
|
383
383
|
if platform == 'mobile':
|
|
384
384
|
config_file = 'pubspec.yaml'
|
|
385
385
|
default_package_name = 'bds_mobile'
|
|
386
|
-
extract_version_method = extract_package_version_from_pubspec
|
|
386
|
+
extract_version_method = CommonsReposClient.extract_package_version_from_pubspec
|
|
387
387
|
else: # web
|
|
388
388
|
config_file = 'package.json'
|
|
389
389
|
default_package_name = '@bancolombia/design-system-web'
|
|
390
|
-
extract_version_method = extract_package_version_from_package_json
|
|
390
|
+
extract_version_method = CommonsReposClient.extract_package_version_from_package_json
|
|
391
391
|
|
|
392
392
|
# Usar nombre de paquete por defecto si no se proporciona
|
|
393
393
|
package_name = design_system_name or default_package_name
|
|
@@ -1,15 +1,46 @@
|
|
|
1
1
|
import requests
|
|
2
2
|
import base64
|
|
3
|
+
import time
|
|
4
|
+
from threading import Lock
|
|
3
5
|
from typing import List, Dict, Optional
|
|
4
6
|
import os
|
|
5
|
-
from .commons_repos_client import
|
|
7
|
+
from .commons_repos_client import CommonsReposClient
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class RateLimiter:
|
|
11
|
+
"""
|
|
12
|
+
Controla el rate limiting para respetar los límites de API de GitHub.
|
|
13
|
+
GitHub permite 5000 requests/hora autenticados = ~1.4 TPS.
|
|
14
|
+
Usamos 720ms entre requests (1.39 TPS) para estar seguros.
|
|
15
|
+
"""
|
|
16
|
+
def __init__(self, delay: float = 0.72):
|
|
17
|
+
self.delay = delay
|
|
18
|
+
self.last_request_time = 0
|
|
19
|
+
self.lock = Lock()
|
|
20
|
+
|
|
21
|
+
def wait(self):
|
|
22
|
+
"""Espera el tiempo necesario antes de hacer el siguiente request"""
|
|
23
|
+
with self.lock:
|
|
24
|
+
current_time = time.time()
|
|
25
|
+
time_since_last_request = current_time - self.last_request_time
|
|
26
|
+
|
|
27
|
+
if time_since_last_request < self.delay:
|
|
28
|
+
sleep_time = self.delay - time_since_last_request
|
|
29
|
+
time.sleep(sleep_time)
|
|
30
|
+
|
|
31
|
+
self.last_request_time = time.time()
|
|
32
|
+
|
|
6
33
|
|
|
7
34
|
class GitHubAPIClient:
|
|
8
35
|
"""
|
|
9
|
-
Cliente para interactuar con la API de GitHub
|
|
36
|
+
Cliente para interactuar con la API de GitHub con rate limiting integrado.
|
|
37
|
+
Controla automáticamente el TPS para no exceder los límites de GitHub (5000 req/hora).
|
|
10
38
|
"""
|
|
11
39
|
|
|
12
|
-
|
|
40
|
+
# Rate limiter compartido entre todas las instancias
|
|
41
|
+
_rate_limiter = RateLimiter(delay=0.72) # 720ms entre requests = 1.39 TPS
|
|
42
|
+
|
|
43
|
+
def __init__(self, token: str, owner: str = None, repo: str = None, enable_rate_limit: bool = True):
|
|
13
44
|
"""
|
|
14
45
|
Inicializa el cliente de GitHub API
|
|
15
46
|
|
|
@@ -17,10 +48,12 @@ class GitHubAPIClient:
|
|
|
17
48
|
token: Personal Access Token de GitHub
|
|
18
49
|
owner: Dueño del repositorio (ej: 'grupobancolombia-innersource') - Opcional
|
|
19
50
|
repo: Nombre del repositorio (ej: 'NU0066001_BDS_MOBILE_Lib') - Opcional
|
|
51
|
+
enable_rate_limit: Si True, aplica rate limiting automático (por defecto True)
|
|
20
52
|
"""
|
|
21
53
|
self.token = token
|
|
22
54
|
self.owner = owner
|
|
23
55
|
self.repo = repo
|
|
56
|
+
self.enable_rate_limit = enable_rate_limit
|
|
24
57
|
self.base_url = f"https://api.github.com/repos/{owner}/{repo}" if owner and repo else "https://api.github.com"
|
|
25
58
|
self.headers = {
|
|
26
59
|
"Authorization": f"token {token}",
|
|
@@ -37,6 +70,9 @@ class GitHubAPIClient:
|
|
|
37
70
|
Returns:
|
|
38
71
|
Lista de diccionarios con información de archivos/carpetas
|
|
39
72
|
"""
|
|
73
|
+
if self.enable_rate_limit:
|
|
74
|
+
self._rate_limiter.wait()
|
|
75
|
+
|
|
40
76
|
url = f"{self.base_url}/contents/{path}"
|
|
41
77
|
response = requests.get(url, headers=self.headers)
|
|
42
78
|
|
|
@@ -57,6 +93,9 @@ class GitHubAPIClient:
|
|
|
57
93
|
Returns:
|
|
58
94
|
Contenido del archivo como string, o None si no existe
|
|
59
95
|
"""
|
|
96
|
+
if self.enable_rate_limit:
|
|
97
|
+
self._rate_limiter.wait()
|
|
98
|
+
|
|
60
99
|
url = f"{self.base_url}/contents/{path}"
|
|
61
100
|
response = requests.get(url, headers=self.headers)
|
|
62
101
|
|
|
@@ -150,6 +189,9 @@ class GitHubAPIClient:
|
|
|
150
189
|
page = 1
|
|
151
190
|
|
|
152
191
|
while True:
|
|
192
|
+
if self.enable_rate_limit:
|
|
193
|
+
self._rate_limiter.wait()
|
|
194
|
+
|
|
153
195
|
url = "https://api.github.com/search/code"
|
|
154
196
|
params = {
|
|
155
197
|
'q': query,
|
|
@@ -207,11 +249,11 @@ class GitHubAPIClient:
|
|
|
207
249
|
if platform == 'mobile':
|
|
208
250
|
config_file = 'pubspec.yaml'
|
|
209
251
|
default_package_name = 'bds_mobile'
|
|
210
|
-
extract_version_method = extract_package_version_from_pubspec
|
|
252
|
+
extract_version_method = CommonsReposClient.extract_package_version_from_pubspec
|
|
211
253
|
else: # web
|
|
212
254
|
config_file = 'package.json'
|
|
213
255
|
default_package_name = '@bancolombia/design-system-web'
|
|
214
|
-
extract_version_method = extract_package_version_from_package_json
|
|
256
|
+
extract_version_method = CommonsReposClient.extract_package_version_from_package_json
|
|
215
257
|
|
|
216
258
|
# Usar nombre de paquete por defecto si no se proporciona
|
|
217
259
|
package_name = design_system_name or default_package_name
|
|
@@ -255,6 +297,9 @@ class GitHubAPIClient:
|
|
|
255
297
|
search_url = "https://api.github.com/search/repositories"
|
|
256
298
|
|
|
257
299
|
while True:
|
|
300
|
+
if self.enable_rate_limit:
|
|
301
|
+
self._rate_limiter.wait()
|
|
302
|
+
|
|
258
303
|
params = {
|
|
259
304
|
'q': query,
|
|
260
305
|
'per_page': per_page,
|
|
@@ -294,6 +339,9 @@ class GitHubAPIClient:
|
|
|
294
339
|
Returns:
|
|
295
340
|
Contenido del archivo como string, o None si no existe
|
|
296
341
|
"""
|
|
342
|
+
if self.enable_rate_limit:
|
|
343
|
+
self._rate_limiter.wait()
|
|
344
|
+
|
|
297
345
|
response = requests.get(api_url, headers=self.headers)
|
|
298
346
|
|
|
299
347
|
if response.status_code == 200:
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
commons_metrics/__init__.py,sha256=
|
|
2
|
-
commons_metrics/azure_devops_client.py,sha256=
|
|
1
|
+
commons_metrics/__init__.py,sha256=xt4Tm9YIRbfAwr9oKzjoH6lNHX4LuDZJXJE7UIgeUqc,796
|
|
2
|
+
commons_metrics/azure_devops_client.py,sha256=XrGqhr4voFUtGkdB27tnzsMSiNdpfY4stQUU51e1a0U,16755
|
|
3
3
|
commons_metrics/cache_manager.py,sha256=HOeup9twUizjJAbh1MNXdPT8BMVeLFoolOWlAzMTXkE,2651
|
|
4
4
|
commons_metrics/commons_repos_client.py,sha256=PiAMLWuDnI8AlZzE3sfQ3s2P23UrYbbqaq63AFRroHc,4695
|
|
5
5
|
commons_metrics/database.py,sha256=wzcrK8q09J28NMLExkhWy8w7N2fQPkckrGf62C9rdQ0,1989
|
|
6
6
|
commons_metrics/date_utils.py,sha256=8465712QJDGcshqry97Gi90lbMEbvbX3uiuHRVwGHbE,2654
|
|
7
|
-
commons_metrics/github_api_client.py,sha256=
|
|
7
|
+
commons_metrics/github_api_client.py,sha256=2gynYtEzPxDETX-KRshCHLvP4AsRceSrRd-7VWSfUNc,13200
|
|
8
8
|
commons_metrics/repositories.py,sha256=47JK9rhcpx_X6RWRkM3768qTwk39ODm8LLvi6QzZDdQ,9480
|
|
9
9
|
commons_metrics/s3_file_manager.py,sha256=Mm7vlPJeXB46LnCXFs9oz7PQezcIcgYLlSJqMzVf72g,3384
|
|
10
10
|
commons_metrics/text_simplifier.py,sha256=jRYckQ5APR0A3wY4hg70kOHxHUFuGzd6D-CJC3__j78,1518
|
|
11
11
|
commons_metrics/update_design_components.py,sha256=QpY0GCCCMjdYOZ7b8oNigU9iTpiGx91CYsyWwN8WVDA,7660
|
|
12
12
|
commons_metrics/util.py,sha256=98zuynalXumQRh-BB0Bcjyoh6vS2BTOUM8tVgr7iS9Q,1225
|
|
13
13
|
commons_metrics/variable_finder.py,sha256=pxI_XSd-lq_AiUjDbcUC4knIZhWZwt7HQrQOa-F0ud4,8061
|
|
14
|
-
commons_metrics-0.0.
|
|
15
|
-
commons_metrics-0.0.
|
|
16
|
-
commons_metrics-0.0.
|
|
17
|
-
commons_metrics-0.0.
|
|
18
|
-
commons_metrics-0.0.
|
|
14
|
+
commons_metrics-0.0.24.dist-info/licenses/LICENSE,sha256=jsHZ2Sh1wCL74HC25pDDGXCyQ0xgsTAy62FvEnehKIg,1067
|
|
15
|
+
commons_metrics-0.0.24.dist-info/METADATA,sha256=urWGuJg84vEuiiFTjw7ArflhFL4SC8hDLsiutYUIJqc,402
|
|
16
|
+
commons_metrics-0.0.24.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
17
|
+
commons_metrics-0.0.24.dist-info/top_level.txt,sha256=lheUN-3OKdU3A8Tg8Y-1IEB_9i_vVRA0g_FOiUsTQz8,16
|
|
18
|
+
commons_metrics-0.0.24.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|