distinguish between project not found and branch not found in types

This commit is contained in:
Mitchell Rosen 2023-03-06 10:56:03 -05:00
parent 204f389ed8
commit 9b6b8b108b
4 changed files with 21 additions and 10 deletions

View File

@ -111,7 +111,8 @@ onGetProjectResponse = \case
onGetProjectBranchResponse :: GetProjectBranchResponse -> Cli ()
onGetProjectBranchResponse = \case
GetProjectBranchResponseNotFound {} -> pure ()
GetProjectBranchResponseBranchNotFound {} -> pure ()
GetProjectBranchResponseProjectNotFound {} -> pure ()
GetProjectBranchResponseUnauthorized {} -> pure ()
GetProjectBranchResponseSuccess branch -> onProjectBranch branch

View File

@ -58,9 +58,12 @@ projectClone projectName = do
let remoteProjectId = RemoteProjectId (project ^. #projectId)
let remoteBranchName = unsafeFrom @Text "main"
Share.getProjectBranchByName (ProjectAndBranch remoteProjectId remoteBranchName) >>= \case
Share.API.GetProjectBranchResponseNotFound notFound -> do
Share.API.GetProjectBranchResponseBranchNotFound notFound -> do
loggeth ["remote branch 'main' doesn't exist: ", tShow notFound]
Cli.returnEarlyWithoutOutput
Share.API.GetProjectBranchResponseProjectNotFound notFound -> do
loggeth ["project doesn't exist: ", tShow notFound]
Cli.returnEarlyWithoutOutput
Share.API.GetProjectBranchResponseUnauthorized unauthorized -> do
loggeth ["unauthorized: ", tShow unauthorized]
Cli.returnEarlyWithoutOutput

View File

@ -368,8 +368,11 @@ bazinga50 localProjectAndBranch localBranchHead maybeRemoteBranchName =
-- "push" with remote mapping for branch
Just remoteBranchId ->
Share.getProjectBranchById (ProjectAndBranch remoteProjectId remoteBranchId) >>= \case
Share.API.GetProjectBranchResponseNotFound (Share.API.NotFound msg) -> do
loggeth ["project or branch deleted on Share: " <> msg]
Share.API.GetProjectBranchResponseBranchNotFound (Share.API.NotFound msg) -> do
loggeth ["branch deleted on Share: " <> msg]
Cli.returnEarlyWithoutOutput
Share.API.GetProjectBranchResponseProjectNotFound (Share.API.NotFound msg) -> do
loggeth ["branch deleted on Share: " <> msg]
Cli.returnEarlyWithoutOutput
Share.API.GetProjectBranchResponseUnauthorized {} -> wundefined
Share.API.GetProjectBranchResponseSuccess remoteBranch -> do
@ -435,7 +438,7 @@ pushToProjectBranch0 pushing localBranchHead remoteProjectAndBranch = do
Share.API.GetProjectResponseSuccess remoteProject -> do
let remoteProjectId = RemoteProjectId (remoteProject ^. #projectId)
Share.getProjectBranchByName (ProjectAndBranch remoteProjectId remoteBranchName) >>= \case
Share.API.GetProjectBranchResponseNotFound {} -> do
Share.API.GetProjectBranchResponseBranchNotFound {} -> do
pure
UploadPlan
{ repoName,
@ -446,6 +449,7 @@ pushToProjectBranch0 pushing localBranchHead remoteProjectAndBranch = do
localBranchHead
(ProjectAndBranch (RemoteProjectId (remoteProject ^. #projectId)) remoteBranchName)
}
Share.API.GetProjectBranchResponseProjectNotFound {} -> wundefined
Share.API.GetProjectBranchResponseUnauthorized {} -> wundefined
Share.API.GetProjectBranchResponseSuccess remoteBranch -> do
afterUploadAction <- makeFastForwardAfterUploadAction pushing localBranchHead remoteBranch
@ -472,8 +476,7 @@ pushToProjectBranch1 localProjectAndBranch localBranchHead remoteProjectAndBranc
Share.API.GetProjectResponseSuccess remoteProject -> expectRemoteProjectRepoName remoteProject
Just userSlug -> pure (Share.RepoName userSlug)
Share.getProjectBranchByName remoteProjectAndBranch >>= \case
Share.API.GetProjectBranchResponseNotFound {} -> do
-- FIXME check to see if the project exists here instead of assuming it does
Share.API.GetProjectBranchResponseBranchNotFound {} -> do
pure
UploadPlan
{ repoName,
@ -484,6 +487,7 @@ pushToProjectBranch1 localProjectAndBranch localBranchHead remoteProjectAndBranc
localBranchHead
remoteProjectAndBranch
}
Share.API.GetProjectBranchResponseProjectNotFound {} -> wundefined
Share.API.GetProjectBranchResponseUnauthorized {} -> wundefined
Share.API.GetProjectBranchResponseSuccess remoteBranch -> do
afterUploadAction <-

View File

@ -152,7 +152,8 @@ type GetProjectBranchAPI =
-- | @GET /project-branch@ response.
data GetProjectBranchResponse
= GetProjectBranchResponseNotFound NotFound
= GetProjectBranchResponseProjectNotFound NotFound
| GetProjectBranchResponseBranchNotFound NotFound
| GetProjectBranchResponseUnauthorized Unauthorized
| GetProjectBranchResponseSuccess !ProjectBranch
deriving stock (Eq, Show, Generic)
@ -161,14 +162,16 @@ instance FromJSON GetProjectBranchResponse where
parseJSON =
withSumType "GetProjectBranchResponse" \typ val ->
case typ of
"not-found" -> GetProjectBranchResponseNotFound <$> parseJSON val
"project-not-found" -> GetProjectBranchResponseProjectNotFound <$> parseJSON val
"branch-not-found" -> GetProjectBranchResponseBranchNotFound <$> parseJSON val
"unauthorized" -> GetProjectBranchResponseUnauthorized <$> parseJSON val
"success" -> GetProjectBranchResponseSuccess <$> parseJSON val
_ -> fail (Text.unpack ("unknown GetProjectBranchResponse type: " <> typ))
instance ToJSON GetProjectBranchResponse where
toJSON = \case
GetProjectBranchResponseNotFound notFound -> toSumType "not-found" (toJSON notFound)
GetProjectBranchResponseProjectNotFound notFound -> toSumType "project-not-found" (toJSON notFound)
GetProjectBranchResponseBranchNotFound notFound -> toSumType "branch-not-found" (toJSON notFound)
GetProjectBranchResponseUnauthorized unauthorized -> toSumType "unauthorized" (toJSON unauthorized)
GetProjectBranchResponseSuccess branch -> toSumType "success" (toJSON branch)