DB: Add media type field to 'Patch' entity

This patch (haha) also adds a VCS field to the AP representation of repos
This commit is contained in:
fr33domlover 2020-08-14 21:16:33 +00:00
parent b16c9505af
commit cb11ea6447
29 changed files with 304 additions and 144 deletions

View file

@ -456,6 +456,7 @@ Bundle
Patch Patch
bundle BundleId bundle BundleId
created UTCTime created UTCTime
type PatchMediaType
content Text content Text
TicketDependencyOffer TicketDependencyOffer

View file

@ -0,0 +1,24 @@
Sharer
Project
Role
Inbox
Outbox
FollowerSet
Repo
ident RpIdent
sharer SharerId
vcs Text
project ProjectId Maybe
desc Text Maybe
mainBranch Text
collabUser RoleId Maybe
collabAnon RoleId Maybe
inbox InboxId
outbox OutboxId
followers FollowerSetId
UniqueRepo ident sharer
UniqueRepoInbox inbox
UniqueRepoOutbox outbox
UniqueRepoFollowers followers

View file

@ -58,7 +58,7 @@ fromEither (Right y) = Right' y
(.:|) :: FromJSON a => Object -> Text -> Parser a (.:|) :: FromJSON a => Object -> Text -> Parser a
o .:| t = o .: t <|> o .: (frg <> t) o .:| t = o .: t <|> o .: (frg <> t)
where where
frg = "https://forgefed.angeley.es/ns#" frg = "https://forgefed.peers.community/ns#"
(.:|?) :: FromJSON a => Object -> Text -> Parser (Maybe a) (.:|?) :: FromJSON a => Object -> Text -> Parser (Maybe a)
o .:|? t = optional $ o .:| t o .:|? t = optional $ o .:| t

View file

@ -0,0 +1,73 @@
{- This file is part of Vervis.
-
- Written in 2016, 2019, 2020 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 Development.PatchMediaType
( VersionControlSystem (..)
, PatchMediaType (..)
, parseVersionControlSystemName
, parseVersionControlSystemURI
, versionControlSystemName
, versionControlSystemURI
, patchMediaTypeVCS
, parsePatchMediaType
, renderPatchMediaType
)
where
import Control.Monad
import Data.Text (Text)
import qualified Data.Text as T
data VersionControlSystem = VCSDarcs | VCSGit deriving Eq
data PatchMediaType = PatchMediaTypeDarcs deriving Eq
forgeFedPrefix :: Text
forgeFedPrefix = "https://forgefed.peers.community/ns#"
parseVersionControlSystemName :: Text -> Maybe VersionControlSystem
parseVersionControlSystemName = parse . T.toLower
where
parse "darcs" = Just VCSDarcs
parse "git" = Just VCSGit
parse _ = Nothing
parseVersionControlSystemURI :: Text -> Maybe VersionControlSystem
parseVersionControlSystemURI = parse <=< T.stripPrefix forgeFedPrefix
where
parse "darcs" = Just VCSDarcs
parse "git" = Just VCSGit
parse _ = Nothing
versionControlSystemName :: VersionControlSystem -> Text
versionControlSystemName VCSDarcs = "Darcs"
versionControlSystemName VCSGit = "Git"
versionControlSystemURI :: VersionControlSystem -> Text
versionControlSystemURI vcs = forgeFedPrefix <> rest vcs
where
rest VCSDarcs = "darcs"
rest VCSGit = "git"
patchMediaTypeVCS :: PatchMediaType -> VersionControlSystem
patchMediaTypeVCS PatchMediaTypeDarcs = VCSDarcs
parsePatchMediaType :: Text -> Maybe PatchMediaType
parsePatchMediaType "application/x-darcs-patch" = Just PatchMediaTypeDarcs
parsePatchMediaType _ = Nothing
renderPatchMediaType :: PatchMediaType -> Text
renderPatchMediaType PatchMediaTypeDarcs = "application/x-darcs-patch"

View file

@ -0,0 +1,45 @@
{- This file is part of Vervis.
-
- Written in 2019, 2020 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 Development.PatchMediaType.JSON () where
import Data.Aeson
import qualified Data.Text as T
import Development.PatchMediaType
instance FromJSON VersionControlSystem where
parseJSON =
withText "VersionControlSystem" $ \ t ->
case parseVersionControlSystemURI t of
Nothing ->
fail $ "Unknown version control system URI: " ++ T.unpack t
Just vcs -> return vcs
instance ToJSON VersionControlSystem where
toJSON = toJSON . versionControlSystemURI
toEncoding = toEncoding . versionControlSystemURI
instance FromJSON PatchMediaType where
parseJSON =
withText "PatchMediaType" $ \ t ->
case parsePatchMediaType t of
Nothing -> fail $ "Unknown patch media type: " ++ T.unpack t
Just pmt -> return pmt
instance ToJSON PatchMediaType where
toJSON = toJSON . renderPatchMediaType
toEncoding = toEncoding . renderPatchMediaType

View file

@ -0,0 +1,43 @@
{- This file is part of Vervis.
-
- Written in 2020 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 Development.PatchMediaType.Persist () where
import Database.Persist
import Database.Persist.Sql
import Development.PatchMediaType
instance PersistField VersionControlSystem where
toPersistValue = toPersistValue . versionControlSystemName
fromPersistValue v = do
t <- fromPersistValue v
case parseVersionControlSystemName t of
Nothing -> Left $ "Unknown version control system name: " <> t
Just vcs -> Right vcs
instance PersistFieldSql VersionControlSystem where
sqlType = sqlType . fmap versionControlSystemName
instance PersistField PatchMediaType where
toPersistValue = toPersistValue . renderPatchMediaType
fromPersistValue v = do
t <- fromPersistValue v
case parsePatchMediaType t of
Nothing -> Left $ "Unknown patch media type: " <> t
Just pmt -> Right pmt
instance PersistFieldSql PatchMediaType where
sqlType = sqlType . fmap renderPatchMediaType

View file

@ -85,7 +85,7 @@ import Crypto.PublicVerifKey
import Database.Persist.JSON import Database.Persist.JSON
import Network.FedURI import Network.FedURI
import Network.HTTP.Digest import Network.HTTP.Digest
import Web.ActivityPub hiding (Patch, Ticket, Follow) import Web.ActivityPub hiding (Patch, Ticket, Follow, Repo (..))
import Yesod.ActivityPub import Yesod.ActivityPub
import Yesod.Auth.Unverified import Yesod.Auth.Unverified
import Yesod.FedURI import Yesod.FedURI
@ -111,7 +111,7 @@ import Vervis.FedURI
import Vervis.Foundation import Vervis.Foundation
import Vervis.Model import Vervis.Model
import Vervis.Model.Ident import Vervis.Model.Ident
import Vervis.Model.Repo import Development.PatchMediaType
import Vervis.Model.Ticket import Vervis.Model.Ticket
import Vervis.RemoteActorStore import Vervis.RemoteActorStore
import Vervis.Settings import Vervis.Settings
@ -578,7 +578,7 @@ createTicketC (Entity pidUser personUser) sharerUser summary audience ticket muT
, projectInbox j , projectInbox j
, LocalActorProject shr prj , LocalActorProject shr prj
) )
Right (Entity _ r, _, _) -> Right (Entity _ r, _, _, _) ->
let rp = repoIdent r let rp = repoIdent r
in ( [ LocalPersonCollectionRepoTeam shr rp in ( [ LocalPersonCollectionRepoTeam shr rp
, LocalPersonCollectionRepoFollowers shr rp , LocalPersonCollectionRepoFollowers shr rp
@ -612,7 +612,7 @@ createTicketC (Entity pidUser personUser) sharerUser summary audience ticket muT
( Host ( Host
, LocalURI , LocalURI
, LocalURI , LocalURI
, Maybe (Maybe LocalURI, PatchType, NonEmpty Text) , Maybe (Maybe LocalURI, PatchMediaType, NonEmpty Text)
) )
, TextHtml , TextHtml
, TextHtml , TextHtml
@ -653,7 +653,7 @@ createTicketC (Entity pidUser personUser) sharerUser summary audience ticket muT
checkTicket checkTicket
:: AP.Ticket URIMode :: AP.Ticket URIMode
-> ExceptT Text Handler -> ExceptT Text Handler
( Either WorkItemTarget (Host, LocalURI, Maybe (Maybe LocalURI, PatchType, NonEmpty Text)) ( Either WorkItemTarget (Host, LocalURI, Maybe (Maybe LocalURI, PatchMediaType, NonEmpty Text))
, TextHtml , TextHtml
, TextHtml , TextHtml
, TextPandocMarkdown , TextPandocMarkdown
@ -679,7 +679,7 @@ createTicketC (Entity pidUser personUser) sharerUser summary audience ticket muT
-> MergeRequest URIMode -> MergeRequest URIMode
-> ExceptT Text Handler -> ExceptT Text Handler
( Either (ShrIdent, RpIdent, Maybe Text) FedURI ( Either (ShrIdent, RpIdent, Maybe Text) FedURI
, PatchType , PatchMediaType
, NonEmpty Text , NonEmpty Text
) )
checkMR h (MergeRequest muOrigin luTarget ebundle) = do checkMR h (MergeRequest muOrigin luTarget ebundle) = do
@ -724,7 +724,7 @@ createTicketC (Entity pidUser personUser) sharerUser summary audience ticket muT
:: Host :: Host
-> AP.Patch URIMode -> AP.Patch URIMode
-> ExceptT Text Handler -> ExceptT Text Handler
( PatchType ( PatchMediaType
, Text , Text
) )
checkPatch h (AP.Patch mlocal attrib mpub typ content) = do checkPatch h (AP.Patch mlocal attrib mpub typ content) = do
@ -741,7 +741,7 @@ createTicketC (Entity pidUser personUser) sharerUser summary audience ticket muT
FedURI FedURI
-> Maybe -> Maybe
( Either (ShrIdent, RpIdent, Maybe Text) FedURI ( Either (ShrIdent, RpIdent, Maybe Text) FedURI
, PatchType , PatchMediaType
, NonEmpty Text , NonEmpty Text
) )
-> ExceptT Text Handler -> ExceptT Text Handler
@ -749,7 +749,7 @@ createTicketC (Entity pidUser personUser) sharerUser summary audience ticket muT
WorkItemTarget WorkItemTarget
( Host ( Host
, LocalURI , LocalURI
, Maybe (Maybe LocalURI, PatchType, NonEmpty Text) , Maybe (Maybe LocalURI, PatchMediaType, NonEmpty Text)
) )
) )
matchContextAndMR (Left (Left (shr, prj))) Nothing = return $ Left $ WITProject shr prj matchContextAndMR (Left (Left (shr, prj))) Nothing = return $ Left $ WITProject shr prj
@ -760,17 +760,14 @@ createTicketC (Entity pidUser personUser) sharerUser summary audience ticket muT
case branch of case branch of
Left (shr', rp', mb) | shr == shr' && rp == rp' -> return mb Left (shr', rp', mb) | shr == shr' && rp == rp' -> return mb
_ -> throwE "MR target repo/branch and Ticket context repo mismatch" _ -> throwE "MR target repo/branch and Ticket context repo mismatch"
let vcs = typ2vcs typ case patchMediaTypeVCS typ of
case vcs of
VCSDarcs -> VCSDarcs ->
unless (isNothing branch') $ unless (isNothing branch') $
throwE "Darcs MR specifies a branch" throwE "Darcs MR specifies a branch"
VCSGit -> VCSGit ->
unless (isJust branch') $ unless (isJust branch') $
throwE "Git MR doesn't specify the branch" throwE "Git MR doesn't specify the branch"
return $ Left $ WITRepo shr rp branch' vcs diffs return $ Left $ WITRepo shr rp branch' typ diffs
where
typ2vcs PatchTypeDarcs = VCSDarcs
matchContextAndMR (Right (ObjURI h lu)) Nothing = return $ Right (h, lu, Nothing) matchContextAndMR (Right (ObjURI h lu)) Nothing = return $ Right (h, lu, Nothing)
matchContextAndMR (Right (ObjURI h lu)) (Just (branch, typ, diffs)) = do matchContextAndMR (Right (ObjURI h lu)) (Just (branch, typ, diffs)) = do
luBranch <- luBranch <-
@ -789,14 +786,14 @@ createTicketC (Entity pidUser personUser) sharerUser summary audience ticket muT
FedURI FedURI
-> Either -> Either
WorkItemTarget WorkItemTarget
(Host, LocalURI, Maybe (Maybe LocalURI, PatchType, NonEmpty Text)) (Host, LocalURI, Maybe (Maybe LocalURI, PatchMediaType, NonEmpty Text))
-> ExceptT Text Handler -> ExceptT Text Handler
(Either (Either
WorkItemTarget WorkItemTarget
( Host ( Host
, LocalURI , LocalURI
, LocalURI , LocalURI
, Maybe (Maybe LocalURI, PatchType, NonEmpty Text) , Maybe (Maybe LocalURI, PatchMediaType, NonEmpty Text)
) )
) )
checkTargetAndContext (Left _) (Right _) = checkTargetAndContext (Left _) (Right _) =
@ -836,14 +833,15 @@ createTicketC (Entity pidUser personUser) sharerUser summary audience ticket muT
ej@(Entity _ j) <- fromMaybeE mej "Local context: no such project" ej@(Entity _ j) <- fromMaybeE mej "Local context: no such project"
obiidAccept <- lift $ insertEmptyOutboxItem (projectOutbox j) now obiidAccept <- lift $ insertEmptyOutboxItem (projectOutbox j) now
return (shr, Left ej, obiidAccept) return (shr, Left ej, obiidAccept)
prepareProject now (Left (WITRepo shr rp mb vcs diff)) = Left <$> do prepareProject now (Left (WITRepo shr rp mb typ diff)) = Left <$> do
mer <- lift $ runMaybeT $ do mer <- lift $ runMaybeT $ do
sid <- MaybeT $ getKeyBy $ UniqueSharer shr sid <- MaybeT $ getKeyBy $ UniqueSharer shr
MaybeT $ getBy $ UniqueRepo rp sid MaybeT $ getBy $ UniqueRepo rp sid
er@(Entity _ r) <- fromMaybeE mer "Local context: no such repo" er@(Entity _ r) <- fromMaybeE mer "Local context: no such repo"
unless (repoVcs r == vcs) $ throwE "Repo VCS and patch VCS mismatch" unless (repoVcs r == patchMediaTypeVCS typ) $
throwE "Repo VCS and patch VCS mismatch"
obiidAccept <- lift $ insertEmptyOutboxItem (repoOutbox r) now obiidAccept <- lift $ insertEmptyOutboxItem (repoOutbox r) now
return (shr, Right (er, mb, diff), obiidAccept) return (shr, Right (er, mb, typ, diff), obiidAccept)
prepareProject _ (Right (iid, era, mlu, mpatch)) = lift $ Right <$> do prepareProject _ (Right (iid, era, mlu, mpatch)) = lift $ Right <$> do
let mlu' = let mlu' =
case mpatch of case mpatch of
@ -889,7 +887,7 @@ createTicketC (Entity pidUser personUser) sharerUser summary audience ticket muT
, ticketProjectLocalProject = jid , ticketProjectLocalProject = jid
} }
return Nothing return Nothing
Right (Entity rid _, mb, diffs) -> Just <$> do Right (Entity rid _, mb, typ, diffs) -> Just <$> do
insert_ TicketRepoLocal insert_ TicketRepoLocal
{ ticketRepoLocalContext = tclid { ticketRepoLocalContext = tclid
, ticketRepoLocalRepo = rid , ticketRepoLocalRepo = rid
@ -898,18 +896,18 @@ createTicketC (Entity pidUser personUser) sharerUser summary audience ticket muT
bnid <- insert $ Bundle tid bnid <- insert $ Bundle tid
(bnid,) . toNE <$> (bnid,) . toNE <$>
insertMany insertMany
(NE.toList $ NE.map (Patch bnid now) diffs) (NE.toList $ NE.map (Patch bnid now typ) diffs)
Right (Entity raid _, mroid, mbundle) -> do Right (Entity raid _, mroid, mbundle) -> do
insert_ TicketProjectRemote insert_ TicketProjectRemote
{ ticketProjectRemoteTicket = talid { ticketProjectRemoteTicket = talid
, ticketProjectRemoteTracker = raid , ticketProjectRemoteTracker = raid
, ticketProjectRemoteProject = mroid , ticketProjectRemoteProject = mroid
} }
for mbundle $ \ (_typ, diffs) -> do for mbundle $ \ (typ, diffs) -> do
bnid <- insert $ Bundle tid bnid <- insert $ Bundle tid
(bnid,) . toNE <$> (bnid,) . toNE <$>
insertMany insertMany
(NE.toList $ NE.map (Patch bnid now) diffs) (NE.toList $ NE.map (Patch bnid now typ) diffs)
return (talid, mbn) return (talid, mbn)
where where
toNE = fromMaybe (error "No Patch IDs returned from DB") . NE.nonEmpty toNE = fromMaybe (error "No Patch IDs returned from DB") . NE.nonEmpty
@ -930,7 +928,7 @@ createTicketC (Entity pidUser personUser) sharerUser summary audience ticket muT
Left (WITProject shr prj) -> Left (WITProject shr prj) ->
let uProject = encodeRouteHome $ ProjectR shr prj let uProject = encodeRouteHome $ ProjectR shr prj
in (uProject, uProject, Nothing) in (uProject, uProject, Nothing)
Left (WITRepo shr rp mb vcs diffs) -> Left (WITRepo shr rp mb typ diffs) ->
let uRepo = encodeRouteHome $ RepoR shr rp let uRepo = encodeRouteHome $ RepoR shr rp
(bnkhid, ptkhids) = (bnkhid, ptkhids) =
case mkh of case mkh of
@ -939,10 +937,6 @@ createTicketC (Entity pidUser personUser) sharerUser summary audience ticket muT
luBundle = luBundle =
encodeRouteLocal $ encodeRouteLocal $
SharerProposalBundleR shrUser talkhid bnkhid SharerProposalBundleR shrUser talkhid bnkhid
typ =
case vcs of
VCSDarcs -> PatchTypeDarcs
VCSGit -> error "createTicketC VCSGit"
mr = MergeRequest mr = MergeRequest
{ mrOrigin = Nothing { mrOrigin = Nothing
, mrTarget = , mrTarget =
@ -1081,7 +1075,7 @@ createTicketC (Entity pidUser personUser) sharerUser summary audience ticket muT
Left (Entity _ j) -> Left (Entity _ j) ->
let prj = projectIdent j let prj = projectIdent j
in (ProjectOutboxItemR shrJ prj, ProjectR shrJ prj) in (ProjectOutboxItemR shrJ prj, ProjectR shrJ prj)
Right (Entity _ r, _, _) -> Right (Entity _ r, _, _, _) ->
let rp = repoIdent r let rp = repoIdent r
in (RepoOutboxItemR shrJ rp, RepoR shrJ rp) in (RepoOutboxItemR shrJ rp, RepoR shrJ rp)
recips = map encodeRouteHome $ map renderLocalActor actors ++ map renderLocalPersonCollection colls recips = map encodeRouteHome $ map renderLocalActor actors ++ map renderLocalPersonCollection colls
@ -1342,14 +1336,15 @@ offerTicketC (Entity pidUser personUser) sharerUser summary audience ticket uTar
ej <- MaybeT $ getBy $ UniqueProject prj sid ej <- MaybeT $ getBy $ UniqueProject prj sid
return (s, ej) return (s, ej)
fromMaybeE mproj "Offer target no such local project in DB" fromMaybeE mproj "Offer target no such local project in DB"
Left (WITRepo shr rp mb vcs diffs) -> Just . Right <$> do Left (WITRepo shr rp mb typ diffs) -> Just . Right <$> do
mproj <- lift $ runMaybeT $ do mproj <- lift $ runMaybeT $ do
Entity sid s <- MaybeT $ getBy $ UniqueSharer shr Entity sid s <- MaybeT $ getBy $ UniqueSharer shr
er <- MaybeT $ getBy $ UniqueRepo rp sid er <- MaybeT $ getBy $ UniqueRepo rp sid
return (s, er) return (s, er)
(s, er@(Entity _ r)) <- fromMaybeE mproj "Offer target no such local repo in DB" (s, er@(Entity _ r)) <- fromMaybeE mproj "Offer target no such local repo in DB"
unless (repoVcs r == vcs) $ throwE "Patch type and repo VCS mismatch" unless (repoVcs r == patchMediaTypeVCS typ) $
return (s, er, mb, diffs) throwE "Patch type and repo VCS mismatch"
return (s, er, mb, typ, diffs)
Right _ -> return Nothing Right _ -> return Nothing
(obiid, doc, luOffer) <- lift $ insertOfferToOutbox shrUser now (personOutbox personUser) blinded (obiid, doc, luOffer) <- lift $ insertOfferToOutbox shrUser now (personOutbox personUser) blinded
remotesHttpOffer <- do remotesHttpOffer <- do
@ -1390,20 +1385,20 @@ offerTicketC (Entity pidUser personUser) sharerUser summary audience ticket uTar
let obid = let obid =
case project of case project of
Left (_, Entity _ j) -> projectOutbox j Left (_, Entity _ j) -> projectOutbox j
Right (_, Entity _ r, _, _) -> repoOutbox r Right (_, Entity _ r, _, _, _) -> repoOutbox r
obiidAccept <- insertEmptyOutboxItem obid now obiidAccept <- insertEmptyOutboxItem obid now
let insertTXL = let insertTXL =
case project of case project of
Left (_, Entity jid _) -> Left (_, Entity jid _) ->
\ tclid -> insert_ $ TicketProjectLocal tclid jid \ tclid -> insert_ $ TicketProjectLocal tclid jid
Right (_, Entity rid _, mb, _) -> Right (_, Entity rid _, mb, _, _) ->
\ tclid -> insert_ $ TicketRepoLocal tclid rid mb \ tclid -> insert_ $ TicketRepoLocal tclid rid mb
(tid, ltid) <- insertTicket pidUser now title desc source insertTXL obiid obiidAccept (tid, ltid) <- insertTicket pidUser now title desc source insertTXL obiid obiidAccept
case project of case project of
Left _ -> return () Left _ -> return ()
Right (_, _, _, diffs) -> do Right (_, _, _, typ, diffs) -> do
bnid <- insert $ Bundle tid bnid <- insert $ Bundle tid
insertMany_ $ NE.toList $ NE.map (Patch bnid now) diffs insertMany_ $ NE.toList $ NE.map (Patch bnid now typ) diffs
(docAccept, localRecipsAccept) <- insertAccept shrUser luOffer project obiidAccept ltid (docAccept, localRecipsAccept) <- insertAccept shrUser luOffer project obiidAccept ltid
let (actor, ibid) = let (actor, ibid) =
case project of case project of
@ -1411,7 +1406,7 @@ offerTicketC (Entity pidUser personUser) sharerUser summary audience ticket uTar
( LocalActorProject (sharerIdent s) (projectIdent j) ( LocalActorProject (sharerIdent s) (projectIdent j)
, projectInbox j , projectInbox j
) )
Right (s, Entity _ r, _, _) -> Right (s, Entity _ r, _, _, _) ->
( LocalActorRepo (sharerIdent s) (repoIdent r) ( LocalActorRepo (sharerIdent s) (repoIdent r)
, repoInbox r , repoInbox r
) )
@ -1430,7 +1425,7 @@ offerTicketC (Entity pidUser personUser) sharerUser summary audience ticket uTar
-> AP.Ticket URIMode -> AP.Ticket URIMode
-> FedURI -> FedURI
-> ExceptT Text Handler -> ExceptT Text Handler
( Either WorkItemTarget (Host, LocalURI, Maybe (Maybe LocalURI, PatchType, NonEmpty Text)) ( Either WorkItemTarget (Host, LocalURI, Maybe (Maybe LocalURI, PatchMediaType, NonEmpty Text))
, TextHtml , TextHtml
, TextHtml , TextHtml
, TextPandocMarkdown , TextPandocMarkdown
@ -1528,17 +1523,14 @@ offerTicketC (Entity pidUser personUser) sharerUser summary audience ticket uTar
case branch of case branch of
Left (shr', rp', mb) | shr == shr' && rp == rp' -> return mb Left (shr', rp', mb) | shr == shr' && rp == rp' -> return mb
_ -> throwE "MR target repo/branch and Offer target repo mismatch" _ -> throwE "MR target repo/branch and Offer target repo mismatch"
let vcs = typ2vcs typ case patchMediaTypeVCS typ of
case vcs of
VCSDarcs -> VCSDarcs ->
unless (isNothing branch') $ unless (isNothing branch') $
throwE "Darcs MR specifies a branch" throwE "Darcs MR specifies a branch"
VCSGit -> VCSGit ->
unless (isJust branch') $ unless (isJust branch') $
throwE "Git MR doesn't specify the branch" throwE "Git MR doesn't specify the branch"
return $ Left $ WITRepo shr rp branch' vcs diffs return $ Left $ WITRepo shr rp branch' typ diffs
where
typ2vcs PatchTypeDarcs = VCSDarcs
matchTargetAndMR (Right (ObjURI h lu)) Nothing = return $ Right (h, lu, Nothing) matchTargetAndMR (Right (ObjURI h lu)) Nothing = return $ Right (h, lu, Nothing)
matchTargetAndMR (Right (ObjURI h lu)) (Just (branch, typ, diffs)) = do matchTargetAndMR (Right (ObjURI h lu)) (Just (branch, typ, diffs)) = do
luBranch <- luBranch <-
@ -1612,7 +1604,7 @@ offerTicketC (Entity pidUser personUser) sharerUser summary audience ticket uTar
, ProjectR shr prj , ProjectR shr prj
, ProjectTicketR shr prj , ProjectTicketR shr prj
) )
Right (s, Entity _ r, _, _) -> Right (s, Entity _ r, _, _, _) ->
let shr = sharerIdent s let shr = sharerIdent s
rp = repoIdent r rp = repoIdent r
in ( [ LocalPersonCollectionRepoTeam shr rp in ( [ LocalPersonCollectionRepoTeam shr rp

View file

@ -121,7 +121,7 @@ import Vervis.Handler.Workflow
import Vervis.Migration (migrateDB) import Vervis.Migration (migrateDB)
import Vervis.Model import Vervis.Model
import Vervis.Model.Ident import Vervis.Model.Ident
import Vervis.Model.Repo import Development.PatchMediaType
import Vervis.Path import Vervis.Path
import Vervis.Settings import Vervis.Settings
import Vervis.Ssh (runSsh) import Vervis.Ssh (runSsh)
@ -244,7 +244,8 @@ makeFoundation appSettings = do
for_ rps $ \ (rp, vcs) -> for_ rps $ \ (rp, vcs) ->
putStrLn $ putStrLn $
"Found repo " ++ "Found repo " ++
shr ++ " / " ++ rp ++ " [" ++ show vcs ++ "]" shr ++ " / " ++ rp ++
" [" ++ T.unpack (versionControlSystemName vcs) ++ "]"
repoTreeFromDir = do repoTreeFromDir = do
dir <- askRepoRootDir dir <- askRepoRootDir
outers <- liftIO $ sort <$> listDirectory dir outers <- liftIO $ sort <$> listDirectory dir

View file

@ -28,7 +28,7 @@ import qualified Data.Text as T (concat)
import Vervis.Changes import Vervis.Changes
import Vervis.Foundation import Vervis.Foundation
import Vervis.Model.Ident import Vervis.Model.Ident
import Vervis.Model.Repo import Development.PatchMediaType
changeEntry :: ShrIdent -> RpIdent -> LogEntry -> FeedEntry (Route App) changeEntry :: ShrIdent -> RpIdent -> LogEntry -> FeedEntry (Route App)
changeEntry shr rp le = FeedEntry changeEntry shr rp le = FeedEntry

View file

@ -83,7 +83,7 @@ import Vervis.Changes
import Vervis.Foundation import Vervis.Foundation
import Vervis.Model import Vervis.Model
import Vervis.Model.Ident import Vervis.Model.Ident
import Vervis.Model.Repo import Development.PatchMediaType
import Vervis.Path import Vervis.Path
import Vervis.Readme import Vervis.Readme
import Vervis.Settings import Vervis.Settings

View file

@ -68,7 +68,7 @@ import qualified Data.Text.Lazy as TL
import Database.Persist.JSON import Database.Persist.JSON
import Network.FedURI import Network.FedURI
import Web.ActivityPub hiding (Patch, Ticket (..)) import Web.ActivityPub hiding (Patch, Ticket (..), Repo (..))
import Yesod.ActivityPub import Yesod.ActivityPub
import Yesod.FedURI import Yesod.FedURI
import Yesod.Hashids import Yesod.Hashids
@ -89,7 +89,7 @@ import Vervis.Federation.Util
import Vervis.Foundation import Vervis.Foundation
import Vervis.Model import Vervis.Model
import Vervis.Model.Ident import Vervis.Model.Ident
import Vervis.Model.Repo import Development.PatchMediaType
import Vervis.Model.Ticket import Vervis.Model.Ticket
import Vervis.Patch import Vervis.Patch
import Vervis.Ticket import Vervis.Ticket
@ -102,7 +102,7 @@ checkOfferTicket
-> ExceptT -> ExceptT
Text Text
Handler Handler
( Either WorkItemTarget (Host, LocalURI, Maybe (Maybe LocalURI, PatchType, NonEmpty Text)) ( Either WorkItemTarget (Host, LocalURI, Maybe (Maybe LocalURI, PatchMediaType, NonEmpty Text))
, TextHtml , TextHtml
, TextHtml , TextHtml
, TextPandocMarkdown , TextPandocMarkdown
@ -195,17 +195,14 @@ checkOfferTicket author ticket uTarget = do
case branch of case branch of
Left (shr', rp', mb) | shr == shr' && rp == rp' -> return mb Left (shr', rp', mb) | shr == shr' && rp == rp' -> return mb
_ -> throwE "MR target repo/branch and Offer target repo mismatch" _ -> throwE "MR target repo/branch and Offer target repo mismatch"
let vcs = typ2vcs typ case patchMediaTypeVCS typ of
case vcs of
VCSDarcs -> VCSDarcs ->
unless (isNothing branch') $ unless (isNothing branch') $
throwE "Darcs MR specifies a branch" throwE "Darcs MR specifies a branch"
VCSGit -> VCSGit ->
unless (isJust branch') $ unless (isJust branch') $
throwE "Git MR doesn't specify the branch" throwE "Git MR doesn't specify the branch"
return $ Left $ WITRepo shr rp branch' vcs diffs return $ Left $ WITRepo shr rp branch' typ diffs
where
typ2vcs PatchTypeDarcs = VCSDarcs
matchTargetAndMR (Right (ObjURI h lu)) Nothing = return $ Right (h, lu, Nothing) matchTargetAndMR (Right (ObjURI h lu)) Nothing = return $ Right (h, lu, Nothing)
matchTargetAndMR (Right (ObjURI h lu)) (Just (branch, typ, diffs)) = do matchTargetAndMR (Right (ObjURI h lu)) (Just (branch, typ, diffs)) = do
luBranch <- luBranch <-
@ -402,11 +399,12 @@ repoOfferTicketF
-> ExceptT Text Handler Text -> ExceptT Text Handler Text
repoOfferTicketF now shrRecip rpRecip author body mfwd luOffer ticket uTarget = do repoOfferTicketF now shrRecip rpRecip author body mfwd luOffer ticket uTarget = do
(target, summary, content, source) <- checkOfferTicket author ticket uTarget (target, summary, content, source) <- checkOfferTicket author ticket uTarget
mmhttp <- for (targetRelevance target) $ \ (mb, vcs, diffs) -> runDBExcept $ do mmhttp <- for (targetRelevance target) $ \ (mb, typ, diffs) -> runDBExcept $ do
Entity rid r <- lift $ do Entity rid r <- lift $ do
sid <- getKeyBy404 $ UniqueSharer shrRecip sid <- getKeyBy404 $ UniqueSharer shrRecip
getBy404 $ UniqueRepo rpRecip sid getBy404 $ UniqueRepo rpRecip sid
unless (repoVcs r == vcs) $ throwE "Patch type and repo VCS mismatch" unless (repoVcs r == patchMediaTypeVCS typ) $
throwE "Patch type and repo VCS mismatch"
mractid <- lift $ insertToInbox now author body (repoInbox r) luOffer False mractid <- lift $ insertToInbox now author body (repoInbox r) luOffer False
lift $ for mractid $ \ ractid -> do lift $ for mractid $ \ ractid -> do
mremotesHttpFwd <- for mfwd $ \ (localRecips, sig) -> do mremotesHttpFwd <- for mfwd $ \ (localRecips, sig) -> do
@ -427,7 +425,7 @@ repoOfferTicketF now shrRecip rpRecip author body mfwd luOffer ticket uTarget =
let makeTRL tclid = TicketRepoLocal tclid rid mb let makeTRL tclid = TicketRepoLocal tclid rid mb
(tid, ltid) <- insertLocalTicket now author makeTRL summary content source ractid obiidAccept (tid, ltid) <- insertLocalTicket now author makeTRL summary content source ractid obiidAccept
bnid <- insert $ Bundle tid bnid <- insert $ Bundle tid
insertMany_ $ NE.toList $ NE.map (Patch bnid now) diffs insertMany_ $ NE.toList $ NE.map (Patch bnid now typ) diffs
(docAccept, localRecipsAccept, remoteRecipsAccept, fwdHostsAccept) <- (docAccept, localRecipsAccept, remoteRecipsAccept, fwdHostsAccept) <-
insertAccept shrRecip rpRecip author luOffer ltid obiidAccept insertAccept shrRecip rpRecip author luOffer ltid obiidAccept
knownRemoteRecipsAccept <- knownRemoteRecipsAccept <-
@ -502,7 +500,7 @@ repoOfferTicketF now shrRecip rpRecip author body mfwd luOffer ticket uTarget =
data RemoteBundle = RemoteBundle data RemoteBundle = RemoteBundle
{ rpBranch :: Maybe LocalURI { rpBranch :: Maybe LocalURI
, rpType :: PatchType , rpType :: PatchMediaType
, rpDiffs :: NonEmpty Text , rpDiffs :: NonEmpty Text
} }
@ -603,7 +601,7 @@ checkCreateTicket author ticket muTarget = do
-> MergeRequest URIMode -> MergeRequest URIMode
-> ExceptT Text Handler -> ExceptT Text Handler
( Either (ShrIdent, RpIdent, Maybe Text) FedURI ( Either (ShrIdent, RpIdent, Maybe Text) FedURI
, PatchType , PatchMediaType
, NonEmpty (Maybe LocalURI, Maybe UTCTime, Text) , NonEmpty (Maybe LocalURI, Maybe UTCTime, Text)
) )
checkMR luTicket h (MergeRequest muOrigin luTarget ebundle) = do checkMR luTicket h (MergeRequest muOrigin luTarget ebundle) = do
@ -665,7 +663,7 @@ checkCreateTicket author ticket muTarget = do
-> ExceptT Text Handler -> ExceptT Text Handler
( Maybe (LocalURI, LocalURI) ( Maybe (LocalURI, LocalURI)
, Maybe UTCTime , Maybe UTCTime
, PatchType , PatchMediaType
, Text , Text
) )
checkPatch h (AP.Patch mlocal attrib mpub typ content) = do checkPatch h (AP.Patch mlocal attrib mpub typ content) = do
@ -686,7 +684,7 @@ checkCreateTicket author ticket muTarget = do
FedURI FedURI
-> Maybe -> Maybe
( Either (ShrIdent, RpIdent, Maybe Text) FedURI ( Either (ShrIdent, RpIdent, Maybe Text) FedURI
, PatchType , PatchMediaType
, NonEmpty (Maybe LocalURI, Maybe UTCTime, Text) , NonEmpty (Maybe LocalURI, Maybe UTCTime, Text)
) )
-> ExceptT Text Handler (Either WorkItemTarget (Host, LocalURI, Maybe RemoteBundle)) -> ExceptT Text Handler (Either WorkItemTarget (Host, LocalURI, Maybe RemoteBundle))
@ -698,8 +696,7 @@ checkCreateTicket author ticket muTarget = do
case branch of case branch of
Left (shr', rp', mb) | shr == shr' && rp == rp' -> return mb Left (shr', rp', mb) | shr == shr' && rp == rp' -> return mb
_ -> throwE "MR target repo/branch and Offer target repo mismatch" _ -> throwE "MR target repo/branch and Offer target repo mismatch"
let vcs = typ2vcs typ case patchMediaTypeVCS typ of
case vcs of
VCSDarcs -> VCSDarcs ->
unless (isNothing branch') $ unless (isNothing branch') $
throwE "Darcs MR specifies a branch" throwE "Darcs MR specifies a branch"
@ -711,9 +708,7 @@ checkCreateTicket author ticket muTarget = do
unless (pub == pub') $ unless (pub == pub') $
throwE "Ticket & Patch 'published' differ" throwE "Ticket & Patch 'published' differ"
return diff return diff
return $ Left $ WITRepo shr rp branch' vcs diffs return $ Left $ WITRepo shr rp branch' typ diffs
where
typ2vcs PatchTypeDarcs = VCSDarcs
matchTicketAndMR _ _ (Right (ObjURI h lu)) Nothing = return $ Right (h, lu, Nothing) matchTicketAndMR _ _ (Right (ObjURI h lu)) Nothing = return $ Right (h, lu, Nothing)
matchTicketAndMR luTicket pub (Right (ObjURI h lu)) (Just (branch, typ, patches)) = do matchTicketAndMR luTicket pub (Right (ObjURI h lu)) (Just (branch, typ, patches)) = do
luBranch <- luBranch <-
@ -1005,11 +1000,12 @@ repoCreateTicketF
repoCreateTicketF now shrRecip rpRecip author body mfwd luCreate ticket muTarget = do repoCreateTicketF now shrRecip rpRecip author body mfwd luCreate ticket muTarget = do
ParsedCreateTicket targetAndContext tlocal published title desc src <- ParsedCreateTicket targetAndContext tlocal published title desc src <-
checkCreateTicket author ticket muTarget checkCreateTicket author ticket muTarget
mmhttp <- for (targetRelevance targetAndContext) $ \ (mb, vcs, diffs) -> runDBExcept $ do mmhttp <- for (targetRelevance targetAndContext) $ \ (mb, typ, diffs) -> runDBExcept $ do
Entity rid r <- lift $ do Entity rid r <- lift $ do
sid <- getKeyBy404 $ UniqueSharer shrRecip sid <- getKeyBy404 $ UniqueSharer shrRecip
getBy404 $ UniqueRepo rpRecip sid getBy404 $ UniqueRepo rpRecip sid
unless (repoVcs r == vcs) $ throwE "Patch type and repo VCS mismatch" unless (repoVcs r == patchMediaTypeVCS typ) $
throwE "Patch type and repo VCS mismatch"
mractid <- lift $ insertToInbox now author body (repoInbox r) luCreate False mractid <- lift $ insertToInbox now author body (repoInbox r) luCreate False
lift $ for mractid $ \ ractid -> do lift $ for mractid $ \ ractid -> do
obiidAccept <- insertEmptyOutboxItem (repoOutbox r) now obiidAccept <- insertEmptyOutboxItem (repoOutbox r) now
@ -1018,7 +1014,7 @@ repoCreateTicketF now shrRecip rpRecip author body mfwd luCreate ticket muTarget
unless (isRight result) $ delete obiidAccept unless (isRight result) $ delete obiidAccept
for result $ \ tid -> do for result $ \ tid -> do
bnid <- insert $ Bundle tid bnid <- insert $ Bundle tid
insertMany_ $ NE.toList $ NE.map (Patch bnid published) diffs insertMany_ $ NE.toList $ NE.map (Patch bnid published typ) diffs
mremotesHttpFwd <- for mfwd $ \ (localRecips, sig) -> do mremotesHttpFwd <- for mfwd $ \ (localRecips, sig) -> do
let sieve = let sieve =
makeRecipientSet makeRecipientSet

View file

@ -38,7 +38,7 @@ import Vervis.Field.Project
import Vervis.Foundation import Vervis.Foundation
import Vervis.Model import Vervis.Model
import Vervis.Model.Ident import Vervis.Model.Ident
import Vervis.Model.Repo import Development.PatchMediaType
import Vervis.Model.Workflow import Vervis.Model.Workflow
data NewProject = NewProject data NewProject = NewProject

View file

@ -32,7 +32,7 @@ import Vervis.Field.Repo
import Vervis.Foundation import Vervis.Foundation
import Vervis.Model import Vervis.Model
import Vervis.Model.Ident import Vervis.Model.Ident
import Vervis.Model.Repo import Development.PatchMediaType
data NewRepo = NewRepo data NewRepo = NewRepo
{ nrpIdent :: RpIdent { nrpIdent :: RpIdent

View file

@ -84,7 +84,7 @@ import Vervis.Changes
import Vervis.Foundation import Vervis.Foundation
import Vervis.Model import Vervis.Model
import Vervis.Model.Ident import Vervis.Model.Ident
import Vervis.Model.Repo import Development.PatchMediaType
import Vervis.Path import Vervis.Path
import Vervis.Readme import Vervis.Readme
import Vervis.Settings import Vervis.Settings

View file

@ -89,7 +89,7 @@ import Vervis.Form.Ticket
import Vervis.Foundation import Vervis.Foundation
import Vervis.Model import Vervis.Model
import Vervis.Model.Ident import Vervis.Model.Ident
import Vervis.Model.Repo import Development.PatchMediaType
import Vervis.Path import Vervis.Path
import Vervis.Settings import Vervis.Settings
import Vervis.Ticket import Vervis.Ticket

View file

@ -37,7 +37,7 @@ import Vervis.Darcs
import Vervis.Foundation import Vervis.Foundation
import Vervis.Model import Vervis.Model
import Vervis.Model.Ident import Vervis.Model.Ident
import Vervis.Model.Repo import Development.PatchMediaType
import Vervis.Path import Vervis.Path
import Vervis.Settings import Vervis.Settings

View file

@ -52,7 +52,7 @@ import qualified Data.List.Ordered as LO
import qualified Database.Esqueleto as E import qualified Database.Esqueleto as E
import Network.FedURI import Network.FedURI
import Web.ActivityPub hiding (Ticket (..), Patch (..), Bundle (..)) import Web.ActivityPub hiding (Ticket (..), Patch (..), Bundle (..), Repo (..))
import Yesod.ActivityPub import Yesod.ActivityPub
import Yesod.FedURI import Yesod.FedURI
import Yesod.Hashids import Yesod.Hashids
@ -69,7 +69,7 @@ import Vervis.FedURI
import Vervis.Foundation import Vervis.Foundation
import Vervis.Model import Vervis.Model
import Vervis.Model.Ident import Vervis.Model.Ident
import Vervis.Model.Repo import Development.PatchMediaType
import Vervis.Model.Ticket import Vervis.Model.Ticket
import Vervis.Paginate import Vervis.Paginate
import Vervis.Patch import Vervis.Patch
@ -309,20 +309,14 @@ getSharerProposalBundlePatchR
-> KeyHashid Patch -> KeyHashid Patch
-> Handler TypedContent -> Handler TypedContent
getSharerProposalBundlePatchR shr talkhid bnkhid ptkhid = do getSharerProposalBundlePatchR shr talkhid bnkhid ptkhid = do
(vcs, patch) <- runDB $ do patch <- runDB $ do
(_, _, _, repo, _, vers) <- getSharerProposal404 shr talkhid (_, _, _, _, _, vers) <- getSharerProposal404 shr talkhid
bnid <- decodeKeyHashid404 bnkhid bnid <- decodeKeyHashid404 bnkhid
unless (bnid `elem` vers) notFound unless (bnid `elem` vers) notFound
ptid <- decodeKeyHashid404 ptkhid ptid <- decodeKeyHashid404 ptkhid
pt <- get404 ptid pt <- get404 ptid
unless (patchBundle pt == bnid) notFound unless (patchBundle pt == bnid) notFound
vcs <- return pt
case repo of
Left (_, Entity _ trl) ->
repoVcs <$> getJust (ticketRepoLocalRepo trl)
Right _ ->
error "TODO determine mediaType of patch of remote repo"
return (vcs, pt)
encodeRouteLocal <- getEncodeRouteLocal encodeRouteLocal <- getEncodeRouteLocal
hLocal <- getsYesod siteInstanceHost hLocal <- getsYesod siteInstanceHost
@ -339,10 +333,7 @@ getSharerProposalBundlePatchR shr talkhid bnkhid ptkhid = do
) )
, AP.patchAttributedTo = encodeRouteLocal $ SharerR shr , AP.patchAttributedTo = encodeRouteLocal $ SharerR shr
, AP.patchPublished = Just $ patchCreated patch , AP.patchPublished = Just $ patchCreated patch
, AP.patchType = , AP.patchType = patchType patch
case vcs of
VCSDarcs -> PatchTypeDarcs
VCSGit -> error "TODO add PatchType for git patches"
, AP.patchContent = patchContent patch , AP.patchContent = patchContent patch
} }
provideHtmlAndAP patchAP $ redirectToPrettyJSON here provideHtmlAndAP patchAP $ redirectToPrettyJSON here
@ -663,11 +654,9 @@ getRepoProposalBundlePatchR
-> KeyHashid Patch -> KeyHashid Patch
-> Handler TypedContent -> Handler TypedContent
getRepoProposalBundlePatchR shr rp ltkhid bnkhid ptkhid = do getRepoProposalBundlePatchR shr rp ltkhid bnkhid ptkhid = do
(vcs, patch, author) <- runDB $ do (patch, author) <- runDB $ do
(_, Entity _ repo, _, _, _, _, ta, _, vers) <- getRepoProposal404 shr rp ltkhid (_, _, _, _, _, _, ta, _, vers) <- getRepoProposal404 shr rp ltkhid
(,,) (,) <$> do bnid <- decodeKeyHashid404 bnkhid
<$> pure (repoVcs repo)
<*> do bnid <- decodeKeyHashid404 bnkhid
unless (bnid `elem` vers) notFound unless (bnid `elem` vers) notFound
ptid <- decodeKeyHashid404 ptkhid ptid <- decodeKeyHashid404 ptkhid
pt <- get404 ptid pt <- get404 ptid
@ -709,10 +698,7 @@ getRepoProposalBundlePatchR shr rp ltkhid bnkhid ptkhid = do
encodeRouteLocal $ SharerR $ sharerIdent sharer encodeRouteLocal $ SharerR $ sharerIdent sharer
Right (_, object) -> remoteObjectIdent object Right (_, object) -> remoteObjectIdent object
, AP.patchPublished = Just $ patchCreated patch , AP.patchPublished = Just $ patchCreated patch
, AP.patchType = , AP.patchType = patchType patch
case vcs of
VCSDarcs -> PatchTypeDarcs
VCSGit -> error "TODO add PatchType for git patches"
, AP.patchContent = patchContent patch , AP.patchContent = patchContent patch
} }
provideHtmlAndAP' host patchAP $ redirectToPrettyJSON here provideHtmlAndAP' host patchAP $ redirectToPrettyJSON here

View file

@ -47,7 +47,7 @@ import Yesod.Persist.Core (runDB, get404, getBy404)
import qualified Database.Esqueleto as E import qualified Database.Esqueleto as E
import Network.FedURI import Network.FedURI
import Web.ActivityPub hiding (Project (..)) import Web.ActivityPub hiding (Project (..), Repo (..))
import Yesod.ActivityPub import Yesod.ActivityPub
import Yesod.FedURI import Yesod.FedURI
@ -63,7 +63,7 @@ import Vervis.Form.Project
import Vervis.Foundation import Vervis.Foundation
import Vervis.Model import Vervis.Model
import Vervis.Model.Ident import Vervis.Model.Ident
import Vervis.Model.Repo import Development.PatchMediaType
import Vervis.Settings import Vervis.Settings
import Vervis.Widget.Project import Vervis.Widget.Project
import Vervis.Widget.Sharer import Vervis.Widget.Sharer

View file

@ -88,7 +88,7 @@ import qualified Database.Esqueleto as E
import Data.MediaType import Data.MediaType
import Network.FedURI import Network.FedURI
import Web.ActivityPub hiding (Repo, Project) import Web.ActivityPub hiding (Repo (..), Project)
import Yesod.ActivityPub import Yesod.ActivityPub
import Yesod.FedURI import Yesod.FedURI
import Yesod.Hashids import Yesod.Hashids
@ -115,7 +115,7 @@ import Vervis.Handler.Repo.Git
import Vervis.Path import Vervis.Path
import Vervis.Model import Vervis.Model
import Vervis.Model.Ident import Vervis.Model.Ident
import Vervis.Model.Repo import Development.PatchMediaType
import Vervis.Paginate import Vervis.Paginate
import Vervis.Readme import Vervis.Readme
import Vervis.Settings import Vervis.Settings
@ -246,6 +246,7 @@ getRepoR shr rp = do
, actorSshKeys = [] , actorSshKeys = []
} }
, AP.repoTeam = encodeRouteLocal $ RepoTeamR shr rp , AP.repoTeam = encodeRouteLocal $ RepoTeamR shr rp
, AP.repoVcs = repoVcs repo
} }
dir = case repoVcs repo of dir = case repoVcs repo of
VCSDarcs -> [] VCSDarcs -> []

View file

@ -66,7 +66,7 @@ import Vervis.Foundation
import Vervis.Path import Vervis.Path
import Vervis.Model import Vervis.Model
import Vervis.Model.Ident import Vervis.Model.Ident
import Vervis.Model.Repo import Development.PatchMediaType
import Vervis.Paginate import Vervis.Paginate
import Vervis.Readme import Vervis.Readme
import Vervis.Settings import Vervis.Settings

View file

@ -80,7 +80,7 @@ import Vervis.Foundation
import Vervis.Path import Vervis.Path
import Vervis.Model import Vervis.Model
import Vervis.Model.Ident import Vervis.Model.Ident
import Vervis.Model.Repo import Development.PatchMediaType
import Vervis.Paginate import Vervis.Paginate
import Vervis.Readme import Vervis.Readme
import Vervis.Settings import Vervis.Settings

View file

@ -34,7 +34,7 @@ import Vervis.Foundation
import Data.MediaType import Data.MediaType
import Vervis.Model import Vervis.Model
import Vervis.Model.Ident import Vervis.Model.Ident
import Vervis.Model.Repo import Development.PatchMediaType
import Vervis.Path (askRepoDir) import Vervis.Path (askRepoDir)
import Yesod.RenderSource import Yesod.RenderSource
import Vervis.Settings (widgetFile) import Vervis.Settings (widgetFile)

View file

@ -1773,6 +1773,18 @@ changes hLocal ctx =
"Bundle" "Bundle"
-- 281 -- 281
, removeField "Patch" "ticket" , removeField "Patch" "ticket"
-- 282
, unchecked $ lift $ do
ers <- selectList ([] :: [Filter Repo282]) []
for_ ers $ \ (Entity rid r) -> do
vcs <-
case repo282Vcs r of
"VCSDarcs" -> return "Darcs"
"VCSGit" -> return "Git"
_ -> error "Weird repoVcs"
update rid [Repo282Vcs =. vcs]
-- 283
, addFieldPrimRequired "Patch" ("???" :: Text) "type"
] ]
migrateDB migrateDB

View file

@ -243,6 +243,8 @@ module Vervis.Migration.Model
, Bundle280Generic (..) , Bundle280Generic (..)
, Patch280 , Patch280
, Patch280Generic (..) , Patch280Generic (..)
, Repo282
, Repo282Generic (..)
) )
where where
@ -260,7 +262,7 @@ import Vervis.Migration.TH (schema)
import Vervis.Model (SharerId) import Vervis.Model (SharerId)
import Vervis.Model.Group import Vervis.Model.Group
import Vervis.Model.Ident import Vervis.Model.Ident
import Vervis.Model.Repo import Development.PatchMediaType
import Vervis.Model.Role import Vervis.Model.Role
import Vervis.Model.TH import Vervis.Model.TH
import Vervis.Model.Workflow import Vervis.Model.Workflow
@ -476,3 +478,6 @@ model_2020_08_10 = $(schema "2020_08_10_bundle")
makeEntitiesMigration "280" makeEntitiesMigration "280"
$(modelFile "migrations/2020_08_10_bundle_mig.model") $(modelFile "migrations/2020_08_10_bundle_mig.model")
makeEntitiesMigration "282"
$(modelFile "migrations/2020_08_13_vcs.model")

View file

@ -34,13 +34,14 @@ import Crypto.PublicVerifKey
import Database.Persist.EmailAddress import Database.Persist.EmailAddress
import Database.Persist.Graph.Class import Database.Persist.Graph.Class
import Database.Persist.JSON import Database.Persist.JSON
import Development.PatchMediaType
import Development.PatchMediaType.Persist
import Network.FedURI import Network.FedURI
import Web.ActivityPub (Doc, Activity) import Web.ActivityPub (Doc, Activity)
import Vervis.FedURI import Vervis.FedURI
import Vervis.Model.Group import Vervis.Model.Group
import Vervis.Model.Ident import Vervis.Model.Ident
import Vervis.Model.Repo
import Vervis.Model.Role import Vervis.Model.Role
import Vervis.Model.Ticket import Vervis.Model.Ticket
import Vervis.Model.TH import Vervis.Model.TH

View file

@ -1,26 +0,0 @@
{- 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.Model.Repo
( VersionControlSystem (..)
)
where
import Database.Persist.TH
data VersionControlSystem = VCSGit | VCSDarcs
deriving (Eq, Show, Read)
derivePersistField "VersionControlSystem"

View file

@ -55,7 +55,7 @@ import Vervis.FedURI
import Vervis.Foundation import Vervis.Foundation
import Vervis.Model import Vervis.Model
import Vervis.Model.Ident import Vervis.Model.Ident
import Vervis.Model.Repo import Development.PatchMediaType
import Vervis.Patch import Vervis.Patch
import Vervis.Ticket import Vervis.Ticket
@ -242,4 +242,4 @@ getWorkItemDetail name v = do
data WorkItemTarget data WorkItemTarget
= WITProject ShrIdent PrjIdent = WITProject ShrIdent PrjIdent
| WITRepo ShrIdent RpIdent (Maybe Text) VersionControlSystem (NonEmpty Text) | WITRepo ShrIdent RpIdent (Maybe Text) PatchMediaType (NonEmpty Text)

View file

@ -46,7 +46,6 @@ module Web.ActivityPub
, TicketDependency (..) , TicketDependency (..)
, TextHtml (..) , TextHtml (..)
, TextPandocMarkdown (..) , TextPandocMarkdown (..)
, PatchType (..)
, PatchLocal (..) , PatchLocal (..)
, Patch (..) , Patch (..)
, BundleLocal (..) , BundleLocal (..)
@ -147,6 +146,8 @@ import qualified Network.HTTP.Signature as S
import qualified Text.Email.Parser as E import qualified Text.Email.Parser as E
import Crypto.PublicVerifKey import Crypto.PublicVerifKey
import Development.PatchMediaType
import Development.PatchMediaType.JSON
import Network.FedURI import Network.FedURI
import Network.HTTP.Digest import Network.HTTP.Digest
@ -402,10 +403,11 @@ instance ActivityPub Actor where
data Repo u = Repo data Repo u = Repo
{ repoActor :: Actor u { repoActor :: Actor u
, repoTeam :: LocalURI , repoTeam :: LocalURI
, repoVcs :: VersionControlSystem
} }
instance ActivityPub Repo where instance ActivityPub Repo where
jsonldContext _ = [as2Context, secContext, forgeContext, extContext] jsonldContext _ = [as2Context, secContext, forgeContext]
parseObject o = do parseObject o = do
(h, a) <- parseObject o (h, a) <- parseObject o
unless (actorType a == ActorTypeRepo) $ unless (actorType a == ActorTypeRepo) $
@ -413,9 +415,11 @@ instance ActivityPub Repo where
fmap (h,) $ fmap (h,) $
Repo a Repo a
<$> withAuthorityO h (o .:| "team") <$> withAuthorityO h (o .:| "team")
toSeries authority (Repo actor team) <*> o .: "versionControlSystem"
toSeries authority (Repo actor team vcs)
= toSeries authority actor = toSeries authority actor
<> "team" .= ObjURI authority team <> "team" .= ObjURI authority team
<> "versionControlSystem" .= vcs
data Project u = Project data Project u = Project
{ projectActor :: Actor u { projectActor :: Actor u
@ -875,7 +879,7 @@ data Patch u = Patch
{ patchLocal :: Maybe (Authority u, PatchLocal) { patchLocal :: Maybe (Authority u, PatchLocal)
, patchAttributedTo :: LocalURI , patchAttributedTo :: LocalURI
, patchPublished :: Maybe UTCTime , patchPublished :: Maybe UTCTime
, patchType :: PatchType , patchType :: PatchMediaType
, patchContent :: Text , patchContent :: Text
} }

View file

@ -85,6 +85,9 @@ library
Database.Persist.Local Database.Persist.Local
Database.Persist.Local.Class.PersistEntityHierarchy Database.Persist.Local.Class.PersistEntityHierarchy
Database.Persist.Local.RecursionDoc Database.Persist.Local.RecursionDoc
Development.PatchMediaType
Development.PatchMediaType.JSON
Development.PatchMediaType.Persist
Diagrams.IntransitiveDAG Diagrams.IntransitiveDAG
Formatting.CaseInsensitive Formatting.CaseInsensitive
Language.Haskell.TH.Quote.Local Language.Haskell.TH.Quote.Local
@ -184,7 +187,6 @@ library
Vervis.Model.Entity Vervis.Model.Entity
Vervis.Model.Group Vervis.Model.Group
Vervis.Model.Ident Vervis.Model.Ident
Vervis.Model.Repo
Vervis.Model.Role Vervis.Model.Role
Vervis.Model.Ticket Vervis.Model.Ticket
Vervis.Model.TH Vervis.Model.TH