From 57dc693b8efe1c3d67081de021895ef624a97e8c Mon Sep 17 00:00:00 2001 From: cheese3660 Date: Sat, 28 Oct 2023 18:13:51 -0400 Subject: [PATCH 1/2] Add aspect for detecting patch manager patches This adds an aspect to the aspects in the ModAnalyzer class that should detect patch manager patches (*.patch files), and automatically add the config tag, and a dependency on PatchManager --- netkan/netkan/mod_analyzer.py | 1 + 1 file changed, 1 insertion(+) diff --git a/netkan/netkan/mod_analyzer.py b/netkan/netkan/mod_analyzer.py index 65560d9..48945c8 100644 --- a/netkan/netkan/mod_analyzer.py +++ b/netkan/netkan/mod_analyzer.py @@ -69,6 +69,7 @@ class ModAnalyzer: FilenameAspect(r'swinfo\.json$', [], ['SpaceWarp']), FilenameAspect(r'\.dll$', ['plugin'], []), FilenameAspect(r'\.cfg$', ['config'], []), + FilenameAspect(r'\.patch$', ['config'], ['PatchManager']), ] FILTERS = [ '__MACOSX', '.DS_Store', From e79548a7847ec2bda7657bf0231a147faa648e48 Mon Sep 17 00:00:00 2001 From: Paul Hebble Date: Wed, 8 Nov 2023 18:03:58 -0600 Subject: [PATCH 2/2] Updates for dependency changes --- .vscode/settings.json | 11 ++--------- netkan/netkan/github_pr.py | 7 ++++--- netkan/setup.py | 2 +- netkan/tests/webhooks.py | 23 ++++++++++++++--------- 4 files changed, 21 insertions(+), 22 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 604e840..ea49c5a 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -2,14 +2,6 @@ "python.pythonPath": "/usr/bin/python3", "python.formatting.provider": "autopep8", "editor.formatOnSave": true, - "python.linting.pylintEnabled": true, - "python.linting.enabled": true, - "python.linting.pylintArgs": [ - "--rcfile", - "/home/netkan/workspace/.pylintrc" - ], - "python.linting.mypyEnabled": true, - "python.linting.pylintUseMinimalCheckers": false, "files.exclude": { "**/__pycache__": true }, @@ -18,5 +10,6 @@ "python.testing.unittestEnabled": false, "files.trimTrailingWhitespace": true, "files.insertFinalNewline": true, - "files.trimFinalNewlines": true + "files.trimFinalNewlines": true, + "mypy.configFile": "netkan/mypy.ini" } diff --git a/netkan/netkan/github_pr.py b/netkan/netkan/github_pr.py index 5769823..f087014 100644 --- a/netkan/netkan/github_pr.py +++ b/netkan/netkan/github_pr.py @@ -28,10 +28,11 @@ def repo(self) -> Repository: def default_branch(self) -> str: return self.repo.default_branch - def create_pull_request(self, title: str, branch: str, body: str, labels: Optional[List[str]] = None) -> None: + def create_pull_request(self, title: str, branch: str, body: str, + labels: Optional[List[str]] = None) -> None: try: - pull = self.repo.create_pull( - title, body, self.default_branch, branch) + pull = self.repo.create_pull(self.default_branch, branch, + title=title, body=body) logging.info('Pull request for %s opened at %s', branch, pull.html_url) diff --git a/netkan/setup.py b/netkan/setup.py index 5d353d8..9653780 100644 --- a/netkan/setup.py +++ b/netkan/setup.py @@ -24,7 +24,7 @@ 'jinja2', 'internetarchive!=3.0.1', 'gunicorn>=19.9,!=20.0.0', - 'discord.py>=1.6.0', + 'discord.py>=1.6.0,<=1.7.3', 'PyGithub', 'ruamel.yaml', ], diff --git a/netkan/tests/webhooks.py b/netkan/tests/webhooks.py index d0e8cdb..f5607a3 100644 --- a/netkan/tests/webhooks.py +++ b/netkan/tests/webhooks.py @@ -1,5 +1,6 @@ import os import sys +from typing import Mapping, Any, cast from unittest import mock, TestCase from unittest.mock import MagicMock @@ -121,7 +122,7 @@ def test_inflate_ksp_wrong_branch(self, sig: MagicMock): response = self.client.post( '/gh/inflate/ksp', json=data, follow_redirects=True) self.assertEqual(response.status_code, 200) - self.assertDictEqual(response.json, {'message': 'Wrong branch'}) + self.assertDictEqual(cast(Mapping[Any, object], response.json), {'message': 'Wrong branch'}) @mock.patch('netkan.webhooks.github_utils.sig_match') def test_inflate_ksp2_wrong_branch(self, sig: MagicMock): @@ -131,7 +132,7 @@ def test_inflate_ksp2_wrong_branch(self, sig: MagicMock): response = self.client.post( '/gh/inflate/ksp2', json=data, follow_redirects=True) self.assertEqual(response.status_code, 200) - self.assertDictEqual(response.json, {'message': 'Wrong branch'}) + self.assertDictEqual(cast(Mapping[Any, object], response.json), {'message': 'Wrong branch'}) @mock.patch('netkan.webhooks.github_utils.sig_match') def test_inflate_ksp_no_commits(self, sig: MagicMock): @@ -141,7 +142,8 @@ def test_inflate_ksp_no_commits(self, sig: MagicMock): response = self.client.post( '/gh/inflate/ksp', json=data, follow_redirects=True) self.assertEqual(response.status_code, 200) - self.assertDictEqual(response.json, {'message': 'No commits received'}) + self.assertDictEqual(cast(Mapping[Any, object], response.json), + {'message': 'No commits received'}) @mock.patch('netkan.webhooks.github_utils.sig_match') def test_inflate_ksp2_no_commits(self, sig: MagicMock): @@ -151,7 +153,8 @@ def test_inflate_ksp2_no_commits(self, sig: MagicMock): response = self.client.post( '/gh/inflate/ksp2', json=data, follow_redirects=True) self.assertEqual(response.status_code, 200) - self.assertDictEqual(response.json, {'message': 'No commits received'}) + self.assertDictEqual(cast(Mapping[Any, object], response.json), + {'message': 'No commits received'}) @mock.patch('netkan.status.ModStatus.get') @mock.patch('netkan.webhooks.github_utils.sig_match') @@ -251,7 +254,7 @@ def test_inflate_ksp_wrong_branch(self, sig: MagicMock): response = self.client.post( '/gh/mirror/ksp', json=data, follow_redirects=True) self.assertEqual(response.status_code, 200) - self.assertDictEqual(response.json, {'message': 'Wrong branch'}) + self.assertDictEqual(cast(Mapping[Any, object], response.json), {'message': 'Wrong branch'}) @mock.patch('netkan.webhooks.github_utils.sig_match') def test_inflate_ksp2_wrong_branch(self, sig: MagicMock): @@ -261,7 +264,7 @@ def test_inflate_ksp2_wrong_branch(self, sig: MagicMock): response = self.client.post( '/gh/mirror/ksp2', json=data, follow_redirects=True) self.assertEqual(response.status_code, 200) - self.assertDictEqual(response.json, {'message': 'Wrong branch'}) + self.assertDictEqual(cast(Mapping[Any, object], response.json), {'message': 'Wrong branch'}) @mock.patch('netkan.webhooks.github_utils.sig_match') def test_inflate_ksp_no_commits(self, sig: MagicMock): @@ -271,7 +274,8 @@ def test_inflate_ksp_no_commits(self, sig: MagicMock): response = self.client.post( '/gh/mirror/ksp', json=data, follow_redirects=True) self.assertEqual(response.status_code, 200) - self.assertDictEqual(response.json, {'message': 'No commits received'}) + self.assertDictEqual(cast(Mapping[Any, object], response.json), + {'message': 'No commits received'}) @mock.patch('netkan.webhooks.github_utils.sig_match') def test_inflate_ksp2_no_commits(self, sig: MagicMock): @@ -281,7 +285,8 @@ def test_inflate_ksp2_no_commits(self, sig: MagicMock): response = self.client.post( '/gh/mirror/ksp2', json=data, follow_redirects=True) self.assertEqual(response.status_code, 200) - self.assertDictEqual(response.json, {'message': 'No commits received'}) + self.assertDictEqual(cast(Mapping[Any, object], response.json), + {'message': 'No commits received'}) class TestWebhookInflate(WebhooksHarness): @@ -433,7 +438,7 @@ def setUp(self) -> None: @staticmethod def mock_netkan_hook() -> dict: return { - 'name: Mod Name Entered by the User on spacedock' + 'name': 'Mod Name Entered by the User on spacedock', 'id': '12345', 'license': 'GPL-3.0', 'username': 'modauthor1',