Repository: WeblateOrg/weblate

Issue:
Component discovery and component lists
### Describe the problem

When a discovery add-on creates a component, it does copy many settings, but it does not add the created component to the component lists of the main component.

### Describe the solution you would like

The discovered component should be part of the same component lists as the main. Possibly excluding the ones with automatic assignment configured.

### Describe alternatives you have considered

_No response_

### Screenshots

_No response_

### Additional context

_No response_


Discussion:

Resolving patch:
diff --git a/weblate/trans/discovery.py b/weblate/trans/discovery.py
--- a/weblate/trans/discovery.py
+++ b/weblate/trans/discovery.py
@@ -234,7 +234,8 @@ def get_val(key, extra=0):
                 "intermediate": match["intermediate"],
                 "file_format": self.file_format,
                 "language_regex": self.language_re,
-                "addons_from": main.pk if self.copy_addons and main else None,
+                "copy_from": main.pk if main else None,
+                "copy_addons": self.copy_addons,
             }
         )
 
diff --git a/weblate/trans/tasks.py b/weblate/trans/tasks.py
--- a/weblate/trans/tasks.py
+++ b/weblate/trans/tasks.py
@@ -34,6 +34,7 @@
     Change,
     Comment,
     Component,
+    ComponentList,
     Project,
     Suggestion,
     Translation,
@@ -510,22 +511,29 @@ def auto_translate_component(
 
 
 @app.task(trail=False)
-def create_component(addons_from=None, in_task=False, **kwargs):
+def create_component(copy_from=None, copy_addons=False, in_task=False, **kwargs):
     kwargs["project"] = Project.objects.get(pk=kwargs["project"])
     kwargs["source_language"] = Language.objects.get(pk=kwargs["source_language"])
     component = Component.objects.create(**kwargs)
     component.change_set.create(action=Change.ACTION_CREATE_COMPONENT)
-    if addons_from:
-        addons = Addon.objects.filter(
-            component__pk=addons_from, project_scope=False, repo_scope=False
-        )
-        for addon in addons:
-            # Avoid installing duplicate addons
-            if component.addon_set.filter(name=addon.name).exists():
-                continue
-            if not addon.addon.can_install(component, None):
-                continue
-            addon.addon.create(component, configuration=addon.configuration)
+    if copy_from:
+        # Copy non-automatic component lists
+        for clist in ComponentList.objects.filter(
+            components__id=copy_from, autocomponentlist__isnull=True
+        ):
+            clist.components.add(component)
+        # Copy add-ons
+        if copy_addons:
+            addons = Addon.objects.filter(
+                component__pk=copy_from, project_scope=False, repo_scope=False
+            )
+            for addon in addons:
+                # Avoid installing duplicate addons
+                if component.addon_set.filter(name=addon.name).exists():
+                    continue
+                if not addon.addon.can_install(component, None):
+                    continue
+                addon.addon.create(component, configuration=addon.configuration)
     if in_task:
         return {"component": component.id}
     return component


Test patch: