Explorar el Código

Eagerly initialise services.

This will need to change when the config is rethought a little.
master
Chris Smith hace 6 años
padre
commit
e165197a70
Se han modificado 2 ficheros con 12 adiciones y 15 borrados
  1. 5
    5
      lineandsinker/services/__init__.py
  2. 7
    10
      main.py

+ 5
- 5
lineandsinker/services/__init__.py Ver fichero

30
     )
30
     )
31
 
31
 
32
 
32
 
33
-factories = {
34
-    "docker": docker_factory,
35
-    "gitea": gitea_factory,
36
-    "jenkins": jenkins_factory,
37
-    "reportbot": reportbot_factory,
33
+services = {
34
+    "docker": docker_factory(),
35
+    "gitea": gitea_factory(),
36
+    "jenkins": jenkins_factory(),
37
+    "reportbot": reportbot_factory(),
38
 }
38
 }

+ 7
- 10
main.py Ver fichero

4
 from flask import Flask, abort, request, Response
4
 from flask import Flask, abort, request, Response
5
 
5
 
6
 from lineandsinker.common import get_hook_key
6
 from lineandsinker.common import get_hook_key
7
-from lineandsinker.services import gitea_factory, jenkins_factory, reportbot_factory
7
+from lineandsinker.services import services
8
 
8
 
9
 url_pattern = re.compile(
9
 url_pattern = re.compile(
10
     "^/hooks/(?P<service>[^/]+)/(?P<identifier>.*)/(?P<key>[^/]+)$"
10
     "^/hooks/(?P<service>[^/]+)/(?P<identifier>.*)/(?P<key>[^/]+)$"
30
     return wrapper
30
     return wrapper
31
 
31
 
32
 
32
 
33
-jenkins_service = jenkins_factory()
34
-gitea_service = gitea_factory()
35
-reportbot_service = reportbot_factory()
36
-repos = dict((name, [ssh, clone]) for name, ssh, clone in gitea_service.get_repos())
37
-jobs = list(jenkins_service.get_jobs())
33
+repos = dict((name, [ssh, clone]) for name, ssh, clone in services["gitea"].get_repos())
34
+jobs = list(services["jenkins"].get_jobs())
38
 app = Flask(__name__)
35
 app = Flask(__name__)
39
 
36
 
40
 
37
 
58
             if url in urls:
55
             if url in urls:
59
                 # TODO: Check branches
56
                 # TODO: Check branches
60
                 app.logger.info(f"Found matching job: {name} with URL {url}")
57
                 app.logger.info(f"Found matching job: {name} with URL {url}")
61
-                jenkins_service.build_job(name)
58
+                services["jenkins"].build_job(name)
62
 
59
 
63
         data = request.get_json()
60
         data = request.get_json()
64
         if not data["repository"]["private"]:
61
         if not data["repository"]["private"]:
67
             compare = data["compare_url"]
64
             compare = data["compare_url"]
68
             pusher = data["pusher"]["login"]
65
             pusher = data["pusher"]["login"]
69
 
66
 
70
-            reportbot_service.announce(
67
+            services["reportbot"].announce(
71
                 f"\002[git]\002 {pusher} pushed {commits} commit{'s' if commits != 1 else ''} to {repo}: {compare}"
68
                 f"\002[git]\002 {pusher} pushed {commits} commit{'s' if commits != 1 else ''} to {repo}: {compare}"
72
             )
69
             )
73
             for commit in data["commits"][:3]:
70
             for commit in data["commits"][:3]:
74
-                reportbot_service.announce(
71
+                services["reportbot"].announce(
75
                     f"\002[git]\002 {commit['id'][:10]}: {commit['message'][:100]}"
72
                     f"\002[git]\002 {commit['id'][:10]}: {commit['message'][:100]}"
76
                 )
73
                 )
77
 
74
 
91
             tag = event["target"]["tag"]
88
             tag = event["target"]["tag"]
92
             host = event["request"]["host"]
89
             host = event["request"]["host"]
93
             user = event["actor"]["name"]
90
             user = event["actor"]["name"]
94
-            reportbot_service.announce(
91
+            services["reportbot"].announce(
95
                 f"\002[registry]\002 New manifest pushed to {host}/{repo}:{tag} by {user}"
92
                 f"\002[registry]\002 New manifest pushed to {host}/{repo}:{tag} by {user}"
96
             )
93
             )
97
 
94
 

Loading…
Cancelar
Guardar