Skip to content

Commit

Permalink
[update]
Browse files Browse the repository at this point in the history
  • Loading branch information
boke0 committed Mar 10, 2021
1 parent 148945a commit a8ac6ef
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 12 deletions.
20 changes: 15 additions & 5 deletions izanami/main.py
Original file line number Diff line number Diff line change
@@ -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


Expand All @@ -17,7 +27,7 @@ class App(App):
view("/static/<path:path>", static_files()),
Router([
view("/<repo:re:(.*)\.git><path:path>", ProxyController),
], middlewares = [BasicMiddleware]),
], middlewares=[BasicMiddleware]),
Router([
view("/", RepoController),
view("/create", RepoController, 'create'),
Expand All @@ -38,7 +48,7 @@ class App(App):
view("/<repo>/hook/<hook>", HookController, 'retrieve'),
view("/<repo>/hook/<hook>/edit", HookController, 'update'),
view("/<repo>/hook/<hook>/delete", HookController, 'delete'),
], middlewares = [SessionMiddleware, CsrfMiddleware])
], middlewares=[SessionMiddleware, CsrfMiddleware])
]
)

Expand Down
29 changes: 22 additions & 7 deletions izanami/model.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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())
Expand All @@ -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"])
Expand All @@ -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

Expand Down

0 comments on commit a8ac6ef

Please sign in to comment.