Skip to content

Commit

Permalink
Clone RepositoryScore when cloning a repository
Browse files Browse the repository at this point in the history
  • Loading branch information
victor-salles committed Sep 23, 2022
1 parent ee0819c commit f18b1dc
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions bothub/common/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,22 @@ def clone_repository(

# region 2. ForeignKeys and ManyToManyFields
clone_repository.categories.set(source_repository.categories.all())

score_queue = []
score_exclude_fields = ("id", "pk", "uuid", "repository")
score_fields = RepositoryScore._meta.fields
for original_score in source_repository.repository_score.all():
clone_score = RepositoryScore(repository=clone_repository)
# copy fields and values
for field in score_fields:
if not (field.name in score_exclude_fields or field.primary_key):
setattr(
clone_score,
field.name,
getattr(original_score, field.name),
)
score_queue.append(clone_score)
RepositoryScore.objects.bulk_create(score_queue)
# endregion

# region 3. reverse ForeignKeys and ManyToManyFields (the ones which reference the Repository)
Expand Down

0 comments on commit f18b1dc

Please sign in to comment.