🚧 reorganise code
This commit is contained in:
parent
6343ee6db3
commit
024f01c9d1
4 changed files with 177 additions and 158 deletions
49
src/gitea_gitlab_exporter/api.py
Normal file
49
src/gitea_gitlab_exporter/api.py
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
import json
|
||||
import logging
|
||||
|
||||
from .utils import get, gitlab_url
|
||||
|
||||
|
||||
def get_user(args):
|
||||
logging.debug("get_user called")
|
||||
|
||||
url = gitlab_url("/user")
|
||||
|
||||
result = get(url, args)
|
||||
|
||||
return result
|
||||
|
||||
|
||||
def list_projects(args):
|
||||
logging.debug("list_projects called")
|
||||
user_id = get_user(args)["id"]
|
||||
|
||||
url = gitlab_url(
|
||||
f"/users/{user_id}/projects?pagination=offset&per_page=500&"
|
||||
"order_by=name&sort=asc"
|
||||
)
|
||||
|
||||
result = get(url, args)
|
||||
|
||||
return result
|
||||
|
||||
|
||||
def get_project_details(args):
|
||||
user_id = get_user(args)["id"]
|
||||
url = gitlab_url(
|
||||
f"/users/{user_id}/projects?pagination=offset&per_page=500&"
|
||||
"order_by=name&sort=asc"
|
||||
)
|
||||
|
||||
response = get(url, args)
|
||||
|
||||
project = [
|
||||
project
|
||||
for project in response
|
||||
if (project["name"] == args.project or project["id"] == args.project)
|
||||
][0]
|
||||
|
||||
if not project:
|
||||
raise KeyError(f"Project {args.project} not found")
|
||||
|
||||
print(json.dumps(project))
|
||||
Loading…
Add table
Add a link
Reference in a new issue