add undelete workspace command

Summary: The command is needed to restore a deleted workspace

Reviewed By: markbt

Differential Revision: D23250376

fbshipit-source-id: e24a7cbc0aad004291853b4c34d7474789aa9c2b
This commit is contained in:
Liubov Dmitrieva 2020-08-21 03:32:32 -07:00 committed by Jun Wu
parent e72b4988d3
commit 56e9cd9ed7
5 changed files with 60 additions and 10 deletions

View File

@ -274,8 +274,8 @@ class BaseService(pycompat.ABC):
""" """
@abstractmethod @abstractmethod
def archiveworkspace(self, reponame, workspace): def updateworkspacearchive(self, reponame, workspace, archive):
"""Archive the given workspace """Archive or Restore the given workspace
""" """
@staticmethod @staticmethod

View File

@ -819,6 +819,10 @@ def cloudlistworspaces(ui, repo, **opts):
"run `hg cloud join -w <workspace name> --switch` to switch to a different workspace\n" "run `hg cloud join -w <workspace name> --switch` to switch to a different workspace\n"
) )
) )
if activeonly and archived:
ui.status(
_("run `hg cloud list --all` to list all workspaces, including deleted\n")
)
@subcmd("deleteworkspace|delete", [] + workspace.workspaceopts) @subcmd("deleteworkspace|delete", [] + workspace.workspaceopts)
@ -842,14 +846,31 @@ def clouddeleteworkspace(ui, repo, **opts):
return return
reponame = ccutil.getreponame(repo) reponame = ccutil.getreponame(repo)
service.get(ui, tokenmod.TokenLocator(ui).token).archiveworkspace( service.get(ui, tokenmod.TokenLocator(ui).token).updateworkspacearchive(
reponame, workspacename reponame, workspacename, True
) )
ui.status( ui.status(
_("workspace %s has been deleted\n") % workspacename, component="commitcloud" _("workspace %s has been deleted\n") % workspacename, component="commitcloud"
) )
@subcmd("undeleteworkspace|undelete", [] + workspace.workspaceopts)
def cloudundeleteworkspace(ui, repo, **opts):
"""Restore (unarchive) workspace in commit cloud"""
workspacename = workspace.parseworkspace(ui, opts)
if workspacename is None:
raise error.Abort(_("workspace name should be provided\n"))
reponame = ccutil.getreponame(repo)
service.get(ui, tokenmod.TokenLocator(ui).token).updateworkspacearchive(
reponame, workspacename, False
)
ui.status(
_("workspace %s has been restored\n") % workspacename, component="commitcloud"
)
@subcmd( @subcmd(
"listbackups", "listbackups",
[ [

View File

@ -512,15 +512,15 @@ class _HttpsCommitCloudService(baseservice.BaseService):
workspaces = response["workspaces_data"] workspaces = response["workspaces_data"]
return self._makeworkspacesinfo(workspaces) return self._makeworkspacesinfo(workspaces)
@perftrace.tracefunc("Archive Workspace") @perftrace.tracefunc("Archive/Restore Workspace")
def archiveworkspace(self, reponame, workspace): def updateworkspacearchive(self, reponame, workspace, archived):
"""Archive the given workspace """Archive or Restore the given workspace
""" """
self.ui.debug( self.ui.debug(
"sending 'update_workspace_archive' request\n", component="commitcloud" "sending 'update_workspace_archive' request\n", component="commitcloud"
) )
path = "/commit_cloud/update_workspace_archive" path = "/commit_cloud/update_workspace_archive"
data = {"repo_name": reponame, "workspace": workspace, "archived": True} data = {"repo_name": reponame, "workspace": workspace, "archived": archived}
start = util.timer() start = util.timer()
response = self._send(path, data) response = self._send(path, data)
elapsed = util.timer() - start elapsed = util.timer() - start

View File

@ -283,7 +283,9 @@ class _LocalService(baseservice.BaseService):
) )
) )
def archiveworkspace(self, reponame, workspace): def updateworkspacearchive(self, reponame, workspace, archived):
"""Archive or Restore the given workspace
"""
allworkspaces = self.getworkspaces(reponame, None) allworkspaces = self.getworkspaces(reponame, None)
found = next( found = next(
(winfo for winfo in allworkspaces if winfo.name == workspace), None (winfo for winfo in allworkspaces if winfo.name == workspace), None
@ -297,7 +299,7 @@ class _LocalService(baseservice.BaseService):
if found: if found:
allworkspaces.append( allworkspaces.append(
baseservice.WorkspaceInfo( baseservice.WorkspaceInfo(
name=found.name, archived=True, version=found.version name=found.name, archived=archived, version=found.version
) )
) )
else: else:

View File

@ -43,6 +43,7 @@ workspaces:
default default
run `hg cloud sl -w <workspace name>` to view the commits run `hg cloud sl -w <workspace name>` to view the commits
run `hg cloud join -w <workspace name> --switch` to switch to a different workspace run `hg cloud join -w <workspace name> --switch` to switch to a different workspace
run `hg cloud list --all` to list all workspaces, including deleted
""" """
sh % "hg cloud list --all" == r""" sh % "hg cloud list --all" == r"""
@ -76,3 +77,29 @@ sh % "hg cloud list" == r"""
commitcloud: searching workspaces for the 'server' repo commitcloud: searching workspaces for the 'server' repo
no active workspaces found with the prefix user/test/ no active workspaces found with the prefix user/test/
""" """
sh % "hg cloud undelete -w default" == r"""
commitcloud: workspace user/test/default has been restored
"""
sh % "hg cloud list" == r"""
commitcloud: searching workspaces for the 'server' repo
workspaces:
default
run `hg cloud sl -w <workspace name>` to view the commits
run `hg cloud join -w <workspace name> --switch` to switch to a different workspace
run `hg cloud list --all` to list all workspaces, including deleted
"""
sh % "hg cloud undelete -w old" == r"""
commitcloud: workspace user/test/old has been restored
"""
sh % "hg cloud list" == r"""
commitcloud: searching workspaces for the 'server' repo
workspaces:
default
old
run `hg cloud sl -w <workspace name>` to view the commits
run `hg cloud join -w <workspace name> --switch` to switch to a different workspace
"""