mirror of
https://github.com/unisonweb/unison.git
synced 2024-09-11 10:35:57 +03:00
distinguish between project not found and branch not found in types
This commit is contained in:
parent
204f389ed8
commit
9b6b8b108b
@ -111,7 +111,8 @@ onGetProjectResponse = \case
|
|||||||
|
|
||||||
onGetProjectBranchResponse :: GetProjectBranchResponse -> Cli ()
|
onGetProjectBranchResponse :: GetProjectBranchResponse -> Cli ()
|
||||||
onGetProjectBranchResponse = \case
|
onGetProjectBranchResponse = \case
|
||||||
GetProjectBranchResponseNotFound {} -> pure ()
|
GetProjectBranchResponseBranchNotFound {} -> pure ()
|
||||||
|
GetProjectBranchResponseProjectNotFound {} -> pure ()
|
||||||
GetProjectBranchResponseUnauthorized {} -> pure ()
|
GetProjectBranchResponseUnauthorized {} -> pure ()
|
||||||
GetProjectBranchResponseSuccess branch -> onProjectBranch branch
|
GetProjectBranchResponseSuccess branch -> onProjectBranch branch
|
||||||
|
|
||||||
|
@ -58,9 +58,12 @@ projectClone projectName = do
|
|||||||
let remoteProjectId = RemoteProjectId (project ^. #projectId)
|
let remoteProjectId = RemoteProjectId (project ^. #projectId)
|
||||||
let remoteBranchName = unsafeFrom @Text "main"
|
let remoteBranchName = unsafeFrom @Text "main"
|
||||||
Share.getProjectBranchByName (ProjectAndBranch remoteProjectId remoteBranchName) >>= \case
|
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]
|
loggeth ["remote branch 'main' doesn't exist: ", tShow notFound]
|
||||||
Cli.returnEarlyWithoutOutput
|
Cli.returnEarlyWithoutOutput
|
||||||
|
Share.API.GetProjectBranchResponseProjectNotFound notFound -> do
|
||||||
|
loggeth ["project doesn't exist: ", tShow notFound]
|
||||||
|
Cli.returnEarlyWithoutOutput
|
||||||
Share.API.GetProjectBranchResponseUnauthorized unauthorized -> do
|
Share.API.GetProjectBranchResponseUnauthorized unauthorized -> do
|
||||||
loggeth ["unauthorized: ", tShow unauthorized]
|
loggeth ["unauthorized: ", tShow unauthorized]
|
||||||
Cli.returnEarlyWithoutOutput
|
Cli.returnEarlyWithoutOutput
|
||||||
|
@ -368,8 +368,11 @@ bazinga50 localProjectAndBranch localBranchHead maybeRemoteBranchName =
|
|||||||
-- "push" with remote mapping for branch
|
-- "push" with remote mapping for branch
|
||||||
Just remoteBranchId ->
|
Just remoteBranchId ->
|
||||||
Share.getProjectBranchById (ProjectAndBranch remoteProjectId remoteBranchId) >>= \case
|
Share.getProjectBranchById (ProjectAndBranch remoteProjectId remoteBranchId) >>= \case
|
||||||
Share.API.GetProjectBranchResponseNotFound (Share.API.NotFound msg) -> do
|
Share.API.GetProjectBranchResponseBranchNotFound (Share.API.NotFound msg) -> do
|
||||||
loggeth ["project or branch deleted on Share: " <> msg]
|
loggeth ["branch deleted on Share: " <> msg]
|
||||||
|
Cli.returnEarlyWithoutOutput
|
||||||
|
Share.API.GetProjectBranchResponseProjectNotFound (Share.API.NotFound msg) -> do
|
||||||
|
loggeth ["branch deleted on Share: " <> msg]
|
||||||
Cli.returnEarlyWithoutOutput
|
Cli.returnEarlyWithoutOutput
|
||||||
Share.API.GetProjectBranchResponseUnauthorized {} -> wundefined
|
Share.API.GetProjectBranchResponseUnauthorized {} -> wundefined
|
||||||
Share.API.GetProjectBranchResponseSuccess remoteBranch -> do
|
Share.API.GetProjectBranchResponseSuccess remoteBranch -> do
|
||||||
@ -435,7 +438,7 @@ pushToProjectBranch0 pushing localBranchHead remoteProjectAndBranch = do
|
|||||||
Share.API.GetProjectResponseSuccess remoteProject -> do
|
Share.API.GetProjectResponseSuccess remoteProject -> do
|
||||||
let remoteProjectId = RemoteProjectId (remoteProject ^. #projectId)
|
let remoteProjectId = RemoteProjectId (remoteProject ^. #projectId)
|
||||||
Share.getProjectBranchByName (ProjectAndBranch remoteProjectId remoteBranchName) >>= \case
|
Share.getProjectBranchByName (ProjectAndBranch remoteProjectId remoteBranchName) >>= \case
|
||||||
Share.API.GetProjectBranchResponseNotFound {} -> do
|
Share.API.GetProjectBranchResponseBranchNotFound {} -> do
|
||||||
pure
|
pure
|
||||||
UploadPlan
|
UploadPlan
|
||||||
{ repoName,
|
{ repoName,
|
||||||
@ -446,6 +449,7 @@ pushToProjectBranch0 pushing localBranchHead remoteProjectAndBranch = do
|
|||||||
localBranchHead
|
localBranchHead
|
||||||
(ProjectAndBranch (RemoteProjectId (remoteProject ^. #projectId)) remoteBranchName)
|
(ProjectAndBranch (RemoteProjectId (remoteProject ^. #projectId)) remoteBranchName)
|
||||||
}
|
}
|
||||||
|
Share.API.GetProjectBranchResponseProjectNotFound {} -> wundefined
|
||||||
Share.API.GetProjectBranchResponseUnauthorized {} -> wundefined
|
Share.API.GetProjectBranchResponseUnauthorized {} -> wundefined
|
||||||
Share.API.GetProjectBranchResponseSuccess remoteBranch -> do
|
Share.API.GetProjectBranchResponseSuccess remoteBranch -> do
|
||||||
afterUploadAction <- makeFastForwardAfterUploadAction pushing localBranchHead remoteBranch
|
afterUploadAction <- makeFastForwardAfterUploadAction pushing localBranchHead remoteBranch
|
||||||
@ -472,8 +476,7 @@ pushToProjectBranch1 localProjectAndBranch localBranchHead remoteProjectAndBranc
|
|||||||
Share.API.GetProjectResponseSuccess remoteProject -> expectRemoteProjectRepoName remoteProject
|
Share.API.GetProjectResponseSuccess remoteProject -> expectRemoteProjectRepoName remoteProject
|
||||||
Just userSlug -> pure (Share.RepoName userSlug)
|
Just userSlug -> pure (Share.RepoName userSlug)
|
||||||
Share.getProjectBranchByName remoteProjectAndBranch >>= \case
|
Share.getProjectBranchByName remoteProjectAndBranch >>= \case
|
||||||
Share.API.GetProjectBranchResponseNotFound {} -> do
|
Share.API.GetProjectBranchResponseBranchNotFound {} -> do
|
||||||
-- FIXME check to see if the project exists here instead of assuming it does
|
|
||||||
pure
|
pure
|
||||||
UploadPlan
|
UploadPlan
|
||||||
{ repoName,
|
{ repoName,
|
||||||
@ -484,6 +487,7 @@ pushToProjectBranch1 localProjectAndBranch localBranchHead remoteProjectAndBranc
|
|||||||
localBranchHead
|
localBranchHead
|
||||||
remoteProjectAndBranch
|
remoteProjectAndBranch
|
||||||
}
|
}
|
||||||
|
Share.API.GetProjectBranchResponseProjectNotFound {} -> wundefined
|
||||||
Share.API.GetProjectBranchResponseUnauthorized {} -> wundefined
|
Share.API.GetProjectBranchResponseUnauthorized {} -> wundefined
|
||||||
Share.API.GetProjectBranchResponseSuccess remoteBranch -> do
|
Share.API.GetProjectBranchResponseSuccess remoteBranch -> do
|
||||||
afterUploadAction <-
|
afterUploadAction <-
|
||||||
|
@ -152,7 +152,8 @@ type GetProjectBranchAPI =
|
|||||||
|
|
||||||
-- | @GET /project-branch@ response.
|
-- | @GET /project-branch@ response.
|
||||||
data GetProjectBranchResponse
|
data GetProjectBranchResponse
|
||||||
= GetProjectBranchResponseNotFound NotFound
|
= GetProjectBranchResponseProjectNotFound NotFound
|
||||||
|
| GetProjectBranchResponseBranchNotFound NotFound
|
||||||
| GetProjectBranchResponseUnauthorized Unauthorized
|
| GetProjectBranchResponseUnauthorized Unauthorized
|
||||||
| GetProjectBranchResponseSuccess !ProjectBranch
|
| GetProjectBranchResponseSuccess !ProjectBranch
|
||||||
deriving stock (Eq, Show, Generic)
|
deriving stock (Eq, Show, Generic)
|
||||||
@ -161,14 +162,16 @@ instance FromJSON GetProjectBranchResponse where
|
|||||||
parseJSON =
|
parseJSON =
|
||||||
withSumType "GetProjectBranchResponse" \typ val ->
|
withSumType "GetProjectBranchResponse" \typ val ->
|
||||||
case typ of
|
case typ of
|
||||||
"not-found" -> GetProjectBranchResponseNotFound <$> parseJSON val
|
"project-not-found" -> GetProjectBranchResponseProjectNotFound <$> parseJSON val
|
||||||
|
"branch-not-found" -> GetProjectBranchResponseBranchNotFound <$> parseJSON val
|
||||||
"unauthorized" -> GetProjectBranchResponseUnauthorized <$> parseJSON val
|
"unauthorized" -> GetProjectBranchResponseUnauthorized <$> parseJSON val
|
||||||
"success" -> GetProjectBranchResponseSuccess <$> parseJSON val
|
"success" -> GetProjectBranchResponseSuccess <$> parseJSON val
|
||||||
_ -> fail (Text.unpack ("unknown GetProjectBranchResponse type: " <> typ))
|
_ -> fail (Text.unpack ("unknown GetProjectBranchResponse type: " <> typ))
|
||||||
|
|
||||||
instance ToJSON GetProjectBranchResponse where
|
instance ToJSON GetProjectBranchResponse where
|
||||||
toJSON = \case
|
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)
|
GetProjectBranchResponseUnauthorized unauthorized -> toSumType "unauthorized" (toJSON unauthorized)
|
||||||
GetProjectBranchResponseSuccess branch -> toSumType "success" (toJSON branch)
|
GetProjectBranchResponseSuccess branch -> toSumType "success" (toJSON branch)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user