move more into config file

This commit is contained in:
mcbloch 2024-03-27 17:16:34 +01:00
parent 8d050a241d
commit 66830a3087
4 changed files with 13 additions and 37 deletions

View file

@ -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 = "..."

View file

@ -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)

View file

@ -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
# )

View file

@ -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():