|
@@ -35,12 +35,19 @@ def get_jenkins_jobs():
|
35
|
35
|
yield job["fullname"], branch_spec, git_config.find("url").text
|
36
|
36
|
|
37
|
37
|
|
|
38
|
+def gitea_request(method, api_path, **kwargs):
|
|
39
|
+ if "params" not in kwargs:
|
|
40
|
+ kwargs["params"] = {}
|
|
41
|
+ kwargs["params"]["access_token"] = os.environ["LAS_GITEA_TOKEN"]
|
|
42
|
+ return requests.request(
|
|
43
|
+ method, f"{os.environ['LAS_GITEA_URL']}api/v1/{api_path}", **kwargs
|
|
44
|
+ )
|
|
45
|
+
|
|
46
|
+
|
38
|
47
|
def maybe_install_gitea_hook(project):
|
39
|
|
- gitea_url = f"{os.environ['LAS_GITEA_URL']}api/v1/repos/{project}/hooks"
|
40
|
48
|
hook_url = get_hook_url("gitea", project)
|
41
|
|
- hooks = requests.get(
|
42
|
|
- gitea_url, params={"access_token": os.environ["LAS_GITEA_TOKEN"]}
|
43
|
|
- ).json()
|
|
49
|
+ path = f"repos/{project}/hooks"
|
|
50
|
+ hooks = gitea_request("get", path).json()
|
44
|
51
|
|
45
|
52
|
if hook_url not in [hook["config"]["url"] for hook in hooks]:
|
46
|
53
|
body = {
|
|
@@ -59,18 +66,11 @@ def maybe_install_gitea_hook(project):
|
59
|
66
|
],
|
60
|
67
|
"type": "gitea",
|
61
|
68
|
}
|
62
|
|
- requests.post(
|
63
|
|
- gitea_url,
|
64
|
|
- json=body,
|
65
|
|
- params={"access_token": "5b8de94a7201bc923e99813850327caf75b85e70"},
|
66
|
|
- ).json()
|
|
69
|
+ gitea_request("post", path, json=body).json()
|
67
|
70
|
|
68
|
71
|
|
69
|
72
|
def get_gitea_repos():
|
70
|
|
- repos = requests.get(
|
71
|
|
- f"{os.environ['LAS_GITEA_URL']}api/v1/user/repos",
|
72
|
|
- params={"access_token": os.environ["LAS_GITEA_TOKEN"]},
|
73
|
|
- ).json()
|
|
73
|
+ repos = gitea_request("get", f"user/repos").json()
|
74
|
74
|
for repo in repos:
|
75
|
75
|
maybe_install_gitea_hook(repo["full_name"])
|
76
|
76
|
yield repo["full_name"], repo["ssh_url"], repo["clone_url"]
|