Compare commits

...

2 Commits

Author SHA1 Message Date
mcbloch e32aa8b464 isort on all code 2024-03-27 18:03:18 +01:00
mcbloch cf933684f3 format all code 2024-03-27 18:02:53 +01:00
6 changed files with 22 additions and 21 deletions

View File

@ -5,4 +5,4 @@ with open("config.toml", mode="rb") as config_toml:
config = tomllib.load(config_toml)
# pprint(config)
# pprint(config)

View File

@ -12,7 +12,7 @@ def find_metadata(filename):
metadata = {}
start_strings = [ ":::spoiler Gitlab sync\n" , ":::spoiler git drive sync\n" ]
start_strings = [":::spoiler Gitlab sync\n", ":::spoiler git drive sync\n"]
end_str = "\n:::"
for start_str in start_strings:
@ -31,8 +31,6 @@ def find_metadata(filename):
print(metadata)
return metadata
print("Not a valid report")
return None

View File

@ -7,11 +7,11 @@ from enum import Enum
from time import sleep
from typing import Dict, List
from config import config
from colored import Style
from mattermostdriver import Driver
from tabulate import tabulate
from config import config
from mattermost_objects import MMChannelPosts, MMPost, MMUser
from utils import humanize_date_difference, timer
@ -56,7 +56,6 @@ users: {str: [User]} = {}
def loadusers():
usr = None
for name, data in config["mattermost"]["users"].items():
if "token" in data:

View File

@ -1,9 +1,8 @@
import mattermostdriver.exceptions
import mattermost_client
from mattermost_client import ChannelApi, MMApi
from config import config
from mattermost_client import ChannelApi, MMApi
def send_message(file_id, file_info, message):
@ -14,7 +13,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[config['mattermost']['selected_user']],
user=mattermost_client.users[config["mattermost"]["selected_user"]],
)
prefix = ""

View File

@ -71,7 +71,9 @@ def sync_file(drive, repo, path, sync_to):
repo.git.push("-u", "origin", branch_name)
if not drive.mergerequests.list(source_branch=branch_name, state="opened"):
if drive.mergerequests.list(source_branch=branch_name):
print(" Creating a new merge request to update the gitlab document with the new version from CodiMD.")
print(
" Creating a new merge request to update the gitlab document with the new version from CodiMD."
)
drive.mergerequests.create(
{
"source_branch": branch_name,
@ -93,8 +95,9 @@ def sync_file(drive, repo, path, sync_to):
else:
print(" Note has no changes.")
def init_sync():
repo = get_repo()
gl = gitlab.Gitlab("https://git.zeus.gent", private_token=TOKEN)
drive = gl.projects.get(2)
return repo, drive
return repo, drive

View File

@ -2,8 +2,10 @@ import json
import os
import re
import time
import traceback
from pprint import pprint
import gitlab
import hug
import requests
@ -13,11 +15,8 @@ import mattermost_client
import mattermost_communication
import sync_gitea as sync
import sync_gitlab
import gitlab
from utils import id_to_url, url_to_id
from config import config
import traceback
from utils import id_to_url, url_to_id
def find_codimd_files_on_mattermost():
@ -92,6 +91,7 @@ def validate_downloaded_files(post_mattermost_hint=True):
return db._load_db()
def sync_files_to_gitlab():
repo, drive = sync_gitlab.init_sync()
for file_id, file_info in db.get_files().items():
@ -99,9 +99,10 @@ def sync_files_to_gitlab():
local_file_path = file_info["local_file_path"]
sync_to = file_info["metadata"]["sync-to"]
try:
sync_gitlab.sync_file(drive, repo, local_file_path, sync_to)
sync_gitlab.sync_file(drive, repo, local_file_path, sync_to)
except Exception as e:
print("Critical error: Failed to sync file to Gitlab")
print("Critical error: Failed to sync file to Gitlab")
def sync_files_to_gitea():
repo, api_handler = sync.init_sync()
@ -110,10 +111,11 @@ def sync_files_to_gitea():
local_file_path = file_info["local_file_path"]
sync_to = file_info["metadata"]["sync-to"]
try:
sync.sync_file(repo, api_handler, local_file_path, sync_to)
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()
print("Critical error: Failed to sync file to Gitea")
traceback.print_exc()
@hug.get("/sync-mattermost")
def sync_mattermost():