Skip to content

Commit

Permalink
Add various url parses back from share
Browse files Browse the repository at this point in the history
  • Loading branch information
hojberg committed Jul 17, 2023
1 parent bac7203 commit f01901e
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/Code/Branch.elm
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,17 @@ import Json.Decode.Pipeline exposing (required)
import UI.DateTime as DateTime exposing (DateTime)


type alias Branch b p =
type alias Branch b =
{ b
| ref : BranchRef
, project : Project p
, createdAt : DateTime
, updatedAt : DateTime
, causalHash : Hash
}


type alias BranchSummary =
Branch {} {}
Branch { project : Project {} }


decodeSummary : Decode.Decoder BranchSummary
Expand Down
3 changes: 3 additions & 0 deletions src/Code/Project/ProjectRef.elm
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{- TODO: Move this to UnisonShare, its not compatible with UCM projects -}


module Code.Project.ProjectRef exposing
( ProjectRef
, decode
Expand Down
64 changes: 64 additions & 0 deletions src/Code/UrlParsers.elm
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@

module Code.UrlParsers exposing (..)

import Code.BranchRef as BranchRef exposing (BranchRef, BranchSlug)
import Code.Definition.Reference exposing (Reference(..))
import Code.FullyQualifiedName as FQN exposing (FQN)
import Code.Hash as Hash exposing (Hash)
import Code.HashQualified exposing (HashQualified(..))
import Code.Perspective exposing (PerspectiveParams(..), RootPerspective(..))
import Code.Version as Version exposing (Version)
import Lib.UserHandle as UserHandle exposing (UserHandle)
import Parser exposing ((|.), (|=), Parser, backtrackable, keyword, succeed)


Expand Down Expand Up @@ -59,6 +62,67 @@ fqnEnd =
Parser.symbol ";"


userHandle : Parser UserHandle
userHandle =
let
parseMaybe mhandle =
case mhandle of
Just u ->
Parser.succeed u

Nothing ->
Parser.problem "Invalid handle"
in
Parser.chompUntilEndOr "/"
|> Parser.getChompedString
|> Parser.map UserHandle.fromString
|> Parser.andThen parseMaybe


version : Parser Version
version =
let
parseMaybe mversion =
case mversion of
Just s_ ->
Parser.succeed s_

Nothing ->
Parser.problem "Invalid Version"
in
Parser.chompUntilEndOr "/"
|> Parser.getChompedString
|> Parser.map Version.fromUrlString
|> Parser.andThen parseMaybe


branchRef : Parser BranchRef
branchRef =
Parser.oneOf
[ b (succeed BranchRef.releaseDraftBranchRef |. s "releases" |. slash |. s "drafts" |. slash |= version)
, b (succeed BranchRef.releaseBranchRef |. s "releases" |. slash |= version)
, b (succeed BranchRef.contributorBranchRef |= userHandle |. slash |= branchSlug)
, b (succeed BranchRef.projectBranchRef |= branchSlug)
]


branchSlug : Parser BranchSlug
branchSlug =
let
parseMaybe mslug =
case mslug of
Just s_ ->
Parser.succeed s_

Nothing ->
Parser.problem "Invalid Slug"
in
Parser.chompUntilEndOr "/"
|> Parser.getChompedString
|> Parser.map BranchRef.branchSlugFromString
|> Parser.andThen parseMaybe


{-| Hash example url segment: "@asd123".
contextual positioning in the url makes this different than a UserHandle
-}
Expand Down

0 comments on commit f01901e

Please sign in to comment.