misc: apply pre-commit tools (#74039)
gitea-wip/gitea-redmine/pipeline/pr-main This commit looks good Details
gitea/gitea-redmine/pipeline/head This commit looks good Details

This commit is contained in:
Frédéric Péters 2023-01-31 19:27:59 +01:00
parent c3bc4d5356
commit 71ff56b6a9
3 changed files with 21 additions and 34 deletions

View File

@ -17,11 +17,7 @@ REDMINE_API_KEY = os.environ["REDMINE_API_KEY"]
REDMINE_CLIENT = redminelib.Redmine(REDMINE_URL, key=REDMINE_API_KEY)
REDMINE_ASSIGNABLE_GROUP = int(os.environ.get('REDMINE_ASSIGNABLE_GROUP', 21))
REDMINE_EXCLUDED_PROJECTS = [
i.strip()
for i in os.environ.get(
'REDMINE_EXCLUDED_PROJECTS',
'projets-clients'
).split(',')
i.strip() for i in os.environ.get('REDMINE_EXCLUDED_PROJECTS', 'projets-clients').split(',')
]
REDMINE_STATUSES = {
@ -138,7 +134,6 @@ def get_redmine_issue(id):
return REDMINE_CLIENT.issue.get(id, includes=['journals'])
def get_redmine_project(id):
return REDMINE_CLIENT.project.get(id)
@ -246,22 +241,19 @@ def set_value_if_empty(field, value):
return inner
PULL_REQUEST_OPENED_NOTE = '{pull_request_user_full_name} ({pull_request_user_username}) a ouvert une pull request sur Gitea concernant cette demande :\n\n* URL : {pull_request_url}\n* Titre : {pull_request_title}\n* Modifications : {pull_request_url}/files'
handle_pull_request_opened = make_handler(
assign_to('pull_request_user_username'),
set_status(REDMINE_STATUSES['Solution proposée'], unless=CLOSED_STATUSES),
add_note(
PULL_REQUEST_OPENED_NOTE
),
add_note(PULL_REQUEST_OPENED_NOTE),
save(),
)
handle_pull_request_opened_draft = make_handler(
assign_to('pull_request_user_username'),
set_status(REDMINE_STATUSES['En cours'], unless=CLOSED_STATUSES),
add_note(
PULL_REQUEST_OPENED_NOTE
),
add_note(PULL_REQUEST_OPENED_NOTE),
save(),
)

View File

@ -1,6 +1,5 @@
import os
import subprocess
from distutils.command.sdist import sdist
from setuptools import find_packages, setup
@ -45,8 +44,6 @@ def get_version():
return '0.0'
setup(
name='gitea_redmine',
version=get_version(),

View File

@ -121,13 +121,15 @@ def test_handle_pull_request_opened(mocker):
issue.save.assert_called_once()
@pytest.mark.parametrize('status', [
gitea_redmine.REDMINE_STATUSES['Résolu'],
gitea_redmine.REDMINE_STATUSES['Fermé'],
gitea_redmine.REDMINE_STATUSES['Solution déployée'],
gitea_redmine.REDMINE_STATUSES['Rejeté'],
])
@pytest.mark.parametrize(
'status',
[
gitea_redmine.REDMINE_STATUSES['Résolu'],
gitea_redmine.REDMINE_STATUSES['Fermé'],
gitea_redmine.REDMINE_STATUSES['Solution déployée'],
gitea_redmine.REDMINE_STATUSES['Rejeté'],
],
)
def test_handle_pull_request_opened_skips_closed_statuses(status, mocker):
redmine_user = mocker.Mock(id=42)
get_redmine_user = mocker.patch.object(gitea_redmine, 'get_redmine_user', return_value=redmine_user)
@ -157,7 +159,7 @@ def test_handle_pull_request_opened_skips_closed_statuses(status, mocker):
gitea_redmine.handle_pull_request_opened(issue, payload, project)
assert issue.status_id == original_status
def test_handle_pull_request_edited(mocker):
redmine_user = mocker.Mock(id=42)
@ -347,9 +349,7 @@ def test_handle_pull_request_reviewed_approved_already_approved(mocker):
project = project = mocker.Mock()
project.parent = None
issue = mocker.Mock(
status=mocker.Mock(id=gitea_redmine.REDMINE_STATUSES["Solution validée"])
)
issue = mocker.Mock(status=mocker.Mock(id=gitea_redmine.REDMINE_STATUSES["Solution validée"]))
gitea_redmine.handle_pull_request_approved(issue, payload, project)
issue.save.assert_not_called()
@ -409,7 +409,9 @@ def test_incoming_webhook_calls_proper_handler(client, mocker):
issue1 = mocker.Mock(journals=[], project=project)
issue2 = mocker.Mock(journals=[], project=project)
issue3 = mocker.Mock(journals=[], project=project)
get_redmine_issue = mocker.patch.object(gitea_redmine, 'get_redmine_issue', side_effect=[issue1, issue2, issue3])
get_redmine_issue = mocker.patch.object(
gitea_redmine, 'get_redmine_issue', side_effect=[issue1, issue2, issue3]
)
get_redmine_project = mocker.patch.object(gitea_redmine, 'get_redmine_project', return_value=project)
get_handler = mocker.patch.object(gitea_redmine, 'get_handler', return_value=[mocker.Mock(), 'foo'])
@ -419,9 +421,7 @@ def test_incoming_webhook_calls_proper_handler(client, mocker):
"pull_request": {
"title": "Fix #1234",
"body": "And this was caused by #5678 that should not be referenced",
"head": {
"ref": "wip/9100-something"
}
"head": {"ref": "wip/9100-something"},
},
}
@ -450,9 +450,7 @@ def test_make_handler_ignore_excluded_projects(mocker):
issue = mocker.Mock()
project = mocker.Mock()
is_excluded_project = mocker.patch.object(gitea_redmine, 'is_excluded_project', return_value=True)
handler = gitea_redmine.make_handler(
f1
)
handler = gitea_redmine.make_handler(f1)
handler(issue, {}, project)
f1.assert_not_called()
@ -476,7 +474,7 @@ def test_excluded_project_parent_true(mocker):
mocker.patch.object(gitea_redmine, 'REDMINE_EXCLUDED_PROJECTS', ['parent'])
parent = mocker.Mock(identifier='parent', id=12)
get_redmine_project = mocker.patch.object(gitea_redmine, 'get_redmine_project', return_value=parent)
project = mocker.Mock(identifier='project')
project.parent = parent
assert gitea_redmine.is_excluded_project(project) is True