-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e52efdf
commit ab51c7e
Showing
10 changed files
with
171 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
DATOCMS_ACCOUNT_EMAIL="" | ||
DATOCMS_ACCOUNT_PASSWORD="" | ||
DATOCMS_ORGANIZATION_ID="" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import 'dotenv/config'; | ||
import { ApiError } from '../packages/dashboard-client'; | ||
import { generateNewDashboardClient } from './generateNewDashboardClient'; | ||
|
||
function isOldEnough(isoDatetime: string) { | ||
const datetime = new Date(isoDatetime); | ||
|
||
const oneDayAgo = new Date(); | ||
oneDayAgo.setDate(oneDayAgo.getDate() - 1); | ||
|
||
return datetime < oneDayAgo; | ||
} | ||
|
||
export default async () => { | ||
const client = await generateNewDashboardClient(); | ||
|
||
// Context: multiple processes might be running tests in parallel (like in Github Actions) | ||
|
||
const siteIds: string[] = []; | ||
|
||
for await (const site of client.sites.listPagedIterator()) { | ||
// We don't want to destroy sites that might be used by other processes, | ||
// let's only delete old ones | ||
|
||
// biome-ignore lint/style/noNonNullAssertion: Always present | ||
if (isOldEnough(site.created_at!)) { | ||
siteIds.push(site.id); | ||
} | ||
} | ||
|
||
await Promise.all( | ||
siteIds.map(async (id) => { | ||
try { | ||
await client.sites.destroy(id); | ||
} catch (e) { | ||
if (e instanceof ApiError && e.findError('NOT_FOUND')) { | ||
// Other processes might have already deleted the project | ||
return; | ||
} | ||
|
||
throw e; | ||
} | ||
}), | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters