Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Aspect to ModAnalyzer to detect patch manager patches #317

Merged
merged 2 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
Expand All @@ -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"
}
7 changes: 4 additions & 3 deletions netkan/netkan/github_pr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
1 change: 1 addition & 0 deletions netkan/netkan/mod_analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion netkan/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
],
Expand Down
23 changes: 14 additions & 9 deletions netkan/tests/webhooks.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import sys
from typing import Mapping, Any, cast

from unittest import mock, TestCase
from unittest.mock import MagicMock
Expand Down Expand Up @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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')
Expand Down Expand Up @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand Down Expand Up @@ -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',
Expand Down
Loading