From 0fa88c5c205d083f742d0e800b55ad0ba289c5d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20P=C3=B6hn?= Date: Tue, 11 Jun 2024 12:24:36 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=87=20implement=20review=20nits?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Implement review nits as requested bei @eighthave in https://gitlab.com/fdroid/fdroidserver/-/merge_requests/1471 --- examples/config.yml | 9 ++++----- fdroidserver/deploy.py | 33 +++++++++++++++++++-------------- fdroidserver/github.py | 5 ++++- tests/deploy.TestCase | 29 +++++++++++++++++------------ 4 files changed, 44 insertions(+), 32 deletions(-) diff --git a/examples/config.yml b/examples/config.yml index 45c9a2f7..f15c00da 100644 --- a/examples/config.yml +++ b/examples/config.yml @@ -231,16 +231,15 @@ # # github_token: {env: GITHUB_TOKEN} # github_releases: -# - repo: f-droid/fdroidclient -# packages: +# - projectUrl: https://github.com/f-droid/fdroidclient +# packageNames: # - org.fdroid.basic # - org.fdroid.fdroid # release_notes_prepend: | # Re-post of official F-Droid App release from https://f-droid.org -# - repo: example/app +# - projectUrl: https://github.com/example/app +# packageNames: com.example.app # token: {env: GITHUB_TOKEN_EXAMPLE} -# packages: -# - com.example.app # Most git hosting services have hard size limits for each git repo. diff --git a/fdroidserver/deploy.py b/fdroidserver/deploy.py index 4ca7dca9..8d2b5dca 100644 --- a/fdroidserver/deploy.py +++ b/fdroidserver/deploy.py @@ -1167,7 +1167,7 @@ def upload_to_github_releases(repo_section, gh_config, global_gh_token): package_names = [] for repo_conf in gh_config: - for package_name in repo_conf.get('packages', []): + for package_name in repo_conf.get('packageNames', []): package_names.append(package_name) release_infos = fdroidserver.deploy.find_release_infos( @@ -1179,12 +1179,12 @@ def upload_to_github_releases(repo_section, gh_config, global_gh_token): def upload_to_github_releases_repo(repo_conf, release_infos, global_gh_token): - repo = repo_conf.get("repo") - if not repo: + projectUrl = repo_conf.get("projectUrl") + if not projectUrl: logging.warning( _( "One of the 'github_releases' config items is missing the " - "'repo' value. skipping ..." + "'projectUrl' value. skipping ..." ) ) return @@ -1197,12 +1197,14 @@ def upload_to_github_releases_repo(repo_conf, release_infos, global_gh_token): ) ) return - packages = repo_conf.get("packages", []) - if not packages: + conf_package_names = repo_conf.get("packageNames", []) + if type(conf_package_names) == str: + conf_package_names = [conf_package_names] + if not conf_package_names: logging.warning( _( "One of the 'github_releases' config itmes is missing the " - "'packages' value. skipping ..." + "'packageNames' value. skipping ..." ) ) return @@ -1210,11 +1212,11 @@ def upload_to_github_releases_repo(repo_conf, release_infos, global_gh_token): # lookup all versionNames (git tags) for all packages available in the # local fdroid repo all_local_versions = set() - for package_name in repo_conf['packages']: + for package_name in conf_package_names: for version in release_infos.get(package_name, {}).keys(): all_local_versions.add(version) - gh = fdroidserver.github.GithubApi(token, repo) + gh = fdroidserver.github.GithubApi(token, projectUrl) unreleased_tags = gh.list_unreleased_tags() for version in all_local_versions: @@ -1223,20 +1225,22 @@ def upload_to_github_releases_repo(repo_conf, release_infos, global_gh_token): # is set. (releaseChannels usually mean it's e.g. an alpha or beta # version) if ( - not release_infos.get(packages[0], {}) + not release_infos.get(conf_package_names[0], {}) .get(version, {}) .get('hasReleaseChannels') ): # collect files associated with this github release files = [] - for package in packages: + for package in conf_package_names: files.extend( release_infos.get(package, {}).get(version, {}).get('files', []) ) # always use the whatsNew text from the first app listed in - # config.qml github_releases.packages + # config.yml github_releases.packageNames text = ( - release_infos.get(packages[0], {}).get(version, {}).get('whatsNew') + release_infos.get(conf_package_names[0], {}) + .get(version, {}) + .get('whatsNew') or '' ) if 'release_notes_prepend' in repo_conf: @@ -1330,7 +1334,8 @@ def main(): logging.warning( _('No option set! Edit your config.yml to set at least one of these:') + '\nserverwebroot, servergitmirrors, local_copy_dir, awsbucket, ' - + 'virustotal_apikey, androidobservatory, or binary_transparency_remote' + + 'virustotal_apikey, androidobservatory, github_releases ' + + 'or binary_transparency_remote' ) sys.exit(1) diff --git a/fdroidserver/github.py b/fdroidserver/github.py index d72e9bb0..c522f522 100644 --- a/fdroidserver/github.py +++ b/fdroidserver/github.py @@ -33,7 +33,10 @@ class GithubApi: def __init__(self, api_token, repo_path): self._api_token = api_token - self._repo_path = repo_path + if repo_path.startswith("https://github.com/"): + self._repo_path = repo_path[19:] + else: + self._repo_path = repo_path def _req(self, url, data=None): h = { diff --git a/tests/deploy.TestCase b/tests/deploy.TestCase index 2db73a02..3d45625d 100755 --- a/tests/deploy.TestCase +++ b/tests/deploy.TestCase @@ -1313,12 +1313,12 @@ class GitHubReleasesTest(unittest.TestCase): def test_upload_to_github_releases(self): gh_config = [ { - "repo": "example/app", - "packages": ["com.example.app", "another.app"], + "projectUrl": "https://github.com/example/app", + "packageNames": ["com.example.app", "another.app"], }, { - "repo": "custom/app", - "packages": ["more.custom.app"], + "projectUrl": "https://github.com/custom/app", + "packageNames": ["more.custom.app"], "token": "custom_token", }, ] @@ -1343,21 +1343,22 @@ class GitHubReleasesTest(unittest.TestCase): ["com.example.app", "another.app", "more.custom.app"], ) + self.maxDiff = None self.assertListEqual( urr_mock.call_args_list, [ unittest.mock.call( { - "repo": "example/app", - "packages": ["com.example.app", "another.app"], + "projectUrl": "https://github.com/example/app", + "packageNames": ["com.example.app", "another.app"], }, "fri_result", "fake_global_token", ), unittest.mock.call( { - "repo": "custom/app", - "packages": ["more.custom.app"], + "projectUrl": "https://github.com/custom/app", + "packageNames": ["more.custom.app"], "token": "custom_token", }, "fri_result", @@ -1370,8 +1371,8 @@ class GitHubReleasesTest(unittest.TestCase): class Test_UploadToGithubReleasesRepo(unittest.TestCase): def setUp(self): self.repo_conf = { - "repo": "example/app", - "packages": ["com.example.app", "com.example.altapp", "another.app"], + "projectUrl": "https://github.com/example/app", + "packageNames": ["com.example.app", "com.example.altapp", "another.app"], } self.release_infos = { "com.example.app": { @@ -1414,7 +1415,9 @@ class Test_UploadToGithubReleasesRepo(unittest.TestCase): "global_token", ) - self.api_constructor.assert_called_once_with("global_token", "example/app") + self.api_constructor.assert_called_once_with( + "global_token", "https://github.com/example/app" + ) self.assertListEqual( self.api.create_release.call_args_list, @@ -1441,7 +1444,9 @@ class Test_UploadToGithubReleasesRepo(unittest.TestCase): "global_token", ) - self.api_constructor.assert_called_once_with("local_token", "example/app") + self.api_constructor.assert_called_once_with( + "local_token", "https://github.com/example/app" + ) self.assertListEqual( self.api.create_release.call_args_list,