update: If cateogories.yml only has icon:, then add name:

E.g. if _categories.yml_ is like:

```yaml
Time:
  icon: time.png
```
This commit is contained in:
Hans-Christoph Steiner 2025-05-22 19:54:07 +02:00
parent 964861eb68
commit 494d811846
2 changed files with 38 additions and 1 deletions

View File

@ -775,7 +775,9 @@ def make_v2(apps, packages, repodir, repodict, requestsdict, signer_fingerprints
# include definitions for "auto-defined" categories, e.g. just used in app metadata
for category in sorted(categories_used_by_apps):
if category not in output['repo'][CATEGORIES_CONFIG_NAME]:
output['repo'][CATEGORIES_CONFIG_NAME][category] = {"name": {DEFAULT_LOCALE: category}}
output['repo'][CATEGORIES_CONFIG_NAME][category] = dict()
if 'name' not in output['repo'][CATEGORIES_CONFIG_NAME][category]:
output['repo'][CATEGORIES_CONFIG_NAME][category]['name'] = {DEFAULT_LOCALE: category}
# do not include defined categories if no apps use them
for category in list(output['repo'].get(CATEGORIES_CONFIG_NAME, list())):
if category not in categories_used_by_apps:

View File

@ -1913,6 +1913,41 @@ class UpdateTest(unittest.TestCase):
index['repo'][CATEGORIES_CONFIG_NAME],
)
def test_categories_with_only_icon_defined(self):
"""If cateogories.yml only includes the icon, the name should be added."""
os.chdir(self.testdir)
os.mkdir('config')
os.mkdir('metadata')
os.mkdir('repo')
fdroidserver.common.write_config_file(
'repo_pubkey: ffffffffffffffffffffffffffffffffffffffff\n'
)
testvalue = 'Time'
Path('config/time.png').write_text('placeholder')
Path('config/categories.yml').write_text(testvalue + ': {icon: time.png}')
testapk = os.path.join('repo', 'com.politedroid_6.apk')
shutil.copy(basedir / testapk, testapk)
Path('metadata/com.politedroid.yml').write_text(f'Categories: [{testvalue}]')
with mock.patch('sys.argv', ['fdroid update', '--delete-unknown', '--nosign']):
fdroidserver.update.main()
with open('repo/index-v2.json') as fp:
index = json.load(fp)
self.assertEqual(
{
'icon': {
'en-US': {
'name': '/icons/time.png',
'sha256': '4097889236a2af26c293033feb964c4cf118c0224e0d063fec0a89e9d0569ef2',
'size': 11,
}
},
'name': {'en-US': testvalue},
},
index['repo'][CATEGORIES_CONFIG_NAME][testvalue],
)
def test_auto_defined_categories_two_apps(self):
"""Repos that don't define categories in config/ should use auto-generated."""
os.chdir(self.testdir)