Skip to content

Commit ed2dd8d

Browse files
authored
Merge pull request #57 from dandi/gh-55
Make deleted Dandisets private
2 parents 0d1e173 + aa424b7 commit ed2dd8d

File tree

1 file changed

+35
-13
lines changed

1 file changed

+35
-13
lines changed

src/backups2datalad/datasetter.py

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
import anyio
1919
from anyio.abc import AsyncResource
20-
from dandi.consts import EmbargoStatus, dandiset_metadata_file
20+
from dandi.consts import DANDISET_ID_REGEX, EmbargoStatus, dandiset_metadata_file
2121
from dandi.exceptions import NotFoundError
2222
from datalad.api import clone
2323
from ghrepo import GHRepo
@@ -90,25 +90,47 @@ async def update_from_backup(
9090
if d.embargo_status is EmbargoStatus.OPEN
9191
else "private"
9292
)
93+
if not dandiset_ids and self.config.gh_org is not None:
94+
extant = {d.identifier for d, _ in report.results}
95+
extant.update(d.identifier for d in report.failed)
96+
for sub_info in await superds.get_subdatasets(result_xfm="relpaths"):
97+
d = sub_info["path"]
98+
if (
99+
re.fullmatch(DANDISET_ID_REGEX, d)
100+
and d not in extant
101+
and (exclude is None or not exclude.search(d))
102+
and sub_info.get("gitmodule_github-access-status", "public")
103+
== "public"
104+
):
105+
log.info(
106+
"Dandiset %s has been deleted; making GitHub backup private",
107+
d,
108+
)
109+
await self.manager.edit_github_repo(
110+
GHRepo(self.config.gh_org, d),
111+
private=True,
112+
)
113+
access_status[d] = "private"
93114
if to_save:
94115
log.debug("Committing superdataset")
95116
superds.assert_no_duplicates_in_gitmodules()
96117
msg = await self.get_superds_commit_message(superds, to_save)
97118
await superds.save(message=msg, path=to_save)
98-
if access_status:
99-
for did, access in access_status.items():
100-
await superds.set_repo_config(
101-
f"submodule.{did}.github-access-status",
102-
access,
103-
file=".gitmodules",
104-
)
105-
await superds.commit_if_changed(
106-
"[backups2datalad] Update github-access-status keys in .gitmodules",
107-
paths=[".gitmodules"],
108-
check_dirty=False,
109-
)
110119
superds.assert_no_duplicates_in_gitmodules()
111120
log.debug("Superdataset committed")
121+
if access_status:
122+
log.debug("Ensuring github-access-status in .gitmodules is up-to-date")
123+
for did, access in access_status.items():
124+
await superds.set_repo_config(
125+
f"submodule.{did}.github-access-status",
126+
access,
127+
file=".gitmodules",
128+
)
129+
await superds.commit_if_changed(
130+
"[backups2datalad] Update github-access-status keys in .gitmodules",
131+
paths=[".gitmodules"],
132+
check_dirty=False,
133+
)
112134
if report.failed:
113135
raise RuntimeError(
114136
f"Backups for {quantify(len(report.failed), 'Dandiset')} failed"

0 commit comments

Comments
 (0)