From 56e9cd9ed7ae6cda97bc027e9c4f1cd798a192b6 Mon Sep 17 00:00:00 2001 From: Liubov Dmitrieva Date: Fri, 21 Aug 2020 03:32:32 -0700 Subject: [PATCH] add undelete workspace command Summary: The command is needed to restore a deleted workspace Reviewed By: markbt Differential Revision: D23250376 fbshipit-source-id: e24a7cbc0aad004291853b4c34d7474789aa9c2b --- .../edenscm/hgext/commitcloud/baseservice.py | 4 +-- .../scm/edenscm/hgext/commitcloud/commands.py | 25 +++++++++++++++-- .../edenscm/hgext/commitcloud/httpsservice.py | 8 +++--- .../edenscm/hgext/commitcloud/localservice.py | 6 +++-- .../test-commitcloud-list-workspaces-t.py | 27 +++++++++++++++++++ 5 files changed, 60 insertions(+), 10 deletions(-) diff --git a/eden/scm/edenscm/hgext/commitcloud/baseservice.py b/eden/scm/edenscm/hgext/commitcloud/baseservice.py index 04f2654a86..ebc64ab10e 100644 --- a/eden/scm/edenscm/hgext/commitcloud/baseservice.py +++ b/eden/scm/edenscm/hgext/commitcloud/baseservice.py @@ -274,8 +274,8 @@ class BaseService(pycompat.ABC): """ @abstractmethod - def archiveworkspace(self, reponame, workspace): - """Archive the given workspace + def updateworkspacearchive(self, reponame, workspace, archive): + """Archive or Restore the given workspace """ @staticmethod diff --git a/eden/scm/edenscm/hgext/commitcloud/commands.py b/eden/scm/edenscm/hgext/commitcloud/commands.py index fcc26df27f..5219919be4 100644 --- a/eden/scm/edenscm/hgext/commitcloud/commands.py +++ b/eden/scm/edenscm/hgext/commitcloud/commands.py @@ -819,6 +819,10 @@ def cloudlistworspaces(ui, repo, **opts): "run `hg cloud join -w --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) @@ -842,14 +846,31 @@ def clouddeleteworkspace(ui, repo, **opts): return reponame = ccutil.getreponame(repo) - service.get(ui, tokenmod.TokenLocator(ui).token).archiveworkspace( - reponame, workspacename + service.get(ui, tokenmod.TokenLocator(ui).token).updateworkspacearchive( + reponame, workspacename, True ) ui.status( _("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( "listbackups", [ diff --git a/eden/scm/edenscm/hgext/commitcloud/httpsservice.py b/eden/scm/edenscm/hgext/commitcloud/httpsservice.py index b1eb7bda96..26944a6d6b 100644 --- a/eden/scm/edenscm/hgext/commitcloud/httpsservice.py +++ b/eden/scm/edenscm/hgext/commitcloud/httpsservice.py @@ -512,15 +512,15 @@ class _HttpsCommitCloudService(baseservice.BaseService): workspaces = response["workspaces_data"] return self._makeworkspacesinfo(workspaces) - @perftrace.tracefunc("Archive Workspace") - def archiveworkspace(self, reponame, workspace): - """Archive the given workspace + @perftrace.tracefunc("Archive/Restore Workspace") + def updateworkspacearchive(self, reponame, workspace, archived): + """Archive or Restore the given workspace """ self.ui.debug( "sending 'update_workspace_archive' request\n", component="commitcloud" ) 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() response = self._send(path, data) elapsed = util.timer() - start diff --git a/eden/scm/edenscm/hgext/commitcloud/localservice.py b/eden/scm/edenscm/hgext/commitcloud/localservice.py index aa6a91f252..0466d88f49 100644 --- a/eden/scm/edenscm/hgext/commitcloud/localservice.py +++ b/eden/scm/edenscm/hgext/commitcloud/localservice.py @@ -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) found = next( (winfo for winfo in allworkspaces if winfo.name == workspace), None @@ -297,7 +299,7 @@ class _LocalService(baseservice.BaseService): if found: allworkspaces.append( baseservice.WorkspaceInfo( - name=found.name, archived=True, version=found.version + name=found.name, archived=archived, version=found.version ) ) else: diff --git a/eden/scm/tests/test-commitcloud-list-workspaces-t.py b/eden/scm/tests/test-commitcloud-list-workspaces-t.py index f8f5da4ac0..01ab50443e 100644 --- a/eden/scm/tests/test-commitcloud-list-workspaces-t.py +++ b/eden/scm/tests/test-commitcloud-list-workspaces-t.py @@ -43,6 +43,7 @@ workspaces: default run `hg cloud sl -w ` to view the commits run `hg cloud join -w --switch` to switch to a different workspace +run `hg cloud list --all` to list all workspaces, including deleted """ sh % "hg cloud list --all" == r""" @@ -76,3 +77,29 @@ sh % "hg cloud list" == r""" commitcloud: searching workspaces for the 'server' repo 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 ` to view the commits +run `hg cloud join -w --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 ` to view the commits +run `hg cloud join -w --switch` to switch to a different workspace +"""