2016-02-27 14:41:36 +09:00
|
|
|
{- This file is part of Vervis.
|
|
|
|
-
|
|
|
|
- Written in 2016 by fr33domlover <fr33domlover@riseup.net>.
|
|
|
|
-
|
|
|
|
- ♡ Copying is an act of love. Please copy, reuse and share.
|
|
|
|
-
|
|
|
|
- The author(s) have dedicated all copyright and related and neighboring
|
|
|
|
- rights to this software to the public domain worldwide. This software is
|
|
|
|
- distributed without any warranty.
|
|
|
|
-
|
|
|
|
- You should have received a copy of the CC0 Public Domain Dedication along
|
|
|
|
- with this software. If not, see
|
|
|
|
- <http://creativecommons.org/publicdomain/zero/1.0/>.
|
|
|
|
-}
|
|
|
|
|
|
|
|
module Vervis.Handler.Repo
|
|
|
|
( getReposR
|
|
|
|
, postReposR
|
|
|
|
, getRepoNewR
|
|
|
|
, getRepoR
|
2016-04-12 09:19:04 +09:00
|
|
|
, getRepoSourceR
|
2016-05-06 01:30:30 +09:00
|
|
|
, getRepoHeadChangesR
|
|
|
|
, getRepoChangesR
|
2016-02-27 14:41:36 +09:00
|
|
|
)
|
|
|
|
where
|
|
|
|
|
|
|
|
--TODO CONTINUE HERE
|
|
|
|
--
|
|
|
|
-- [/] maybe list project repos in personal overview too
|
|
|
|
-- [x] make repo list page
|
|
|
|
-- [x] add new repo creation link
|
|
|
|
-- [x] make new repo form
|
|
|
|
-- [x] write the git and mkdir parts that actually create the repo
|
2016-03-03 17:15:54 +09:00
|
|
|
-- [x] make repo view that shows a table of commits
|
2016-02-27 14:41:36 +09:00
|
|
|
|
2016-05-05 02:17:47 +09:00
|
|
|
import ClassyPrelude.Conduit hiding (last, unpack)
|
2016-03-03 17:15:54 +09:00
|
|
|
import Yesod hiding (Header, parseTime, (==.))
|
|
|
|
import Yesod.Auth
|
|
|
|
|
2016-04-13 08:10:46 +09:00
|
|
|
import Prelude (init, last, tail)
|
2016-04-12 20:21:14 +09:00
|
|
|
|
2016-04-10 00:45:00 +09:00
|
|
|
import Data.Git.Graph
|
2016-05-01 05:14:56 +09:00
|
|
|
import Data.Git.Harder
|
2016-04-12 09:19:04 +09:00
|
|
|
import Data.Git.Named (RefName (..))
|
2016-03-03 17:15:54 +09:00
|
|
|
import Data.Git.Ref (toHex)
|
2016-05-04 20:44:06 +09:00
|
|
|
import Data.Git.Repository
|
2016-05-05 02:17:47 +09:00
|
|
|
import Data.Git.Storage (withRepo)
|
2016-04-12 19:06:21 +09:00
|
|
|
import Data.Git.Storage.Object (Object (..))
|
|
|
|
import Data.Git.Types (Blob (..), Commit (..), Person (..), entName)
|
2016-04-10 00:45:00 +09:00
|
|
|
import Data.Graph.Inductive.Graph (noNodes)
|
|
|
|
import Data.Graph.Inductive.Query.Topsort
|
2016-04-13 08:10:46 +09:00
|
|
|
import Data.List (inits)
|
2016-03-03 17:15:54 +09:00
|
|
|
import Data.Text (unpack)
|
|
|
|
import Data.Text.Encoding (decodeUtf8With)
|
|
|
|
import Data.Text.Encoding.Error (lenientDecode)
|
2016-02-27 14:41:36 +09:00
|
|
|
import Database.Esqueleto
|
2016-03-03 17:15:54 +09:00
|
|
|
import Data.Hourglass (timeConvert)
|
2016-02-27 14:41:36 +09:00
|
|
|
import System.Directory (createDirectoryIfMissing)
|
2016-03-03 17:15:54 +09:00
|
|
|
import System.Hourglass (dateCurrent)
|
|
|
|
|
2016-04-10 00:45:00 +09:00
|
|
|
import qualified Data.DList as D
|
2016-04-12 09:19:04 +09:00
|
|
|
import qualified Data.Set as S (member)
|
2016-04-12 19:06:21 +09:00
|
|
|
import qualified Data.Text.Lazy.Encoding as L (decodeUtf8With)
|
2016-04-10 00:45:00 +09:00
|
|
|
|
2016-03-03 17:15:54 +09:00
|
|
|
import Data.ByteString.Char8.Local (takeLine)
|
2016-05-05 02:17:47 +09:00
|
|
|
import Data.Git.Local
|
2016-04-18 02:55:23 +09:00
|
|
|
import Text.FilePath.Local (breakExt)
|
2016-02-27 14:41:36 +09:00
|
|
|
import Vervis.Form.Repo
|
2016-03-03 17:15:54 +09:00
|
|
|
import Vervis.Foundation
|
2016-05-05 16:29:19 +09:00
|
|
|
import Vervis.GitOld (timeAgo')
|
2016-03-03 17:15:54 +09:00
|
|
|
import Vervis.Path
|
2016-04-18 02:55:23 +09:00
|
|
|
import Vervis.MediaType (chooseMediaType)
|
2016-03-03 17:15:54 +09:00
|
|
|
import Vervis.Model
|
2016-05-03 09:33:49 +09:00
|
|
|
import Vervis.Model.Repo
|
2016-04-14 01:17:34 +09:00
|
|
|
import Vervis.Readme
|
2016-04-13 15:55:39 +09:00
|
|
|
import Vervis.Render
|
2016-03-03 17:15:54 +09:00
|
|
|
import Vervis.Settings
|
2016-05-05 16:29:19 +09:00
|
|
|
import Vervis.SourceTree
|
2016-04-12 23:44:43 +09:00
|
|
|
import Vervis.Style
|
2016-05-06 19:29:02 +09:00
|
|
|
import Vervis.Widget.Repo
|
2016-02-27 14:41:36 +09:00
|
|
|
|
2016-05-08 23:28:03 +09:00
|
|
|
import qualified Darcs.Local.Repository as D (createRepo)
|
2016-05-05 02:17:47 +09:00
|
|
|
import qualified Data.ByteString.Lazy as BL (ByteString)
|
|
|
|
import qualified Data.Git.Local as G (createRepo)
|
2016-05-08 23:28:03 +09:00
|
|
|
import qualified Vervis.Darcs as D (readSourceView, readChangesView)
|
2016-05-06 19:29:02 +09:00
|
|
|
import qualified Vervis.Git as G (readSourceView, readChangesView)
|
2016-05-04 20:44:06 +09:00
|
|
|
|
2016-04-13 02:37:31 +09:00
|
|
|
getReposR :: Text -> Handler Html
|
|
|
|
getReposR user = do
|
|
|
|
repos <- runDB $ select $ from $ \ (sharer, repo) -> do
|
2016-02-27 14:41:36 +09:00
|
|
|
where_ $
|
|
|
|
sharer ^. SharerIdent ==. val user &&.
|
2016-04-13 02:37:31 +09:00
|
|
|
sharer ^. SharerId ==. repo ^. RepoSharer
|
2016-02-27 14:41:36 +09:00
|
|
|
orderBy [asc $ repo ^. RepoIdent]
|
|
|
|
return $ repo ^. RepoIdent
|
|
|
|
defaultLayout $ do
|
2016-04-13 02:37:31 +09:00
|
|
|
setTitle $ toHtml $ intercalate " > "
|
|
|
|
["Vervis", "People", user, "Repos"]
|
2016-04-12 06:24:10 +09:00
|
|
|
$(widgetFile "repo/repos")
|
2016-02-27 14:41:36 +09:00
|
|
|
|
2016-04-13 02:37:31 +09:00
|
|
|
postReposR :: Text -> Handler Html
|
|
|
|
postReposR user = do
|
2016-02-27 14:41:36 +09:00
|
|
|
Entity _pid person <- requireAuth
|
|
|
|
let sid = personIdent person
|
2016-04-13 02:37:31 +09:00
|
|
|
((result, widget), enctype) <- runFormPost $ newRepoForm sid
|
2016-02-27 14:41:36 +09:00
|
|
|
case result of
|
2016-05-04 20:44:06 +09:00
|
|
|
FormSuccess repo -> do
|
|
|
|
parent <- askSharerDir user
|
|
|
|
liftIO $ do
|
|
|
|
createDirectoryIfMissing True parent
|
|
|
|
let repoName = unpack $ repoIdent repo
|
|
|
|
case repoVcs repo of
|
2016-05-05 02:17:47 +09:00
|
|
|
VCSDarcs -> D.createRepo parent repoName
|
|
|
|
VCSGit -> G.createRepo parent repoName
|
2016-05-04 20:44:06 +09:00
|
|
|
runDB $ insert_ repo
|
|
|
|
setMessage "Repo added."
|
|
|
|
redirect $ ReposR user
|
2016-02-27 14:41:36 +09:00
|
|
|
FormMissing -> do
|
|
|
|
setMessage "Field(s) missing"
|
2016-04-12 06:24:10 +09:00
|
|
|
defaultLayout $(widgetFile "repo/repo-new")
|
2016-05-04 20:44:06 +09:00
|
|
|
FormFailure _l -> do
|
|
|
|
setMessage "Repo creation failed, see errors below"
|
2016-04-12 06:24:10 +09:00
|
|
|
defaultLayout $(widgetFile "repo/repo-new")
|
2016-02-27 14:41:36 +09:00
|
|
|
|
2016-04-13 02:37:31 +09:00
|
|
|
getRepoNewR :: Text -> Handler Html
|
|
|
|
getRepoNewR user = do
|
2016-02-27 14:41:36 +09:00
|
|
|
Entity _pid person <- requireAuth
|
|
|
|
let sid = personIdent person
|
2016-04-13 02:37:31 +09:00
|
|
|
((_result, widget), enctype) <- runFormPost $ newRepoForm sid
|
2016-02-27 14:41:36 +09:00
|
|
|
defaultLayout $ do
|
2016-04-13 02:37:31 +09:00
|
|
|
setTitle $ toHtml $ mconcat ["Vervis > People > ", user, " > New Repo"]
|
2016-04-12 06:24:10 +09:00
|
|
|
$(widgetFile "repo/repo-new")
|
2016-02-27 14:41:36 +09:00
|
|
|
|
2016-05-06 01:30:30 +09:00
|
|
|
selectRepo :: Text -> Text -> AppDB Repo
|
|
|
|
selectRepo shar repo = do
|
|
|
|
Entity sid _s <- getBy404 $ UniqueSharerIdent shar
|
|
|
|
Entity _rid r <- getBy404 $ UniqueRepo repo sid
|
|
|
|
return r
|
|
|
|
|
2016-04-13 02:37:31 +09:00
|
|
|
getRepoR :: Text -> Text -> Handler Html
|
2016-05-06 01:30:30 +09:00
|
|
|
getRepoR shar repo = do
|
|
|
|
repository <- runDB $ selectRepo shar repo
|
2016-05-05 16:29:19 +09:00
|
|
|
case repoVcs repository of
|
2016-05-06 01:30:30 +09:00
|
|
|
VCSDarcs -> getDarcsRepoSource repository shar repo []
|
2016-05-05 16:29:19 +09:00
|
|
|
VCSGit ->
|
|
|
|
getGitRepoSource
|
2016-05-06 01:30:30 +09:00
|
|
|
repository shar repo (repoMainBranch repository) []
|
2016-05-05 16:29:19 +09:00
|
|
|
|
|
|
|
getDarcsRepoSource :: Repo -> Text -> Text -> [Text] -> Handler Html
|
|
|
|
getDarcsRepoSource repository user repo dir = do
|
2016-04-13 02:37:31 +09:00
|
|
|
path <- askRepoDir user repo
|
2016-05-05 16:29:19 +09:00
|
|
|
msv <- liftIO $ D.readSourceView path dir
|
|
|
|
case msv of
|
2016-05-05 02:17:47 +09:00
|
|
|
Nothing -> notFound
|
|
|
|
Just sv -> do
|
2016-04-13 08:10:46 +09:00
|
|
|
let parent = if null dir then [] else init dir
|
|
|
|
dirs = zip parent (tail $ inits parent)
|
2016-04-12 09:19:04 +09:00
|
|
|
defaultLayout $ do
|
2016-05-06 01:30:30 +09:00
|
|
|
setTitle $ toHtml $ intercalate " > "
|
2016-04-13 02:37:31 +09:00
|
|
|
["Vervis", "People", user, "Repos", repo]
|
2016-05-05 16:29:19 +09:00
|
|
|
$(widgetFile "repo/source-darcs")
|
2016-04-12 09:19:04 +09:00
|
|
|
|
2016-05-05 16:29:19 +09:00
|
|
|
getGitRepoSource :: Repo -> Text -> Text -> Text -> [Text] -> Handler Html
|
|
|
|
getGitRepoSource repository user repo ref dir = do
|
|
|
|
path <- askRepoDir user repo
|
|
|
|
(branches, tags, msv) <- liftIO $ G.readSourceView path ref dir
|
|
|
|
case msv of
|
|
|
|
Nothing -> notFound
|
|
|
|
Just sv -> do
|
|
|
|
let parent = if null dir then [] else init dir
|
|
|
|
dirs = zip parent (tail $ inits parent)
|
|
|
|
defaultLayout $ do
|
|
|
|
setTitle $ toHtml $ intercalate " > " $
|
|
|
|
["Vervis", "People", user, "Repos", repo]
|
|
|
|
$(widgetFile "repo/source-git")
|
|
|
|
|
|
|
|
getRepoSourceR :: Text -> Text -> [Text] -> Handler Html
|
2016-05-06 01:30:30 +09:00
|
|
|
getRepoSourceR shar repo refdir = do
|
|
|
|
repository <- runDB $ selectRepo shar repo
|
2016-05-05 16:29:19 +09:00
|
|
|
case repoVcs repository of
|
2016-05-06 01:30:30 +09:00
|
|
|
VCSDarcs -> getDarcsRepoSource repository shar repo refdir
|
2016-05-05 16:29:19 +09:00
|
|
|
VCSGit -> case refdir of
|
|
|
|
[] -> notFound
|
2016-05-06 01:30:30 +09:00
|
|
|
(ref:dir) -> getGitRepoSource repository shar repo ref dir
|
|
|
|
|
|
|
|
getDarcsRepoHeadChanges :: Text -> Text -> Handler Html
|
2016-05-08 23:28:03 +09:00
|
|
|
getDarcsRepoHeadChanges shar repo = do
|
|
|
|
path <- askRepoDir shar repo
|
|
|
|
mentries <- liftIO $ D.readChangesView path
|
|
|
|
case mentries of
|
|
|
|
Nothing -> notFound
|
|
|
|
Just entries ->
|
|
|
|
let changes = changesW entries
|
|
|
|
in defaultLayout $(widgetFile "repo/changes-darcs")
|
2016-05-06 01:30:30 +09:00
|
|
|
|
|
|
|
getGitRepoHeadChanges :: Repo -> Text -> Text -> Handler Html
|
|
|
|
getGitRepoHeadChanges repository shar repo =
|
|
|
|
getGitRepoChanges shar repo $ repoMainBranch repository
|
|
|
|
|
|
|
|
getRepoHeadChangesR :: Text -> Text -> Handler Html
|
|
|
|
getRepoHeadChangesR user repo = do
|
|
|
|
repository <- runDB $ selectRepo user repo
|
|
|
|
case repoVcs repository of
|
|
|
|
VCSDarcs -> getDarcsRepoHeadChanges user repo
|
|
|
|
VCSGit -> getGitRepoHeadChanges repository user repo
|
|
|
|
|
|
|
|
getDarcsRepoChanges :: Text -> Text -> Text -> Handler Html
|
|
|
|
getDarcsRepoChanges shar repo tag = notFound
|
|
|
|
|
|
|
|
getGitRepoChanges :: Text -> Text -> Text -> Handler Html
|
|
|
|
getGitRepoChanges shar repo ref = do
|
|
|
|
path <- askRepoDir shar repo
|
2016-05-06 19:29:02 +09:00
|
|
|
(branches, tags, mentries) <- liftIO $ G.readChangesView path ref
|
|
|
|
case mentries of
|
|
|
|
Nothing -> notFound
|
|
|
|
Just entries ->
|
|
|
|
let refSelect = refSelectW shar repo branches tags
|
|
|
|
changes = changesW entries
|
|
|
|
in defaultLayout $(widgetFile "repo/changes-git")
|
2016-05-06 01:30:30 +09:00
|
|
|
|
|
|
|
getRepoChangesR :: Text -> Text -> Text -> Handler Html
|
|
|
|
getRepoChangesR shar repo ref = do
|
|
|
|
repository <- runDB $ selectRepo shar repo
|
|
|
|
case repoVcs repository of
|
|
|
|
VCSDarcs -> getDarcsRepoChanges shar repo ref
|
|
|
|
VCSGit -> getGitRepoChanges shar repo ref
|