From 66830a308775e860e3e91e55950076eb5fe3caeb Mon Sep 17 00:00:00 2001 From: mcbloch Date: Wed, 27 Mar 2024 17:16:34 +0100 Subject: [PATCH] move more into config file --- config.example.toml | 7 +++++++ src/mattermost_communication.py | 5 +++-- src/sync_gitea.py | 35 --------------------------------- src/web.py | 3 +++ 4 files changed, 13 insertions(+), 37 deletions(-) diff --git a/config.example.toml b/config.example.toml index 767557b..0663870 100644 --- a/config.example.toml +++ b/config.example.toml @@ -20,6 +20,7 @@ email = "" password = "" +# Outdated [gitlab] host = "https://git.zeus.gent" @@ -31,6 +32,12 @@ local_repo_folder = "drive" [gitea] +server_url = "https://git.zeus.gent" # Generate at gitea.example.com/user/settings/applications access_token = "..." local_repo_folder = "drive" +remote_org = "ZeusWPI" +remote_repo = "drive" + +commit_user_email = "..." +commit_user_name = "..." \ No newline at end of file diff --git a/src/mattermost_communication.py b/src/mattermost_communication.py index b6062b1..d2260dd 100644 --- a/src/mattermost_communication.py +++ b/src/mattermost_communication.py @@ -14,7 +14,7 @@ def send_message(file_id, file_info, message): # channel_id = MMApi().get_channel_id("bestuur-dev") channel = ChannelApi( channel_id=channel_id, - user=mattermost_client.users["flynn"], + user=mattermost_client.users[config['mattermost']['selected_user']], ) prefix = "" @@ -36,7 +36,8 @@ def send_message(file_id, file_info, message): def report_newly_found_file(file_id, file_info): - message = f"I found a new CodiMD file in this post! Making work of putting it on git :)\n - Requested location in the [drive](https://git.zeus.gent/bestuur/drive): {file_info['metadata']['sync-to']}" + git_url = f"https://{config['gitea']['server_url']}/{config['gitea']['remote_org']}/{config['gitea']['remote_repo']}" + message = f"I found a new CodiMD file in this post! Making work of putting it on git :)\n - Requested location in the [drive]({git_url}): {file_info['metadata']['sync-to']}" send_message(file_id, file_info, message) diff --git a/src/sync_gitea.py b/src/sync_gitea.py index d947bd3..1fc9b7d 100644 --- a/src/sync_gitea.py +++ b/src/sync_gitea.py @@ -126,38 +126,3 @@ def sync_file(repo, api_instance, path, sync_to): print(" Merge request was already open.") else: print(" Note has no changes.") - - -if __name__ == "__main__": - - repo, api_handler = init_sync() - for i, (file_id, file_info) in enumerate(db.get_files().items()): - if file_info["valid"]: - local_file_path = file_info["local_file_path"] - sync_to = file_info["metadata"]["sync-to"] - try: - sync_file(repo, api_handler, local_file_path, sync_to) - except Exception as e: - import traceback - - print("Critical error: Failed to sync file to Gitea") - traceback.print_exc() - - # # username = 'username_example' # str | username of the user that will own the created organization - # # organization = giteapy.CreateOrgOption() # CreateOrgOption | - - # pull_request = giteapy.CreatePullRequestOption( - # head="master", base="activiteiten_23-24", title="foo" - # ) - - # try: - # # Create an organization - # # api_response = api_instance.admin_create_org(username, organization) - # api_response = api_instance.repo_create_pull_request( - # "ZeusWPI", "drive", async_req=False, body=pull_request - # ) - # # pprint(api_response) - # except ApiException as e: - # print( - # "Exception when calling RepositoryApi->repo_create_pull_request: %s\n" % e - # ) diff --git a/src/web.py b/src/web.py index 9a30548..c7dd5cb 100644 --- a/src/web.py +++ b/src/web.py @@ -17,6 +17,8 @@ import gitlab from utils import id_to_url, url_to_id from config import config +import traceback + def find_codimd_files_on_mattermost(): mattermost = mattermost_client.MMApi() @@ -111,6 +113,7 @@ def sync_files_to_gitea(): sync.sync_file(repo, api_handler, local_file_path, sync_to) except Exception as e: print("Critical error: Failed to sync file to Gitea") + traceback.print_exc() @hug.get("/sync-mattermost") def sync_mattermost():