77from datetime import datetime
88from typing import Any , Dict , List , Optional
99
10+ import git
1011from flask import Flask , g
1112from flask_migrate import Migrate
1213from google .cloud .storage import Client
2627from mod_auth .controllers import mod_auth
2728from mod_ci .controllers import mod_ci
2829from mod_customized .controllers import mod_customized
29- from mod_deploy .controllers import mod_deploy
3030from mod_home .controllers import mod_home
3131from mod_regression .controllers import mod_regression
3232from mod_sample .controllers import mod_sample
4343 raise MissingConfigError ()
4444
4545app .config .from_mapping (config )
46- try :
47- app .config ['DEBUG' ] = os .environ ['DEBUG' ]
48- except KeyError :
49- app .config ['DEBUG' ] = False
46+ app .config ['DEBUG' ] = os .environ .get ('DEBUG' , False )
5047
5148# embed flask-migrate in the app itself
5249try :
6764storage_client = Client .from_service_account_json (sa_file )
6865storage_client_bucket = storage_client .bucket (app .config .get ('GCS_BUCKET_NAME' , '' ))
6966
67+ # Save build commit
68+ repo = git .Repo (search_parent_directories = True )
69+ app .config ['BUILD_COMMIT' ] = repo .head .object .hexsha
70+
7071
7172def load_secret_keys (application : Flask , secret_session : str = 'secret_key' ,
7273 secret_csrf : str = 'secret_csrf' ) -> None :
@@ -233,6 +234,7 @@ def before_request() -> None:
233234 g .version = "0.1"
234235 g .log = log
235236 g .github = get_github_config (app .config )
237+ g .build_commit = app .config ['BUILD_COMMIT' ]
236238
237239
238240def get_github_config (config : Dict [str , str ]) -> Dict [str , str ]:
@@ -245,7 +247,6 @@ def get_github_config(config: Dict[str, str]) -> Dict[str, str]:
245247 :rtype: dict
246248 """
247249 return {
248- 'deploy_key' : config .get ('GITHUB_DEPLOY_KEY' , '' ),
249250 'ci_key' : config .get ('GITHUB_CI_KEY' , '' ),
250251 'bot_token' : config .get ('GITHUB_TOKEN' , '' ),
251252 'bot_name' : config .get ('GITHUB_BOT' , '' ),
@@ -268,7 +269,6 @@ def teardown(exception: Optional[Exception]):
268269app .register_blueprint (mod_regression , url_prefix = '/regression' )
269270app .register_blueprint (mod_sample , url_prefix = '/sample' )
270271app .register_blueprint (mod_home )
271- app .register_blueprint (mod_deploy )
272272app .register_blueprint (mod_test , url_prefix = "/test" )
273273app .register_blueprint (mod_ci )
274274app .register_blueprint (mod_customized , url_prefix = '/custom' )
0 commit comments