mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-05-15 22:48:00 +02:00
fix(repo): reuse existing record on rename to avoid externalId duplicate key
When a GitHub repo is renamed and looked up by its new name, the lookup by name misses but a record with the same externalId still exists, causing E11000 on save. Fall back to a lookup by externalId before creating a new document. Fixes #500 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -298,6 +298,12 @@ export async function getRepositoryFromGitHub(opt: {
|
|||||||
repo: opt.repo,
|
repo: opt.repo,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
// If the lookup-by-name missed but we already have a record for this
|
||||||
|
// GitHub repo id (e.g. the repo was renamed on GitHub), reuse it instead
|
||||||
|
// of creating a duplicate that would violate the externalId unique index.
|
||||||
|
if (!dbModel && isConnected) {
|
||||||
|
dbModel = await RepositoryModel.findOne({ externalId: "gh_" + r.id });
|
||||||
|
}
|
||||||
const model = dbModel || new RepositoryModel({ externalId: "gh_" + r.id });
|
const model = dbModel || new RepositoryModel({ externalId: "gh_" + r.id });
|
||||||
model.name = r.full_name;
|
model.name = r.full_name;
|
||||||
model.url = r.html_url;
|
model.url = r.html_url;
|
||||||
|
|||||||
Reference in New Issue
Block a user