Skip to content

Commit

Permalink
api: expose linked component
Browse files Browse the repository at this point in the history
  • Loading branch information
nijel committed Feb 13, 2024
1 parent 1cdbfcb commit cdf1234
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
9 changes: 5 additions & 4 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand All @@ -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`
Expand Down
1 change: 1 addition & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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**

Expand Down
7 changes: 7 additions & 0 deletions weblate/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -564,6 +570,7 @@ class Meta:
"glossary_color",
"disable_autoshare",
"category",
"linked_component",
)
extra_kwargs = {
"url": {
Expand Down
10 changes: 10 additions & 0 deletions weblate/api/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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(
Expand Down

0 comments on commit cdf1234

Please sign in to comment.