mirror of
https://github.com/RayLabsHQ/gitea-mirror.git
synced 2026-11-28 17:48:28 +01:00
fix(cleanup): check starred rows with starred import off, clearer cleanup and storage text (#599, #600, #601) (#602)
Cleanup skipped every row flagged starred while starred import was off, so a deleted source behind one was never found. It now reads the star list for them and looks up the ones no longer starred: a deleted source counts as gone, an unstar alone does not. The destination switch on the Repository Cleanup card moves right under the action and is named after it. The Storage page says it counts only the mirrors gitea-mirror manages.
This commit is contained in:
@@ -39,6 +39,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
- An SSO sign-in is no longer linked to a local account from another domain. When the identity provider said the email was verified, the sign-in was linked to the local account with that email whatever the provider's Email Domain, so someone who could get that email at the provider could take over the account. Linking now only happens for emails in the provider's domain, as the docs already said
|
||||
|
||||
### Changed
|
||||
- The Repository Cleanup card puts the destination switch right under the action and names it after it: **Archive on the destination too** or **Delete from the destination too** (#601, thanks @zwimer). It sat below Wait before acting as **Apply to the destination too**, which read like a separate setting and made it look as if the action only happened with it on. Off, the action still happens, in gitea-mirror's own list only
|
||||
- The Storage page says it counts only the mirrors gitea-mirror manages, at the size the destination reports for each (#599, thanks @zwimer). **Total stored** read like the whole destination, whose data folder also holds its database, search indexes, wikis and repositories gitea-mirror doesn't manage
|
||||
- GitLab and Gitea / Forgejo sources (Codeberg included), the Forgejo destination and Git LFS mirroring are no longer marked beta. They have had three months of use and fixes since they shipped (#440, #506 and others). The Git URL source, which arrived in 3.52, and the GitHub and GitLab push destinations, which overwrite the copy on every sync, keep their BETA pill
|
||||
- A change on the Configuration page that leaves mirrors out of place now brings up a bar at the bottom of the page saying how many, with **Review and move** and **Not now** (#550). The count was only in the Organization Structure card's footer, which on a laptop sits below the fold while you pick a strategy, so nothing said the change touched existing mirrors. The bar shows wherever the page is scrolled, follows a move started from it until it ends, and **Not now** puts it away until the next change. It stays down when the change failed to save. Mirrors that were already out of place when the page opened are still shown in the card only
|
||||
- The Configuration page is regrouped into five tabs. Connections held six cards, and four of them were about mirroring rather than connecting, so release, metadata and placement options were hard to find. Connections now holds the Sources card and the destination card at their own heights. A new **Mirroring** tab holds Repository Selection and Mirror Content on the left and Organization Structure on the right. Destructive Update Protection moved to the Automation tab next to the sync cards, and the Authentication tab is now called **Access**, since it also holds API keys. The import button moved from the page header into the Sources card as **Import repositories**: it imports from every source, so it no longer names one, and it is hidden when only Git URL sources are connected, since those have nothing to list. No setting changed
|
||||
@@ -50,6 +52,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
- Pages keep what they last showed in this browser tab. Going back to the Dashboard, Repositories, Organizations, Storage or Activity Log shows that data at once and refreshes it in the background, instead of starting from a skeleton and waiting for the whole list again. Nothing is written to browser storage; a reload or a new tab starts fresh
|
||||
|
||||
### Fixed
|
||||
- **Repository cleanup never checked repositories that came in through your stars while Starred repositories was off** (#600, thanks @zwimer). Such a repository stays marked as starred after an unstar, and with the option off cleanup skipped every one of them, so a deleted source behind one was never found. Cleanup now reads your stars for them and looks up any that are no longer starred: a deleted source counts as gone, an unstar alone does not. With **Starred repositories** on, an unstar still counts as gone
|
||||
- **Release files added as a link were downloaded again on every sync** (#596, thanks @zwimer). Forgejo lists such a file with a size of 0, so it never matched the copy on the destination: each sync deleted that copy, downloaded the file and uploaded it again, and a failed download left the release without it until a later sync. When the source gives no size, a file with the same name already on the release now counts as mirrored. The log says "size not given by the source" instead of "0 bytes"
|
||||
- **All releases / Keep latest snapped back to 10 when cleared** (#595, thanks @zwimer), while the note under the release table said empty means no limit. That box always needs a number: it can now be cleared while typing, a whole number of 1 or more is saved, and leaving it empty puts the saved value back. The note says only the other boxes can stay empty, and the empty **Pre-releases** / **Keep latest** box reads "all" like the others
|
||||
- **Repository cleanup never checked a public only source** (#589, thanks @zwimer). For a source with no token it asked for the account's own repositories, which on Gitea and Forgejo went to `/users//orgs` when the username was empty too. The request failed on every run, the log said the account might be deleted or banned, and the source was skipped, so a repository deleted there was never noticed. Cleanup now lists the organizations added to such a source and looks up its other repositories one at a time; starred repositories on it are left alone. Gitea and GitLab sources also refuse to build a listing address for an empty username
|
||||
|
||||
@@ -101,8 +101,8 @@ function formatIntervalSeconds(interval: number | string | undefined): string {
|
||||
|
||||
/**
|
||||
* The three choices for a repository whose source is gone. What archive and
|
||||
* delete do depends on the destination switch below them: with it off only
|
||||
* gitea-mirror's own list changes (#558), so the tiles say so instead of
|
||||
* delete do depends on the destination switch right under them: with it off
|
||||
* only gitea-mirror's own list changes (#558), so the tiles say so instead of
|
||||
* promising a change on the destination.
|
||||
*/
|
||||
function orphanActions(applyToDestination: boolean) {
|
||||
@@ -123,7 +123,7 @@ function orphanActions(applyToDestination: boolean) {
|
||||
icon: Archive,
|
||||
info: applyToDestination
|
||||
? "Renames the mirror with an archived- prefix and disables automatic syncs. Nothing is lost; use Sync on the Repositories page to refresh."
|
||||
: "The repository is marked archived in gitea-mirror. The copy on the destination stays as it is. Turn on Apply to the destination too to archive it there as well.",
|
||||
: "The repository is marked archived in gitea-mirror. The copy on the destination stays as it is. Turn on Archive on the destination too, under these choices, to archive it there as well.",
|
||||
},
|
||||
{
|
||||
value: "delete" as const,
|
||||
@@ -134,7 +134,7 @@ function orphanActions(applyToDestination: boolean) {
|
||||
icon: Trash2,
|
||||
info: applyToDestination
|
||||
? "Permanently deletes the mirror repository from the destination."
|
||||
: "The repository is removed from gitea-mirror. The copy on the destination stays as it is. Turn on Apply to the destination too to delete it there as well.",
|
||||
: "The repository is removed from gitea-mirror. The copy on the destination stays as it is. Turn on Delete from the destination too, under these choices, to delete it there as well.",
|
||||
},
|
||||
];
|
||||
}
|
||||
@@ -542,48 +542,59 @@ export function AutomationSettings({
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
{/* Part of the choice above, so it sits right under it and is
|
||||
named after the action (#601). Off, the action still
|
||||
happens, in gitea-mirror's own list only. */}
|
||||
{(cleanupConfig.orphanedRepoAction ?? "archive") !== "skip" && (
|
||||
<SwitchRow
|
||||
label={
|
||||
cleanupConfig.orphanedRepoAction === "delete"
|
||||
? "Delete from the destination too"
|
||||
: "Archive on the destination too"
|
||||
}
|
||||
description={
|
||||
cleanupConfig.orphanedRepoAction === "delete"
|
||||
? "When off, the repository is only removed from gitea-mirror's list, and the copy on the destination stays as it is"
|
||||
: "When off, the repository is only marked archived in gitea-mirror, which stops syncing it, and the copy on the destination stays as it is"
|
||||
}
|
||||
info="Archiving keeps everything: a Gitea or Forgejo mirror gets an archived- prefix and stops syncing automatically, and GitHub or GitLab use their own archive. Deleting cannot be undone. CLEANUP_DELETE_FROM_GITEA, when set, replaces this on every restart."
|
||||
checked={Boolean(cleanupConfig.deleteFromGitea)}
|
||||
onCheckedChange={(checked) =>
|
||||
onCleanupChange({ ...cleanupConfig, deleteFromGitea: checked })
|
||||
}
|
||||
/>
|
||||
)}
|
||||
</CardSection>
|
||||
<CardDivider />
|
||||
<CardSection>
|
||||
{(cleanupConfig.orphanedRepoAction ?? "archive") !== "skip" && (
|
||||
<>
|
||||
<OptionRow
|
||||
label="Wait before acting"
|
||||
description="Act only once the source has been gone this many days. 0 acts on the first check that finds it gone"
|
||||
info="Counted from the first check that finds the source gone. If the source comes back during the wait, nothing happens and the count starts over. With cleanup notifications on, you hear about it when the wait starts. CLEANUP_ORPHANED_REPO_GRACE_DAYS, when set, replaces this on every restart."
|
||||
right={
|
||||
<div className="flex shrink-0 items-center gap-2 text-xs text-muted-foreground">
|
||||
<input
|
||||
id="cleanup-grace-days"
|
||||
type="number"
|
||||
min="0"
|
||||
inputMode="numeric"
|
||||
value={cleanupConfig.orphanedRepoGraceDays ?? 0}
|
||||
onChange={(event) => {
|
||||
const value = parseInt(event.target.value, 10);
|
||||
onCleanupChange({
|
||||
...cleanupConfig,
|
||||
orphanedRepoGraceDays: Number.isFinite(value) ? Math.max(0, value) : 0,
|
||||
});
|
||||
}}
|
||||
className="w-16 rounded border border-input bg-background px-2 py-1 text-xs text-foreground"
|
||||
/>
|
||||
<label htmlFor="cleanup-grace-days">
|
||||
{(cleanupConfig.orphanedRepoGraceDays ?? 0) === 1 ? "day" : "days"}
|
||||
</label>
|
||||
</div>
|
||||
}
|
||||
/>
|
||||
<SwitchRow
|
||||
label="Apply to the destination too"
|
||||
description="When off, only gitea-mirror's list changes and the copies on the destination stay as they are"
|
||||
info="Archiving keeps everything: a Gitea or Forgejo mirror gets an archived- prefix and stops syncing automatically, and GitHub or GitLab use their own archive. Deleting cannot be undone. CLEANUP_DELETE_FROM_GITEA, when set, replaces this on every restart."
|
||||
checked={Boolean(cleanupConfig.deleteFromGitea)}
|
||||
onCheckedChange={(checked) =>
|
||||
onCleanupChange({ ...cleanupConfig, deleteFromGitea: checked })
|
||||
}
|
||||
/>
|
||||
</>
|
||||
<OptionRow
|
||||
label="Wait before acting"
|
||||
description="Act only once the source has been gone this many days. 0 acts on the first check that finds it gone"
|
||||
info="Counted from the first check that finds the source gone. If the source comes back during the wait, nothing happens and the count starts over. With cleanup notifications on, you hear about it when the wait starts. CLEANUP_ORPHANED_REPO_GRACE_DAYS, when set, replaces this on every restart."
|
||||
right={
|
||||
<div className="flex shrink-0 items-center gap-2 text-xs text-muted-foreground">
|
||||
<input
|
||||
id="cleanup-grace-days"
|
||||
type="number"
|
||||
min="0"
|
||||
inputMode="numeric"
|
||||
value={cleanupConfig.orphanedRepoGraceDays ?? 0}
|
||||
onChange={(event) => {
|
||||
const value = parseInt(event.target.value, 10);
|
||||
onCleanupChange({
|
||||
...cleanupConfig,
|
||||
orphanedRepoGraceDays: Number.isFinite(value) ? Math.max(0, value) : 0,
|
||||
});
|
||||
}}
|
||||
className="w-16 rounded border border-input bg-background px-2 py-1 text-xs text-foreground"
|
||||
/>
|
||||
<label htmlFor="cleanup-grace-days">
|
||||
{(cleanupConfig.orphanedRepoGraceDays ?? 0) === 1 ? "day" : "days"}
|
||||
</label>
|
||||
</div>
|
||||
}
|
||||
/>
|
||||
)}
|
||||
<SwitchRow
|
||||
label="Dry run"
|
||||
|
||||
@@ -401,13 +401,13 @@ export function Storage() {
|
||||
title="Total stored"
|
||||
value={formatBytes(totals.total)}
|
||||
icon={<HardDrive className="h-4 w-4" />}
|
||||
description={`Across ${totals.measured} ${totals.measured === 1 ? "repository" : "repositories"}`}
|
||||
description={`Your ${totals.measured} ${totals.measured === 1 ? "mirror" : "mirrors"}, not the whole destination`}
|
||||
/>
|
||||
<StatusCard
|
||||
title="Git + LFS"
|
||||
value={formatBytes(totals.destinationSize)}
|
||||
icon={<Database className="h-4 w-4" />}
|
||||
description="As the destination reports it"
|
||||
description="As the destination reports each mirror"
|
||||
/>
|
||||
<StatusCard
|
||||
title="Release assets"
|
||||
@@ -576,7 +576,9 @@ export function Storage() {
|
||||
<p className="text-xs text-muted-foreground">
|
||||
Sizes are what the destination reports: Git and LFS together, plus the release assets it stores. Each sync
|
||||
records them from data it already fetches, and Refresh sizes reads them from the destination on demand. The
|
||||
Git size a sync records is read before it pulls, so it trails by one sync.
|
||||
Git size a sync records is read before it pulls, so it trails by one sync. Only these mirrors are counted:
|
||||
the destination's own database and search indexes, wikis, files attached to issues and repositories
|
||||
gitea-mirror doesn't manage are not, so its data folder on disk is bigger than the total.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
194
src/lib/cleanup-starred-rows.test.ts
Normal file
194
src/lib/cleanup-starred-rows.test.ts
Normal file
@@ -0,0 +1,194 @@
|
||||
/**
|
||||
* Repository cleanup and rows flagged starred (#600). The flag means the row
|
||||
* came in through the star list, and it stays after an unstar. With starred
|
||||
* import off, cleanup used to skip those rows outright, so a deleted source
|
||||
* behind one was never found. Now it reads the star list for them and checks
|
||||
* the rest by a plain lookup; only with starred import on does an unstar
|
||||
* count as gone.
|
||||
*
|
||||
* Runs against the real schema in an in-memory SQLite database that replaces
|
||||
* @/lib/db through mock.module, with the source host faked, so the file runs
|
||||
* in its own process.
|
||||
*/
|
||||
import { beforeEach, describe, expect, mock, test } from "bun:test";
|
||||
import { Database } from "bun:sqlite";
|
||||
import { drizzle } from "drizzle-orm/bun-sqlite";
|
||||
import { readFileSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
import * as schema from "@/lib/db/schema";
|
||||
import { runsIsolated } from "@/tests/isolated";
|
||||
|
||||
const isolated = runsIsolated(import.meta.path);
|
||||
|
||||
const sqlite = new Database(":memory:");
|
||||
const db = drizzle({ client: sqlite });
|
||||
|
||||
function applyMigrations(): void {
|
||||
const folder = join(process.cwd(), "drizzle");
|
||||
const journal = JSON.parse(readFileSync(join(folder, "meta", "_journal.json"), "utf8")) as {
|
||||
entries: { tag: string }[];
|
||||
};
|
||||
for (const entry of journal.entries) {
|
||||
const sql = readFileSync(join(folder, `${entry.tag}.sql`), "utf8");
|
||||
for (const statement of sql.split("--> statement-breakpoint")) {
|
||||
if (statement.trim()) sqlite.run(statement);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const gitRepo = (fullName: string, extra: Record<string, unknown> = {}) => ({
|
||||
fullName,
|
||||
name: fullName.split("/")[1],
|
||||
owner: fullName.split("/")[0],
|
||||
...extra,
|
||||
});
|
||||
|
||||
/** What the fake source host was asked. */
|
||||
const calls = {
|
||||
starListings: [] as unknown[],
|
||||
lookups: [] as string[],
|
||||
starChecks: [] as string[],
|
||||
};
|
||||
/** Repositories that exist on the source. */
|
||||
let existing = new Set<string>();
|
||||
/** Repositories the account has starred. */
|
||||
let starred = new Set<string>();
|
||||
|
||||
const provider = {
|
||||
connection: { token: "token", username: "me", url: "https://github.com", provider: "github" },
|
||||
listRepositories: async () => [gitRepo("me/owned")],
|
||||
listStarredRepositories: async (config: any) => {
|
||||
calls.starListings.push(config?.githubConfig?.starredLists);
|
||||
return [...starred].map((fullName) => gitRepo(fullName, { isStarred: true }));
|
||||
},
|
||||
getRepository: async (owner: string, name: string) => {
|
||||
calls.lookups.push(`${owner}/${name}`);
|
||||
return existing.has(`${owner}/${name}`) ? gitRepo(`${owner}/${name}`) : null;
|
||||
},
|
||||
isRepositoryStarred: async (owner: string, name: string) => {
|
||||
calls.starChecks.push(`${owner}/${name}`);
|
||||
return starred.has(`${owner}/${name}`);
|
||||
},
|
||||
};
|
||||
|
||||
if (isolated) {
|
||||
process.env.ENCRYPTION_SECRET ??= "cleanup-starred-rows-test-secret-0123456";
|
||||
applyMigrations();
|
||||
// Copy the real exports before mocking: mock.module patches the namespace.
|
||||
const realProviders = { ...(await import("@/lib/source-providers")) };
|
||||
const realSources = { ...(await import("@/lib/sources")) };
|
||||
mock.module("@/lib/db", () => ({ ...schema, db }));
|
||||
mock.module("@/lib/source-providers", () => ({
|
||||
...realProviders,
|
||||
createSourceProviderFromSource: () => provider,
|
||||
isRepositoryFromConfiguredSource: () => true,
|
||||
}));
|
||||
mock.module("@/lib/sources", () => ({
|
||||
...realSources,
|
||||
listSources: async () => [
|
||||
{ id: "src-gh", name: "GitHub", provider: "github", url: "https://github.com", username: "me", token: "token", enabled: true },
|
||||
],
|
||||
}));
|
||||
}
|
||||
|
||||
const { identifyOrphanedRepositories } = isolated
|
||||
? await import("@/lib/repository-cleanup-service")
|
||||
: ({} as Partial<typeof import("@/lib/repository-cleanup-service")>);
|
||||
|
||||
function configWith(githubConfig: Record<string, unknown>) {
|
||||
return {
|
||||
id: "config-1",
|
||||
userId: "user-1",
|
||||
githubConfig,
|
||||
cleanupConfig: { enabled: true, deleteIfNotInGitHub: true, orphanedRepoAction: "archive" },
|
||||
};
|
||||
}
|
||||
|
||||
function repoRow(fullName: string, extra: Record<string, unknown> = {}) {
|
||||
const [owner, name] = fullName.split("/");
|
||||
return {
|
||||
id: `repo-${fullName.replace("/", "-")}`,
|
||||
userId: "user-1",
|
||||
configId: "config-1",
|
||||
sourceId: "src-gh",
|
||||
sourceProvider: "github",
|
||||
sourceUrl: "https://github.com",
|
||||
name,
|
||||
fullName,
|
||||
normalizedFullName: fullName.toLowerCase(),
|
||||
url: `https://github.com/${fullName}`,
|
||||
cloneUrl: `https://github.com/${fullName}.git`,
|
||||
owner,
|
||||
defaultBranch: "main",
|
||||
status: "mirrored",
|
||||
...extra,
|
||||
} as any;
|
||||
}
|
||||
|
||||
async function seed(rows: any[]) {
|
||||
for (const table of ["repositories", "organizations", "configs", "users"]) {
|
||||
sqlite.run(`DELETE FROM ${table}`);
|
||||
}
|
||||
sqlite.run(`INSERT INTO users (id, email) VALUES ('user-1', 'user-1@example.com')`);
|
||||
await db.insert(schema.configs).values({
|
||||
id: "config-1",
|
||||
userId: "user-1",
|
||||
name: "Default",
|
||||
isActive: true,
|
||||
githubConfig: {} as any,
|
||||
giteaConfig: { url: "https://gitea.example.com", defaultOwner: "mirror" } as any,
|
||||
scheduleConfig: { enabled: false } as any,
|
||||
cleanupConfig: { enabled: true } as any,
|
||||
});
|
||||
await db.insert(schema.repositories).values(rows);
|
||||
}
|
||||
|
||||
if (isolated) {
|
||||
describe("repository cleanup and rows flagged starred (#600)", () => {
|
||||
beforeEach(async () => {
|
||||
calls.starListings.length = 0;
|
||||
calls.lookups.length = 0;
|
||||
calls.starChecks.length = 0;
|
||||
existing = new Set(["me/owned", "them/still-starred", "them/unstarred"]);
|
||||
starred = new Set(["them/still-starred"]);
|
||||
await seed([
|
||||
repoRow("me/owned"),
|
||||
repoRow("them/still-starred", { isStarred: true }),
|
||||
// Starred once, unstarred since, still on the source.
|
||||
repoRow("them/unstarred", { isStarred: true }),
|
||||
// Starred once, then deleted on the source.
|
||||
repoRow("them/deleted", { isStarred: true }),
|
||||
]);
|
||||
});
|
||||
|
||||
test("with starred import off, finds the deleted source and keeps the unstarred one", async () => {
|
||||
const orphaned = await identifyOrphanedRepositories!(
|
||||
configWith({ includeStarred: false, starredLists: ["old list"] })
|
||||
);
|
||||
|
||||
expect(orphaned.map((repo: any) => repo.fullName)).toEqual(["them/deleted"]);
|
||||
// The star list is read once, without the saved list filter.
|
||||
expect(calls.starListings).toEqual([[]]);
|
||||
// Only rows missing from both listings are looked up, by existence.
|
||||
expect(calls.lookups.sort()).toEqual(["them/deleted", "them/unstarred"]);
|
||||
expect(calls.starChecks).toEqual([]);
|
||||
});
|
||||
|
||||
test("with starred import on, an unstar still counts as gone", async () => {
|
||||
const orphaned = await identifyOrphanedRepositories!(configWith({ includeStarred: true }));
|
||||
|
||||
expect(orphaned.map((repo: any) => repo.fullName).sort()).toEqual(["them/deleted", "them/unstarred"]);
|
||||
expect(calls.starChecks.sort()).toEqual(["them/deleted", "them/unstarred"]);
|
||||
expect(calls.lookups).toEqual([]);
|
||||
});
|
||||
|
||||
test("with starred import off and no starred rows, the star list is not read", async () => {
|
||||
await seed([repoRow("me/owned")]);
|
||||
|
||||
const orphaned = await identifyOrphanedRepositories!(configWith({ includeStarred: false }));
|
||||
|
||||
expect(orphaned).toEqual([]);
|
||||
expect(calls.starListings).toEqual([]);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -140,6 +140,17 @@ export async function listPublicOnlySourceRepositories(
|
||||
return repos;
|
||||
}
|
||||
|
||||
/**
|
||||
* The config with the GitHub star list filter removed, for reading the stars
|
||||
* of rows flagged starred while starred import is off (#600). Lists saved from
|
||||
* an earlier setup would narrow the listing, or fail it when a list was
|
||||
* renamed since, and any star is enough to show such a row is still there.
|
||||
*/
|
||||
export function withEveryStar<T extends { githubConfig?: unknown }>(config: T): T {
|
||||
const githubConfig = (config.githubConfig ?? {}) as Record<string, unknown>;
|
||||
return { ...config, githubConfig: { ...githubConfig, starredLists: [] } };
|
||||
}
|
||||
|
||||
/**
|
||||
* Identify orphaned repositories for a user
|
||||
* These are repositories that exist in our database (and likely in Gitea)
|
||||
@@ -252,6 +263,21 @@ async function scanForOrphanedRepositories(config: any): Promise<OrphanScan> {
|
||||
|
||||
let allGithubRepos: any[] = [];
|
||||
|
||||
// A row flagged starred came in through the star list, and the flag
|
||||
// stays after an unstar (#600). With starred repositories imported, an
|
||||
// unstar counts as gone, as it always has. With them off the star list
|
||||
// is still read for such rows, so a star that is still there costs no
|
||||
// extra request, but only a deleted source counts as gone: a row
|
||||
// missing from the list gets the plain existence check below.
|
||||
const unstarCountsAsGone = config.githubConfig?.includeStarred === true;
|
||||
const hasStarredRows = sourceOwnedRepos.some(
|
||||
repo =>
|
||||
repo.sourceId === source.id &&
|
||||
repo.isStarred &&
|
||||
repo.status !== 'archived' &&
|
||||
!repo.isArchived
|
||||
);
|
||||
|
||||
try {
|
||||
if (publicOnly) {
|
||||
const organizationNames = organizationsToListForPublicSource(
|
||||
@@ -278,9 +304,11 @@ async function scanForOrphanedRepositories(config: any): Promise<OrphanScan> {
|
||||
includeCollaboratorReposOverride: true,
|
||||
includeAllOrgsOverride: true,
|
||||
}),
|
||||
config.githubConfig?.includeStarred
|
||||
unstarCountsAsGone
|
||||
? sourceProvider.listStarredRepositories(config)
|
||||
: Promise.resolve([]),
|
||||
: hasStarredRows
|
||||
? sourceProvider.listStarredRepositories(withEveryStar(config))
|
||||
: Promise.resolve([]),
|
||||
]);
|
||||
|
||||
allGithubRepos = [...basicAndForkedRepos, ...starredRepos];
|
||||
@@ -334,12 +362,6 @@ async function scanForOrphanedRepositories(config: any): Promise<OrphanScan> {
|
||||
return false;
|
||||
}
|
||||
|
||||
// If starred repos are not being fetched from the source, we can't determine
|
||||
// if a starred repo is orphaned - skip it to prevent data loss
|
||||
if (repo.isStarred && !config.githubConfig?.includeStarred) {
|
||||
console.log(`[Repository Cleanup] Skipping starred repo ${repo.fullName} - starred repos not being fetched from the source`);
|
||||
return false;
|
||||
}
|
||||
// Stars belong to an account; a public only source has none to ask.
|
||||
if (repo.isStarred && publicOnly) {
|
||||
console.log(`[Repository Cleanup] Skipping starred repo ${repo.fullName} - source ${source.name} has no account to check stars with`);
|
||||
@@ -380,7 +402,7 @@ async function scanForOrphanedRepositories(config: any): Promise<OrphanScan> {
|
||||
// would not resolve on the source host.
|
||||
const upstreamPath = splitFullName(repo.fullName, repo.owner, repo.name);
|
||||
|
||||
if (repo.isStarred) {
|
||||
if (repo.isStarred && unstarCountsAsGone) {
|
||||
try {
|
||||
const stillStarred = await sourceProvider.isRepositoryStarred(
|
||||
upstreamPath.owner,
|
||||
|
||||
@@ -20,7 +20,7 @@ Cleanup looks for repositories that the database tracks but that no longer exist
|
||||
| Action | `CLEANUP_ORPHANED_REPO_ACTION` | `archive` | `skip` leaves the mirror untouched, `archive` keeps it read only with an archived prefix, `delete` removes it. |
|
||||
| Wait before acting | `CLEANUP_ORPHANED_REPO_GRACE_DAYS` | `0` | Act only once the source has been gone this many days. `0` acts on the first check that finds it gone. Shown on the card unless the action is `skip`. See [the wait](#waiting-before-acting). |
|
||||
| Dry run | `CLEANUP_DRY_RUN` | off | Log the planned actions without changing anything. |
|
||||
| Apply to the destination too | `CLEANUP_DELETE_FROM_GITEA` | `false` | Apply the action on the destination too. Off means only gitea-mirror's own list is updated. Shown on the card unless the action is `skip`. |
|
||||
| Archive on the destination too, or Delete from the destination too | `CLEANUP_DELETE_FROM_GITEA` | `false` | Apply the action on the destination too. Off means only gitea-mirror's own list is updated. Shown right under the action, named after it, unless the action is `skip`. |
|
||||
| Protected repositories | `CLEANUP_PROTECTED_REPOS` | none | Comma-separated repository names cleanup never touches. |
|
||||
| Batch size and pause | `CLEANUP_BATCH_SIZE`, `CLEANUP_PAUSE_BETWEEN_DELETES` | `10`, `2000` | Items per batch, and the pause between deletions in milliseconds. |
|
||||
|
||||
@@ -38,12 +38,12 @@ The wait counts from the first check that saw the source gone, and checks run ev
|
||||
|
||||
### What each action does
|
||||
|
||||
`archive` never deletes. With **Apply to the destination too** off, the default, the row is marked archived in the database and the destination is left alone. With it on:
|
||||
`archive` never deletes. With **Archive on the destination too** off, the default, the row is marked archived in the database, gitea-mirror stops syncing it, and the destination is left alone. With it on:
|
||||
|
||||
- On Gitea and Forgejo, the mirror is renamed with an `archived-` prefix, because the Gitea API cannot archive a mirror. It gets a description that says why and has its automatic syncs turned off (a manual sync still works). It remains fully cloneable.
|
||||
- On GitHub and GitLab, the repository is archived through the host's API.
|
||||
|
||||
`delete` removes the row from the database and, with **Apply to the destination too** on, removes the repository from the destination. Deleting on GitHub needs a token with the `delete_repo` scope; without it the run fails with a message naming the scope and the repository stays. On gitlab.com and instances with delayed deletion, a deleted project is renamed and kept for the configured number of days. For push targets the bare clone on disk is removed as well.
|
||||
`delete` removes the row from the database and, with **Delete from the destination too** on, removes the repository from the destination. Deleting on GitHub needs a token with the `delete_repo` scope; without it the run fails with a message naming the scope and the repository stays. On gitlab.com and instances with delayed deletion, a deleted project is renamed and kept for the configured number of days. For push targets the bare clone on disk is removed as well.
|
||||
|
||||
If archiving fails for any reason, the repository is left alone and stays accessible.
|
||||
|
||||
@@ -55,6 +55,7 @@ Cleanup is careful about what it calls an orphan, because the cost of a false po
|
||||
|
||||
- It first lists everything the source token can see, including collaborator repositories and every organization regardless of the import filters, so narrowing a filter later cannot make old mirrors look orphaned.
|
||||
- A public only source, one without a token, has no account to list. Cleanup lists the organizations you added to it instead, and every other repository on it, such as one added by URL, goes straight to the direct lookup below. Its starred repositories are left alone. On GitHub these lookups count against the anonymous limit of 60 requests an hour.
|
||||
- A repository that came in through your stars stays marked as starred after you unstar it. With **Starred repositories** on in Repository Selection, unstarring it counts as gone. With it off, only a deleted source counts: cleanup still reads your stars for these repositories, and one that is no longer starred gets the direct lookup below.
|
||||
- A repository missing from that list is only a candidate. It counts as orphaned when a direct lookup of that repository on the source returns a clean 404 as well. Any other outcome, including a rate limit, a network error or a 5xx, leaves it alone.
|
||||
- If the source API cannot be reached at all, or answers 403 or 404 for the account itself, that source is skipped until the next run.
|
||||
- Repositories imported from a previous source, and rows mirrored to a previous destination, are not touched.
|
||||
|
||||
@@ -218,7 +218,7 @@ Cleanup covers both trimming the activity log and handling repositories that no
|
||||
| `CLEANUP_DELETE_IF_NOT_IN_GITHUB` | `true` | Act on repositories that no longer exist on the source. |
|
||||
| `CLEANUP_ORPHANED_REPO_ACTION` | `archive` | What to do with an orphaned repository: `skip`, `archive`, or `delete`. |
|
||||
| `CLEANUP_ORPHANED_REPO_GRACE_DAYS` | `0` | Days the source must stay gone before that action is applied, counted from the first check that finds it gone. `0` acts right away. Same as **Wait before acting** on the Repository Cleanup card. |
|
||||
| `CLEANUP_DELETE_FROM_GITEA` | `false` | Apply the orphan action on the destination too, not just in the local database. Same as **Apply to the destination too** on the Repository Cleanup card. Deleting on a GitHub push target needs the `delete_repo` scope. |
|
||||
| `CLEANUP_DELETE_FROM_GITEA` | `false` | Apply the orphan action on the destination too, not just in the local database. Same as the **Archive on the destination too** (or **Delete from the destination too**) switch on the Repository Cleanup card. Deleting on a GitHub push target needs the `delete_repo` scope. |
|
||||
| `CLEANUP_PROTECTED_REPOS` | none | Comma-separated repositories cleanup will never touch, matched exactly by name or by `owner/name`. |
|
||||
| `CLEANUP_DRY_RUN` | `false` | Log what cleanup would do without doing it. |
|
||||
| `CLEANUP_BATCH_SIZE` | `10` | Items processed per batch. |
|
||||
|
||||
@@ -35,7 +35,7 @@ Only terminal job statuses trigger sync notifications. Jobs that are still queue
|
||||
|
||||
New repositories arrive as one notification per group instead of one per repository: one for your account, one per organization, and one for all starred repositories. Each lists up to 10 names, then "and N more".
|
||||
|
||||
A cleanup run sends one notification for everything it did, for example "Repository Cleanup: 2 repositories archived", listing up to 10 names, followed by any repository it could not handle. It says whether the destination was changed or only gitea-mirror's own list, which depends on **Apply to the destination too**. A repository is reported once: the next run leaves an archived repository alone.
|
||||
A cleanup run sends one notification for everything it did, for example "Repository Cleanup: 2 repositories archived", listing up to 10 names, followed by any repository it could not handle. It says whether the destination was changed or only gitea-mirror's own list, which depends on the **Archive on the destination too** (or **Delete from the destination too**) switch. A repository is reported once: the next run leaves an archived repository alone.
|
||||
|
||||
With **Wait before acting** set, the run that first finds a source gone sends a heads-up instead, for example "Repository Cleanup: source gone for 1 repository", saying on which day the repository will be archived or removed if its source is still gone. It is sent once per disappearance, with the same switch and the same `repo_cleanup` type.
|
||||
|
||||
|
||||
@@ -150,6 +150,8 @@ The **Storage** page shows how much space your mirrors take on the destination:
|
||||
|
||||
Sizes are recorded during each sync from answers Gitea Mirror already gets, so they trail by one sync and cost no extra requests. Nothing is asked of the source. A repository whose release assets are at least half its size, and at least 50 MB, gets a hint pointing to its release limit.
|
||||
|
||||
Only the mirrors Gitea Mirror manages are counted, at the size the destination reports for each: Git and LFS, plus release assets. The destination's own database and search indexes, wikis, files attached to issues and repositories Gitea Mirror doesn't manage are not, so the destination's data folder on disk is bigger than the total.
|
||||
|
||||
**Refresh sizes** reads every mirror's size from the destination now instead of waiting for the next sync. It works with Gitea and Forgejo destinations; GitHub and GitLab destinations are not measured.
|
||||
|
||||
## Activity Log
|
||||
|
||||
Reference in New Issue
Block a user