Federated forge server
Clone
HTTPS:
git clone https://vervis.peers.community/repos/rjQ3E
SSH:
git clone USERNAME@vervis.peers.community:rjQ3E
Branches
Tags
F3.hs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 | {- This file is part of Vervis.
-
- Written in 2024 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 Data.F3
( Identifier
, Markdown
, Comment (..)
, IssueState (..)
, Issue (..)
, ExtIssueTracker (..)
, Reaction (..)
, Vcs (..)
, ExtRepo (..)
)
where
import Control.Monad
import Data.Aeson
import Data.Maybe
import Data.Text (Text)
import Data.Time.Clock
import Web.Text
import Data.Aeson.Local
infixr 8 .=??
(.=??) :: ToJSON v => Key -> Maybe v -> Maybe (Key, Value)
k .=?? mv = (k .=) <$> mv
-- Custom extensions:
--
-- * New properties prefixed with @ext@
-- * New object types prefixed with @Ext@
type Identifier = Text
type Markdown = Text
data Comment = Comment
{ commentIndex :: Identifier
, commentPoster :: Identifier
, commentCreated :: UTCTime
, commentUpdated :: UTCTime
, commentContent :: PandocMarkdown
, commentReactions :: [Reaction]
, extCommentReplies :: [Comment]
}
instance FromJSON Comment where
parseJSON = withObject "Comment" $ \ o -> Comment
<$> o .: "index"
<*> o .: "poster_id"
<*> o .: "created"
<*> o .: "updated"
<*> o .: "content"
<*> o .: "reactions"
<*> o .: "replies"
instance ToJSON Comment where
toJSON c = object
[ "index" .= commentIndex c
, "poster_id" .= commentPoster c
, "created" .= commentCreated c
, "updated" .= commentUpdated c
, "content" .= commentContent c
, "reactions" .= commentReactions c
, "replies" .= extCommentReplies c
]
toEncoding c = pairs
( "index" .= commentIndex c
<> "poster_id" .= commentPoster c
<> "created" .= commentCreated c
<> "updated" .= commentUpdated c
<> "content" .= commentContent c
<> "reactions" .= commentReactions c
<> "replies" .= extCommentReplies c
)
data IssueState = IssueOpen | IssueClosed
instance FromJSON IssueState where
parseJSON = withText "IssueState" $ \case
"open" -> pure IssueOpen
"closed" -> pure IssueClosed
_ -> mzero
renderIssueState :: IssueState -> Text
renderIssueState = \case
IssueOpen -> "open"
IssueClosed -> "closed"
instance ToJSON IssueState where
toJSON = toJSON . renderIssueState
toEncoding = toEncoding . renderIssueState
data Issue = Issue
{ issueIndex :: Identifier
, issuePoster :: Identifier
, issueTitle :: Text
, issueContent :: PandocMarkdown
, issueMilestone :: Maybe Identifier
, issueState :: IssueState
, issueIsLocked :: Bool
, issueCreated :: UTCTime
, issueUpdated :: UTCTime
, issueClosed :: Maybe UTCTime
, issueDue :: Maybe UTCTime
, issueLabels :: [Identifier]
, issueReactions :: [Reaction]
, issueAssignees :: [Text]
, extIssueComments :: [Comment]
}
instance FromJSON Issue where
parseJSON = withObject "Issue" $ \ o -> Issue
<$> o .: "index"
<*> o .: "poster_id"
<*> o .: "title"
<*> o .: "content"
<*> o .:? "milestone"
<*> o .: "state"
<*> o .: "is_locked"
<*> o .: "created"
<*> o .: "updated"
<*> o .:? "closed"
<*> o .:? "due"
<*> o .: "labels"
<*> o .: "reactions"
<*> o .: "assignees"
<*> o .: "comments"
instance ToJSON Issue where
toJSON i = object $
[ "index" .= issueIndex i
, "poster_id" .= issuePoster i
, "title" .= issueTitle i
, "content" .= issueContent i
, "state" .= issueState i
, "is_locked" .= issueIsLocked i
, "created" .= issueCreated i
, "updated" .= issueUpdated i
, "labels" .= issueLabels i
, "reactions" .= issueReactions i
, "assignees" .= issueAssignees i
, "comments" .= extIssueComments i
]
++ catMaybes
[ "milestone" .=?? issueMilestone i
, "closed" .=?? issueClosed i
, "due" .=?? issueDue i
]
toEncoding i = pairs
( "index" .= issueIndex i
<> "poster_id" .= issuePoster i
<> "title" .= issueTitle i
<> "content" .= issueContent i
<> "milestone" .=? issueMilestone i
<> "state" .= issueState i
<> "is_locked" .= issueIsLocked i
<> "created" .= issueCreated i
<> "updated" .= issueUpdated i
<> "closed" .=? issueClosed i
<> "due" .=? issueDue i
<> "labels" .= issueLabels i
<> "reactions" .= issueReactions i
<> "assignees" .= issueAssignees i
<> "comments" .= extIssueComments i
)
-- Based on the properties of Project
data ExtIssueTracker = IssueTracker
{ issueTrackerIndex :: Identifier
, issueTrackerName :: Text
, issueTrackerDescription :: Markdown
, issueTrackerCreated :: UTCTime
, issueTrackerUpdated :: UTCTime
, issueTrackerIssues :: [Issue]
}
instance FromJSON ExtIssueTracker where
parseJSON = withObject "IssueTracker" $ \ o -> IssueTracker
<$> o .: "index"
<*> o .: "name"
<*> o .: "description"
<*> o .: "created"
<*> o .: "updated"
<*> o .: "issues"
instance ToJSON ExtIssueTracker where
toJSON it = object
[ "index" .= issueTrackerIndex it
, "name" .= issueTrackerName it
, "description" .= issueTrackerDescription it
, "created" .= issueTrackerCreated it
, "updated" .= issueTrackerUpdated it
, "issues" .= issueTrackerIssues it
]
toEncoding it = pairs
( "index" .= issueTrackerIndex it
<> "name" .= issueTrackerName it
<> "description" .= issueTrackerDescription it
<> "created" .= issueTrackerCreated it
<> "updated" .= issueTrackerUpdated it
<> "issues" .= issueTrackerIssues it
)
data Reaction = Reaction
{ reactionIndex :: Identifier
, reactionUser :: Identifier
, reactionContent :: Text
}
instance FromJSON Reaction where
parseJSON = withObject "Reaction" $ \ o -> Reaction
<$> o .: "index"
<*> o .: "user_id"
<*> o .: "content"
instance ToJSON Reaction where
toJSON r = object
[ "index" .= reactionIndex r
, "user_id" .= reactionUser r
, "content" .= reactionContent r
]
toEncoding r = pairs
( "index" .= reactionIndex r
<> "user_id" .= reactionUser r
<> "content" .= reactionContent r
)
data Vcs = Git | Hg | Bazaar | Darcs | Fossil | Svn
renderVcs :: Vcs -> Text
renderVcs = \case
Git -> "git"
Hg -> "hg"
Bazaar -> "bazaar"
Darcs -> "darcs"
Fossil -> "fossil"
Svn -> "svn"
parseVcs :: Text -> Maybe Vcs
parseVcs = \case
"git" -> Just Git
"hg" -> Just Hg
"bazaar" -> Just Bazaar
"darcs" -> Just Darcs
"fossil" -> Just Fossil
"svn" -> Just Svn
_ -> Nothing
instance FromJSON Vcs where
parseJSON = withText "Vcs" $ maybe mzero pure . parseVcs
instance ToJSON Vcs where
toJSON = toJSON . renderVcs
toEncoding = toEncoding . renderVcs
-- Based on the properties of Project and Repository
data ExtRepo = Repo
{ repoIndex :: Identifier
, repoName :: Text
, repoDescription :: Markdown
, repoCreated :: UTCTime
, repoUpdated :: UTCTime
, repoMain :: Text
, repoVcs :: Vcs
}
instance FromJSON ExtRepo where
parseJSON = withObject "Repo" $ \ o -> Repo
<$> o .: "index"
<*> o .: "name"
<*> o .: "description"
<*> o .: "created"
<*> o .: "updated"
<*> o .: "default_branch"
<*> o .: "vcs"
instance ToJSON ExtRepo where
toJSON it = object
[ "index" .= repoIndex it
, "name" .= repoName it
, "description" .= repoDescription it
, "created" .= repoCreated it
, "updated" .= repoUpdated it
, "default_branch" .= repoMain it
, "vcs" .= repoVcs it
]
toEncoding it = pairs
( "index" .= repoIndex it
<> "name" .= repoName it
<> "description" .= repoDescription it
<> "created" .= repoCreated it
<> "updated" .= repoUpdated it
<> "default_branch" .= repoMain it
<> "vcs" .= repoVcs it
)
|