Skip to content

Commit 8a0ad97

Browse files
authored
Merge pull request #1140 from AlmaLinux/change_gitea_tags_endpoint
Change endpoint for fetching tags from Gitea API
2 parents f2fd907 + b0f6866 commit 8a0ad97

File tree

2 files changed

+35
-12
lines changed

2 files changed

+35
-12
lines changed

alws/scripts/git_cacher/git_cacher.py

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ class Config(BaseSettings):
2525
cacher_sentry_traces_sample_rate: float = 0.2
2626

2727

28-
async def load_redis_cache(redis, cache_key):
28+
async def load_redis_cache(redis: aioredis.Redis, cache_key: str) -> dict:
2929
value = await redis.get(cache_key)
3030
if not value:
3131
return {}
3232
return json.loads(value)
3333

3434

35-
async def save_redis_cache(redis, cache_key, cache):
35+
async def save_redis_cache(redis: aioredis.Redis, cache_key: str, cache: dict):
3636
await redis.set(cache_key, json.dumps(cache))
3737

3838

@@ -49,7 +49,13 @@ def setup_logger():
4949
return logger
5050

5151

52-
async def run(config, logger, redis_client, gitea_client, organization):
52+
async def run(
53+
config: Config,
54+
logger: logging.Logger,
55+
redis_client: aioredis.Redis,
56+
gitea_client: GiteaClient,
57+
organization: str,
58+
):
5359
cache = await load_redis_cache(
5460
redis_client, config.git_cache_keys[organization]
5561
)
@@ -114,15 +120,19 @@ async def main():
114120
wait = 600
115121
while True:
116122
logger.info('Checking cache for updates')
117-
await asyncio.gather(
118-
# projects git data live in these gitea orgs
119-
run(config, logger, redis_client, gitea_client, 'rpms'),
120-
run(config, logger, redis_client, gitea_client, 'modules'),
121-
# almalinux modified packages live in autopatch gitea org
122-
run(config, logger, redis_client, gitea_client, 'autopatch'),
123-
)
123+
await asyncio.gather(*(
124+
run(config, logger, redis_client, gitea_client, organization)
125+
for organization in (
126+
# projects git data live in these gitea orgs
127+
'rpms',
128+
'modules',
129+
# almalinux modified packages live in autopatch gitea org
130+
'autopatch',
131+
)
132+
))
124133
logger.info(
125-
'Cache has been updated, waiting for %d secs for next update' % wait
134+
'Cache has been updated, waiting for %d secs for next update',
135+
wait,
126136
)
127137
await asyncio.sleep(wait)
128138

alws/utils/gitea.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ async def make_request(self, endpoint: str, params: dict = None):
6262
) as response:
6363
response.raise_for_status()
6464
return await response.json()
65+
except aiohttp.client_exceptions.ClientResponseError:
66+
self.log.exception(
67+
'Request %s returned with an error',
68+
full_url,
69+
)
70+
return []
6571
except (
6672
aiohttp.client_exceptions.ClientConnectorError,
6773
aiohttp.client_exceptions.ServerDisconnectedError,
@@ -99,6 +105,13 @@ async def list_tags(self, repo: str) -> typing.List:
99105
endpoint = f'repos/{repo}/tags'
100106
return await self._list_all_pages(endpoint)
101107

108+
async def list_tags_from_repo_refs(self, repo: str) -> list[dict]:
109+
endpoint = f'repos/{repo}/git/refs/tags'
110+
return [
111+
{'name': ref['ref'].replace('refs/tags/', '')}
112+
for ref in await self.make_request(endpoint)
113+
]
114+
102115
async def list_branches(self, repo: str) -> typing.List:
103116
endpoint = f'repos/{repo}/branches'
104117
return await self._list_all_pages(endpoint)
@@ -108,6 +121,6 @@ async def get_branch(self, repo: str, branch: str) -> typing.Dict:
108121
return await self.make_request(endpoint)
109122

110123
async def index_repo(self, repo_name: str):
111-
tags = await self.list_tags(repo_name)
124+
tags = await self.list_tags_from_repo_refs(repo_name)
112125
branches = await self.list_branches(repo_name)
113126
return {'repo_name': repo_name, 'tags': tags, 'branches': branches}

0 commit comments

Comments
 (0)