From a8ac6ef2e21b661680ca18256d744bf62b8a0376 Mon Sep 17 00:00:00 2001 From: boke0 Date: Wed, 10 Mar 2021 17:20:51 +0900 Subject: [PATCH] [update] --- izanami/main.py | 20 +++++++++++++++----- izanami/model.py | 29 ++++++++++++++++++++++------- 2 files changed, 37 insertions(+), 12 deletions(-) diff --git a/izanami/main.py b/izanami/main.py index 6648394..a6235fd 100644 --- a/izanami/main.py +++ b/izanami/main.py @@ -1,10 +1,20 @@ from mitama.app import App, Router from mitama.utils.controllers import static_files -from mitama.utils.middlewares import BasicMiddleware, SessionMiddleware, CsrfMiddleware +from mitama.utils.middlewares import ( + BasicMiddleware, + SessionMiddleware, + CsrfMiddleware +) from mitama.app.method import view -#from .controller import RepoController, ProxyController, HookController -from .controller import RepoController, ProxyController, HookController, MergeController, SettingController +# from .controller import RepoController, ProxyController, HookController +from .controller import ( + RepoController, + ProxyController, + HookController, + MergeController, + SettingController +) from .model import Repo, Merge, InnerPermission @@ -17,7 +27,7 @@ class App(App): view("/static/", static_files()), Router([ view("/", ProxyController), - ], middlewares = [BasicMiddleware]), + ], middlewares=[BasicMiddleware]), Router([ view("/", RepoController), view("/create", RepoController, 'create'), @@ -38,7 +48,7 @@ class App(App): view("//hook/", HookController, 'retrieve'), view("//hook//edit", HookController, 'update'), view("//hook//delete", HookController, 'delete'), - ], middlewares = [SessionMiddleware, CsrfMiddleware]) + ], middlewares=[SessionMiddleware, CsrfMiddleware]) ] ) diff --git a/izanami/model.py b/izanami/model.py index a8554a1..7d6f788 100644 --- a/izanami/model.py +++ b/izanami/model.py @@ -1,10 +1,11 @@ from mitama.db import BaseDatabase, relationship -from mitama.db.types import * -from mitama.models import inner_permission, Role, User, Node +from mitama.db.types import Column, String, Text, ForeignKey +from mitama.models import inner_permission, User, Node +from unidiff import PatchSet +import markdown import git import hashlib import shutil -import asyncio class Database(BaseDatabase): @@ -13,16 +14,19 @@ class Database(BaseDatabase): db = Database(prefix="izanami") + class Repo(db.Model): name = Column(String(64), primary_key=True, unique=True) owner = relationship(Node) owner_id = Column(String(64), ForeignKey("mitama_node._id")) + @property def entity(self): entity = git.Repo( self.project_dir / 'repos/{}.git'.format(self.name), ) return entity + def merge(self, source, target): dirname = hashlib.sha256() dirname.update(self.name.encode()) @@ -34,19 +38,25 @@ def merge(self, source, target): self.project_dir / 'tmp/{}'.format(dirname), branch=source ) - repo.index.merge_tree('origin/' + target).commit("Merged into {}".format(source)) + repo.index.merge_tree( + 'origin/' + target + ).commit( + "Merged into {}".format(source) + ) repo.remotes.origin.push() shutil.rmtree(self.project_dir / 'tmp/{}'.format(dirname)) + class Merge(db.Model): repo_id = Column(String(64), ForeignKey("izanami_repo._id")) repo = relationship(Repo) base = Column(String(255), nullable=False) compare = Column(String(255), nullable=False) - body = Column(String(1000)) + body = Column(Text) title = Column(String(255)) user_id = Column(String(64), ForeignKey("mitama_user._id")) user = relationship(User) + @property def meta(self): md = markdown.Metadata(extensions=["meta"]) @@ -55,12 +65,17 @@ def meta(self): def merge(self): self.repo.merge(self.base, self.compare) - self.on("merge")() + self.event["merge"]() @property def diff(self): entity = self.repo.entity - diff_str = entity.git.diff(self.base, self.compare, ignore_blank_lines=True, ignore_space_at_eol=True) if len(commit.parents) > 0 else None + diff_str = entity.git.diff( + self.base, + self.compare, + ignore_blank_lines=True, + ignore_space_at_eol=True + ) diff = PatchSet(diff_str) return diff