misc: apply double-quote-string-fixer (#79788)
This commit is contained in:
parent
bc7a7a62f3
commit
78c5b1677f
|
@ -7,11 +7,11 @@ import flask
|
|||
import redminelib
|
||||
|
||||
logging.basicConfig(
|
||||
level=logging.INFO, format="%(asctime)s [%(levelname)s] %(message)s", handlers=[logging.StreamHandler()]
|
||||
level=logging.INFO, format='%(asctime)s [%(levelname)s] %(message)s', handlers=[logging.StreamHandler()]
|
||||
)
|
||||
INCOMING_WEBHOOK_SECRET = os.environ["INCOMING_WEBHOOK_SECRET"]
|
||||
REDMINE_URL = os.environ["REDMINE_URL"]
|
||||
REDMINE_API_KEY = os.environ["REDMINE_API_KEY"]
|
||||
INCOMING_WEBHOOK_SECRET = os.environ['INCOMING_WEBHOOK_SECRET']
|
||||
REDMINE_URL = os.environ['REDMINE_URL']
|
||||
REDMINE_API_KEY = os.environ['REDMINE_API_KEY']
|
||||
|
||||
REDMINE_CLIENT = redminelib.Redmine(REDMINE_URL, key=REDMINE_API_KEY, raise_attr_exception=False)
|
||||
REDMINE_ASSIGNABLE_GROUP = int(os.environ.get('REDMINE_ASSIGNABLE_GROUP', 21))
|
||||
|
@ -45,7 +45,7 @@ REDMINE_TRACKERS = {
|
|||
app = flask.Flask(__name__)
|
||||
|
||||
|
||||
@app.route("/incoming-webhook/<token>", methods=['POST'])
|
||||
@app.route('/incoming-webhook/<token>', methods=['POST'])
|
||||
def incoming_webhook(token):
|
||||
if token != INCOMING_WEBHOOK_SECRET:
|
||||
logging.warning('Received invalid token')
|
||||
|
@ -232,7 +232,7 @@ def save():
|
|||
|
||||
def skip_if_not_draft(issue, payload):
|
||||
if not payload['pull_request_title'].lower().startswith('wip:'):
|
||||
raise Abort("Not a WIP: PR")
|
||||
raise Abort('Not a WIP: PR')
|
||||
|
||||
|
||||
def skip_if_notes_include(field, reason):
|
||||
|
|
330
test_app.py
330
test_app.py
|
@ -33,12 +33,12 @@ def client():
|
|||
'pull_request.edited',
|
||||
),
|
||||
(
|
||||
{'action': 'reviewed', 'review': {"type": "pull_request_review_approved"}},
|
||||
{'action': 'reviewed', 'review': {'type': 'pull_request_review_approved'}},
|
||||
gitea_redmine.handle_pull_request_approved,
|
||||
'pull_request.approved',
|
||||
),
|
||||
(
|
||||
{'action': 'reviewed', 'review': {"type": "pull_request_review_rejected"}},
|
||||
{'action': 'reviewed', 'review': {'type': 'pull_request_review_rejected'}},
|
||||
gitea_redmine.handle_pull_request_rejected,
|
||||
'pull_request.rejected',
|
||||
),
|
||||
|
@ -101,21 +101,21 @@ def test_handle_pull_request_opened(current_tracker_id, expected_tracker_id, moc
|
|||
get_redmine_user = mocker.patch.object(gitea_redmine, 'get_redmine_user', return_value=redmine_user)
|
||||
|
||||
payload = {
|
||||
"action": "opened",
|
||||
"number": 2,
|
||||
"pull_request": {
|
||||
"id": 7,
|
||||
"url": "https://gitea.entrouvert.org/entrouvert/gitea-redmine/pulls/2",
|
||||
"number": 2,
|
||||
"user": {
|
||||
"id": 7,
|
||||
"login": "testuser",
|
||||
"full_name": "Test User",
|
||||
"email": "test_user@noreply.gitea.entrouvert.org",
|
||||
"username": "testuser",
|
||||
'action': 'opened',
|
||||
'number': 2,
|
||||
'pull_request': {
|
||||
'id': 7,
|
||||
'url': 'https://gitea.entrouvert.org/entrouvert/gitea-redmine/pulls/2',
|
||||
'number': 2,
|
||||
'user': {
|
||||
'id': 7,
|
||||
'login': 'testuser',
|
||||
'full_name': 'Test User',
|
||||
'email': 'test_user@noreply.gitea.entrouvert.org',
|
||||
'username': 'testuser',
|
||||
},
|
||||
"title": "Foo",
|
||||
"body": "See #70893",
|
||||
'title': 'Foo',
|
||||
'body': 'See #70893',
|
||||
},
|
||||
}
|
||||
project = mocker.Mock()
|
||||
|
@ -151,21 +151,21 @@ def test_handle_pull_request_opened_skips_closed_statuses(status, mocker):
|
|||
get_redmine_user = mocker.patch.object(gitea_redmine, 'get_redmine_user', return_value=redmine_user)
|
||||
|
||||
payload = {
|
||||
"action": "opened",
|
||||
"number": 2,
|
||||
"pull_request": {
|
||||
"id": 7,
|
||||
"url": "https://gitea.entrouvert.org/entrouvert/gitea-redmine/pulls/2",
|
||||
"number": 2,
|
||||
"user": {
|
||||
"id": 7,
|
||||
"login": "testuser",
|
||||
"full_name": "Test User",
|
||||
"email": "test_user@noreply.gitea.entrouvert.org",
|
||||
"username": "testuser",
|
||||
'action': 'opened',
|
||||
'number': 2,
|
||||
'pull_request': {
|
||||
'id': 7,
|
||||
'url': 'https://gitea.entrouvert.org/entrouvert/gitea-redmine/pulls/2',
|
||||
'number': 2,
|
||||
'user': {
|
||||
'id': 7,
|
||||
'login': 'testuser',
|
||||
'full_name': 'Test User',
|
||||
'email': 'test_user@noreply.gitea.entrouvert.org',
|
||||
'username': 'testuser',
|
||||
},
|
||||
"title": "Foo",
|
||||
"body": "See #70893",
|
||||
'title': 'Foo',
|
||||
'body': 'See #70893',
|
||||
},
|
||||
}
|
||||
project = mocker.Mock()
|
||||
|
@ -182,21 +182,21 @@ def test_handle_pull_request_edited(mocker):
|
|||
get_redmine_user = mocker.patch.object(gitea_redmine, 'get_redmine_user', return_value=redmine_user)
|
||||
|
||||
payload = {
|
||||
"action": "edited",
|
||||
"number": 2,
|
||||
"pull_request": {
|
||||
"id": 7,
|
||||
"url": "https://gitea.entrouvert.org/entrouvert/gitea-redmine/pulls/2",
|
||||
"number": 2,
|
||||
"user": {
|
||||
"id": 7,
|
||||
"login": "testuser",
|
||||
"full_name": "Test User",
|
||||
"email": "test_user@noreply.gitea.entrouvert.org",
|
||||
"username": "testuser",
|
||||
'action': 'edited',
|
||||
'number': 2,
|
||||
'pull_request': {
|
||||
'id': 7,
|
||||
'url': 'https://gitea.entrouvert.org/entrouvert/gitea-redmine/pulls/2',
|
||||
'number': 2,
|
||||
'user': {
|
||||
'id': 7,
|
||||
'login': 'testuser',
|
||||
'full_name': 'Test User',
|
||||
'email': 'test_user@noreply.gitea.entrouvert.org',
|
||||
'username': 'testuser',
|
||||
},
|
||||
"title": "Foo",
|
||||
"body": "See #70893",
|
||||
'title': 'Foo',
|
||||
'body': 'See #70893',
|
||||
},
|
||||
}
|
||||
project = mocker.Mock()
|
||||
|
@ -223,21 +223,21 @@ def test_handle_pull_request_edited_wip_removal(mocker):
|
|||
get_redmine_user = mocker.patch.object(gitea_redmine, 'get_redmine_user', return_value=redmine_user)
|
||||
|
||||
payload = {
|
||||
"action": "opened",
|
||||
"number": 2,
|
||||
"pull_request": {
|
||||
"id": 7,
|
||||
"url": "https://gitea.entrouvert.org/entrouvert/gitea-redmine/pulls/2",
|
||||
"number": 2,
|
||||
"user": {
|
||||
"id": 7,
|
||||
"login": "testuser",
|
||||
"full_name": "Test User",
|
||||
"email": "test_user@noreply.gitea.entrouvert.org",
|
||||
"username": "testuser",
|
||||
'action': 'opened',
|
||||
'number': 2,
|
||||
'pull_request': {
|
||||
'id': 7,
|
||||
'url': 'https://gitea.entrouvert.org/entrouvert/gitea-redmine/pulls/2',
|
||||
'number': 2,
|
||||
'user': {
|
||||
'id': 7,
|
||||
'login': 'testuser',
|
||||
'full_name': 'Test User',
|
||||
'email': 'test_user@noreply.gitea.entrouvert.org',
|
||||
'username': 'testuser',
|
||||
},
|
||||
"title": "WIP: Foo",
|
||||
"body": "...",
|
||||
'title': 'WIP: Foo',
|
||||
'body': '...',
|
||||
},
|
||||
}
|
||||
project = mocker.Mock()
|
||||
|
@ -269,21 +269,21 @@ def test_handle_pull_request_edited_wip_removal(mocker):
|
|||
|
||||
def test_handle_pull_request_draft(mocker):
|
||||
payload = {
|
||||
"action": "edited",
|
||||
"number": 2,
|
||||
"pull_request": {
|
||||
"id": 7,
|
||||
"url": "https://gitea.entrouvert.org/entrouvert/gitea-redmine/pulls/2",
|
||||
"number": 2,
|
||||
"user": {
|
||||
"id": 7,
|
||||
"login": "testuser",
|
||||
"full_name": "Test User",
|
||||
"email": "test_user@noreply.gitea.entrouvert.org",
|
||||
"username": "testuser",
|
||||
'action': 'edited',
|
||||
'number': 2,
|
||||
'pull_request': {
|
||||
'id': 7,
|
||||
'url': 'https://gitea.entrouvert.org/entrouvert/gitea-redmine/pulls/2',
|
||||
'number': 2,
|
||||
'user': {
|
||||
'id': 7,
|
||||
'login': 'testuser',
|
||||
'full_name': 'Test User',
|
||||
'email': 'test_user@noreply.gitea.entrouvert.org',
|
||||
'username': 'testuser',
|
||||
},
|
||||
"title": "WIP: Foo",
|
||||
"body": "See #70893",
|
||||
'title': 'WIP: Foo',
|
||||
'body': 'See #70893',
|
||||
},
|
||||
}
|
||||
project = mocker.Mock()
|
||||
|
@ -304,10 +304,10 @@ def test_handle_pull_request_draft(mocker):
|
|||
|
||||
def test_handle_pull_request_edited_already_linked_does_nothing(mocker):
|
||||
payload = {
|
||||
"action": "edited",
|
||||
"pull_request": {
|
||||
"url": "https://gitea.entrouvert.org/entrouvert/gitea-redmine/pulls/2",
|
||||
"title": "Foo",
|
||||
'action': 'edited',
|
||||
'pull_request': {
|
||||
'url': 'https://gitea.entrouvert.org/entrouvert/gitea-redmine/pulls/2',
|
||||
'title': 'Foo',
|
||||
},
|
||||
}
|
||||
project = mocker.Mock()
|
||||
|
@ -324,24 +324,24 @@ def test_handle_pull_request_edited_already_linked_does_nothing(mocker):
|
|||
|
||||
def test_handle_pull_request_reviewed_approved(mocker):
|
||||
payload = {
|
||||
"action": "reviewed",
|
||||
"number": 2,
|
||||
"pull_request": {
|
||||
"id": 7,
|
||||
"url": "https://gitea.entrouvert.org/entrouvert/gitea-redmine/pulls/2",
|
||||
"number": 2,
|
||||
"title": "Foo",
|
||||
"body": "See #70893",
|
||||
"merged": True,
|
||||
'action': 'reviewed',
|
||||
'number': 2,
|
||||
'pull_request': {
|
||||
'id': 7,
|
||||
'url': 'https://gitea.entrouvert.org/entrouvert/gitea-redmine/pulls/2',
|
||||
'number': 2,
|
||||
'title': 'Foo',
|
||||
'body': 'See #70893',
|
||||
'merged': True,
|
||||
},
|
||||
"sender": {
|
||||
"id": 7,
|
||||
"login": "testuser",
|
||||
"full_name": "Test User",
|
||||
"email": "test_user@noreply.gitea.entrouvert.org",
|
||||
"username": "testuser",
|
||||
'sender': {
|
||||
'id': 7,
|
||||
'login': 'testuser',
|
||||
'full_name': 'Test User',
|
||||
'email': 'test_user@noreply.gitea.entrouvert.org',
|
||||
'username': 'testuser',
|
||||
},
|
||||
"review": {"type": "pull_request_review_approved", "content": "Okay pour moi"},
|
||||
'review': {'type': 'pull_request_review_approved', 'content': 'Okay pour moi'},
|
||||
}
|
||||
project = mocker.Mock()
|
||||
project.parent = None
|
||||
|
@ -360,24 +360,24 @@ def test_handle_pull_request_reviewed_approved(mocker):
|
|||
|
||||
def test_handle_pull_request_reviewed_rejected(mocker):
|
||||
payload = {
|
||||
"action": "reviewed",
|
||||
"number": 2,
|
||||
"pull_request": {
|
||||
"id": 7,
|
||||
"url": "https://gitea.entrouvert.org/entrouvert/gitea-redmine/pulls/2",
|
||||
"number": 2,
|
||||
"title": "Foo",
|
||||
"body": "See #70893",
|
||||
"merged": True,
|
||||
'action': 'reviewed',
|
||||
'number': 2,
|
||||
'pull_request': {
|
||||
'id': 7,
|
||||
'url': 'https://gitea.entrouvert.org/entrouvert/gitea-redmine/pulls/2',
|
||||
'number': 2,
|
||||
'title': 'Foo',
|
||||
'body': 'See #70893',
|
||||
'merged': True,
|
||||
},
|
||||
"sender": {
|
||||
"id": 7,
|
||||
"login": "testuser",
|
||||
"full_name": "Test User",
|
||||
"email": "test_user@noreply.gitea.entrouvert.org",
|
||||
"username": "testuser",
|
||||
'sender': {
|
||||
'id': 7,
|
||||
'login': 'testuser',
|
||||
'full_name': 'Test User',
|
||||
'email': 'test_user@noreply.gitea.entrouvert.org',
|
||||
'username': 'testuser',
|
||||
},
|
||||
"review": {"type": "pull_request_review_rejected", "content": "Des choses à changer"},
|
||||
'review': {'type': 'pull_request_review_rejected', 'content': 'Des choses à changer'},
|
||||
}
|
||||
project = mocker.Mock()
|
||||
project.parent = None
|
||||
|
@ -396,51 +396,51 @@ def test_handle_pull_request_reviewed_rejected(mocker):
|
|||
|
||||
def test_handle_pull_request_reviewed_approved_already_approved(mocker):
|
||||
payload = {
|
||||
"action": "reviewed",
|
||||
"number": 2,
|
||||
"pull_request": {
|
||||
"id": 7,
|
||||
"url": "https://gitea.entrouvert.org/entrouvert/gitea-redmine/pulls/2",
|
||||
"number": 2,
|
||||
"title": "Foo",
|
||||
"body": "See #70893",
|
||||
"merged": True,
|
||||
'action': 'reviewed',
|
||||
'number': 2,
|
||||
'pull_request': {
|
||||
'id': 7,
|
||||
'url': 'https://gitea.entrouvert.org/entrouvert/gitea-redmine/pulls/2',
|
||||
'number': 2,
|
||||
'title': 'Foo',
|
||||
'body': 'See #70893',
|
||||
'merged': True,
|
||||
},
|
||||
"sender": {
|
||||
"id": 7,
|
||||
"login": "testuser",
|
||||
"full_name": "Test User",
|
||||
"email": "test_user@noreply.gitea.entrouvert.org",
|
||||
"username": "testuser",
|
||||
'sender': {
|
||||
'id': 7,
|
||||
'login': 'testuser',
|
||||
'full_name': 'Test User',
|
||||
'email': 'test_user@noreply.gitea.entrouvert.org',
|
||||
'username': 'testuser',
|
||||
},
|
||||
"review": {"type": "pull_request_review_approved", "content": ""},
|
||||
'review': {'type': 'pull_request_review_approved', 'content': ''},
|
||||
}
|
||||
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()
|
||||
|
||||
|
||||
def test_handle_pull_request_merged(mocker):
|
||||
payload = {
|
||||
"action": "closed",
|
||||
"number": 2,
|
||||
"pull_request": {
|
||||
"id": 7,
|
||||
"url": "https://gitea.entrouvert.org/entrouvert/gitea-redmine/pulls/2",
|
||||
"number": 2,
|
||||
"title": "Foo",
|
||||
"body": "See #70893",
|
||||
"merged": True,
|
||||
'action': 'closed',
|
||||
'number': 2,
|
||||
'pull_request': {
|
||||
'id': 7,
|
||||
'url': 'https://gitea.entrouvert.org/entrouvert/gitea-redmine/pulls/2',
|
||||
'number': 2,
|
||||
'title': 'Foo',
|
||||
'body': 'See #70893',
|
||||
'merged': True,
|
||||
},
|
||||
"sender": {
|
||||
"id": 7,
|
||||
"login": "testuser",
|
||||
"full_name": "Test User",
|
||||
"email": "test_user@noreply.gitea.entrouvert.org",
|
||||
"username": "testuser",
|
||||
'sender': {
|
||||
'id': 7,
|
||||
'login': 'testuser',
|
||||
'full_name': 'Test User',
|
||||
'email': 'test_user@noreply.gitea.entrouvert.org',
|
||||
'username': 'testuser',
|
||||
},
|
||||
}
|
||||
project = mocker.Mock()
|
||||
|
@ -475,11 +475,11 @@ def test_incoming_webhook_requires_secret(client):
|
|||
|
||||
def test_incoming_webhook_ignore_hotfix_branch(client):
|
||||
payload = {
|
||||
"action": "opened",
|
||||
"pull_request": {
|
||||
"title": "WIP: Foo",
|
||||
"head": {
|
||||
"ref": "hotfix/1",
|
||||
'action': 'opened',
|
||||
'pull_request': {
|
||||
'title': 'WIP: Foo',
|
||||
'head': {
|
||||
'ref': 'hotfix/1',
|
||||
},
|
||||
},
|
||||
}
|
||||
|
@ -506,11 +506,11 @@ def test_incoming_webhook_calls_proper_handler(client, mocker):
|
|||
get_handler = mocker.patch.object(gitea_redmine, 'get_handler', return_value=[mocker.Mock(), 'foo'])
|
||||
|
||||
payload = {
|
||||
"action": "foo",
|
||||
"pull_request": {
|
||||
"title": "Fix #1234",
|
||||
"body": "And this was caused by #5678 that should not be referenced",
|
||||
"head": {"ref": "wip/9100-something"},
|
||||
'action': 'foo',
|
||||
'pull_request': {
|
||||
'title': 'Fix #1234',
|
||||
'body': 'And this was caused by #5678 that should not be referenced',
|
||||
'head': {'ref': 'wip/9100-something'},
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -581,22 +581,22 @@ def test_excluded_project_parent_false(mocker):
|
|||
|
||||
def test_handle_pull_request_closed(mocker):
|
||||
payload = {
|
||||
"action": "closed",
|
||||
"number": 2,
|
||||
"pull_request": {
|
||||
"id": 7,
|
||||
"url": "https://gitea.entrouvert.org/entrouvert/gitea-redmine/pulls/2",
|
||||
"number": 2,
|
||||
"title": "Foo",
|
||||
"body": "See #70893",
|
||||
"merged": False,
|
||||
'action': 'closed',
|
||||
'number': 2,
|
||||
'pull_request': {
|
||||
'id': 7,
|
||||
'url': 'https://gitea.entrouvert.org/entrouvert/gitea-redmine/pulls/2',
|
||||
'number': 2,
|
||||
'title': 'Foo',
|
||||
'body': 'See #70893',
|
||||
'merged': False,
|
||||
},
|
||||
"sender": {
|
||||
"id": 7,
|
||||
"login": "testuser",
|
||||
"full_name": "Test User",
|
||||
"email": "test_user@noreply.gitea.entrouvert.org",
|
||||
"username": "testuser",
|
||||
'sender': {
|
||||
'id': 7,
|
||||
'login': 'testuser',
|
||||
'full_name': 'Test User',
|
||||
'email': 'test_user@noreply.gitea.entrouvert.org',
|
||||
'username': 'testuser',
|
||||
},
|
||||
}
|
||||
project = mocker.Mock()
|
||||
|
|
Loading…
Reference in New Issue