From afec880c81b58683bfa10680d95c68ae0408bd5f Mon Sep 17 00:00:00 2001 From: Ashutosh Gangwar Date: Sun, 30 Oct 2022 19:00:51 +0530 Subject: [PATCH 1/2] use default.txt as fallback changelog when inserting fastlane metadata --- fdroidserver/update.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/fdroidserver/update.py b/fdroidserver/update.py index 1ed8a3a8..1bf20530 100644 --- a/fdroidserver/update.py +++ b/fdroidserver/update.py @@ -996,6 +996,12 @@ def insert_localized_app_metadata(apps): locale = segments[-2] _set_localized_text_entry(apps[packageName], locale, 'whatsNew', os.path.join(root, f)) + elif f == 'default.txt': + # use `default.txt` changelog entry as fallback. + localized = _get_localized_dict(apps[packageName], locale) + if not localized.get('whatsNew', ''): + _set_localized_text_entry(apps[packageName], locale, 'whatsNew', + os.path.join(root, f)) base, extension = common.get_extension(f) From 8b484b37bd51dec17e42a8485266ab2a5a55306a Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Mon, 31 Oct 2022 09:23:09 +0100 Subject: [PATCH 2/2] add tests for Fastlane changelogs including default.txt --- fdroidserver/update.py | 2 +- .../en-US/changelogs/default.txt | 1 + tests/update.TestCase | 46 +++++++++++++++++++ 3 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 tests/metadata/info.guardianproject.urzip/en-US/changelogs/default.txt diff --git a/fdroidserver/update.py b/fdroidserver/update.py index 1bf20530..a6c086ea 100644 --- a/fdroidserver/update.py +++ b/fdroidserver/update.py @@ -997,7 +997,7 @@ def insert_localized_app_metadata(apps): _set_localized_text_entry(apps[packageName], locale, 'whatsNew', os.path.join(root, f)) elif f == 'default.txt': - # use `default.txt` changelog entry as fallback. + # use "default.txt" changelog entry as fallback. localized = _get_localized_dict(apps[packageName], locale) if not localized.get('whatsNew', ''): _set_localized_text_entry(apps[packageName], locale, 'whatsNew', diff --git a/tests/metadata/info.guardianproject.urzip/en-US/changelogs/default.txt b/tests/metadata/info.guardianproject.urzip/en-US/changelogs/default.txt new file mode 100644 index 00000000..331d858c --- /dev/null +++ b/tests/metadata/info.guardianproject.urzip/en-US/changelogs/default.txt @@ -0,0 +1 @@ +default \ No newline at end of file diff --git a/tests/update.TestCase b/tests/update.TestCase index 59c1aac5..a46b0fb9 100755 --- a/tests/update.TestCase +++ b/tests/update.TestCase @@ -74,6 +74,7 @@ class UpdateTest(unittest.TestCase): def setUp(self): logging.basicConfig(level=logging.INFO) + logging.getLogger('androguard.apk').setLevel(logging.WARNING) logging.getLogger('androguard.axml').setLevel(logging.INFO) logging.getLogger('androguard.core.api_specific_resources').setLevel(logging.INFO) from PIL import PngImagePlugin @@ -212,6 +213,49 @@ class UpdateTest(unittest.TestCase): elif packageName == 'eu.siacs.conversations': self.assertEqual('Conversations', app['localized']['en-US']['name']) + def test_insert_fastlane_default_txt_changelog(self): + """Test that Fastlane's default.txt is handled properly + + https://docs.fastlane.tools/actions/supply/#changelogs-whats-new + """ + tmptestsdir = tempfile.mkdtemp( + prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir + ) + os.chdir(tmptestsdir) + + config = dict() + fdroidserver.common.fill_config_defaults(config) + fdroidserver.update.config = config + + app = fdroidserver.metadata.App() + app.id = 'com.example.app' + changelogs_dir = 'build/%s/metadata/en-US/changelogs' % app.id + os.makedirs(changelogs_dir) + with open(os.path.join(changelogs_dir, 'default.txt'), 'w') as fp: + fp.write('default') + with open(os.path.join(changelogs_dir, '42.txt'), 'w') as fp: + fp.write('42') + apps = {app.id: app} + build = fdroidserver.metadata.Build() + build.versionCode = 42 + app['Builds'] = [build] + + fdroidserver.update.insert_localized_app_metadata(apps) + self.assertEqual('default', apps[app.id]['localized']['en-US']['whatsNew']) + + app.CurrentVersionCode = 1 + fdroidserver.update.insert_localized_app_metadata(apps) + self.assertEqual('default', apps[app.id]['localized']['en-US']['whatsNew']) + + app.CurrentVersionCode = 10000 + fdroidserver.update.insert_localized_app_metadata(apps) + self.assertEqual('default', apps[app.id]['localized']['en-US']['whatsNew']) + + app.CurrentVersionCode = 42 + fdroidserver.update.insert_localized_app_metadata(apps) + self.assertEqual('42', apps[app.id]['localized']['en-US']['whatsNew']) + + def test_name_title_scraping(self): """metadata file --> fdroiddata localized files --> fastlane/triple-t in app source --> APK""" config = dict() @@ -225,6 +269,7 @@ class UpdateTest(unittest.TestCase): fdroidserver.update.options.delete_unknown = True apps = fdroidserver.metadata.read_metadata() + apps['info.guardianproject.urzip']['CurrentVersionCode'] = 100 knownapks = fdroidserver.common.KnownApks() apks, cachechanged = fdroidserver.update.process_apks({}, 'repo', knownapks, False) fdroidserver.update.insert_localized_app_metadata(apps) @@ -233,6 +278,7 @@ class UpdateTest(unittest.TestCase): self.assertIsNone(app.Name) self.assertTrue('localized' in app) self.assertEqual('title', app['localized']['en-US']['name']) + self.assertEqual('100\n', app['localized']['en-US']['whatsNew']) app = apps['org.videolan.vlc'] self.assertIsNone(app.Name) self.assertTrue('localized' in app)