diff --git a/docs/api.rst b/docs/api.rst index 8b3cd20a15a4..8affe46ebcab 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -1195,10 +1195,12 @@ Components :>json string name: :ref:`component-name` :>json string slug: :ref:`component-slug` :>json string vcs: :ref:`component-vcs` - :>json string repo: :ref:`component-repo` + :>json string linked_component: component whose repository is linked via :ref:`internal-urls` + :>json string repo: :ref:`component-repo`, this is the actual repository URL even when :ref:`internal-urls` are used, use ``linked_component`` to detect this situation :>json string git_export: :ref:`component-git_export` - :>json string branch: :ref:`component-branch` - :>json string push_branch: :ref:`component-push_branch` + :>json string branch: :ref:`component-branch`, this is the actual repository branch even when :ref:`internal-urls` are used + :>json string push: :ref:`component-push`, this is the actual repository URL even when :ref:`internal-urls` are used + :>json string push_branch: :ref:`component-push_branch`, this is the actual repository brach even when :ref:`internal-urls` are used :>json string filemask: :ref:`component-filemask` :>json string template: :ref:`component-template` :>json string edit_template: :ref:`component-edit_template` @@ -1210,7 +1212,6 @@ Components :>json string new_lang: :ref:`component-new_lang` :>json string language_code_style: :ref:`component-language_code_style` :>json object source_language: source language object; see :http:get:`/api/languages/(string:language)/` - :>json string push: :ref:`component-push` :>json string check_flags: :ref:`component-check_flags` :>json string priority: :ref:`component-priority` :>json string enforced_checks: :ref:`component-enforced_checks` diff --git a/docs/changes.rst b/docs/changes.rst index d778f2600d1d..f1aae64d935f 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -22,6 +22,7 @@ Not yet released. * :ref:`num-words` support for CJK languages. * :ref:`addon-weblate.discovery.discovery` now preserves :ref:`componentlists`. * Nicer formatting of :ref:`glossary` tooltips. +* :http:get:`/api/components/(string:project)/(string:component)/` now includes information about linked component. **Bug fixes** diff --git a/weblate/api/serializers.py b/weblate/api/serializers.py index e0860a68dfcf..a56bae9368da 100644 --- a/weblate/api/serializers.py +++ b/weblate/api/serializers.py @@ -489,6 +489,12 @@ class ComponentSerializer(RemovableSerializer): required=False, allow_null=True, ) + linked_component = MultiFieldHyperlinkedIdentityField( + view_name="api:component-detail", + lookup_field=("linked_component__project__slug", "linked_component__slug"), + strip_parts=1, + read_only=True, + ) task_url = RelatedTaskField(lookup_field="background_task_id") @@ -564,6 +570,7 @@ class Meta: "glossary_color", "disable_autoshare", "category", + "linked_component", ) extra_kwargs = { "url": { diff --git a/weblate/api/tests.py b/weblate/api/tests.py index 9cd8ccbd89be..99fa85519163 100644 --- a/weblate/api/tests.py +++ b/weblate/api/tests.py @@ -1343,6 +1343,11 @@ def test_create_component_no_push(self): "weblate://test/test", ) self.assertEqual(response.data["repo"], repo_url) + self.assertEqual( + response.data["linked_component"], + "http://example.com" + + reverse("api:component-detail", kwargs=self.component_kwargs), + ) def test_create_component_empty_push(self): repo_url = self.format_local_path(self.git_repo_path) @@ -1369,6 +1374,11 @@ def test_create_component_empty_push(self): "weblate://test/test", ) self.assertEqual(response.data["repo"], repo_url) + self.assertEqual( + response.data["linked_component"], + "http://example.com" + + reverse("api:component-detail", kwargs=self.component_kwargs), + ) def test_create_component_no_match(self): response = self.do_request(