Skip to content

Commit

Permalink
Get SpaceDock co-authors from POST form lists
Browse files Browse the repository at this point in the history
  • Loading branch information
HebaruSan committed Apr 12, 2023
1 parent 7624ee4 commit 38aa44b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
10 changes: 1 addition & 9 deletions netkan/netkan/spacedock_adder.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,19 +84,11 @@ def try_add(self) -> bool:
@staticmethod
def _pr_body(info: Dict[str, Any]) -> str:
try:
shared_authors = info.get('shared_authors', [])
# It's supposed to be a list of dicts, SpaceDock has a bug right now where it's a string
bad_author = (not isinstance(shared_authors, list)
or any(not isinstance(auth, dict) for auth in shared_authors))
if bad_author:
logging.error('shared_authors should be list of dicts, is: %s', shared_authors)
return SpaceDockAdder.PR_BODY_TEMPLATE.safe_substitute(defaultdict(
lambda: '',
{**info,
'all_authors_md': ', '.join(SpaceDockAdder.USER_TEMPLATE.safe_substitute(defaultdict(lambda: '', a))
for a in ([info]
if bad_author else
[info, *info.get('shared_authors', [])]))}))
for a in info.get('all_authors', []))}))
except Exception as exc:
# Log the input on failure
logging.error('Failed to generate pull request body from %s', info)
Expand Down
20 changes: 17 additions & 3 deletions netkan/netkan/webhooks/spacedock_add.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from hashlib import md5
import json
from typing import Tuple, Dict, Any, TYPE_CHECKING
from typing import Tuple, TYPE_CHECKING
from flask import Blueprint, current_app, request
from werkzeug.datastructures import ImmutableMultiDict

from ..common import sqs_batch_entries
from .config import current_config
Expand Down Expand Up @@ -43,8 +44,21 @@ def add_hook(game_id: str) -> Tuple[str, int]:
return '', 204


def batch_message(raw: Dict[str, Any], game_id: str) -> SendMessageBatchRequestEntryTypeDef:
body = json.dumps(raw)
def batch_message(raw: 'ImmutableMultiDict[str, str]', game_id: str) -> SendMessageBatchRequestEntryTypeDef:
body = json.dumps({**raw,
# Turn the separate user property lists into a list of user dicts so JSON can encode it
# (the original properties will only have the first user)
'all_authors': [{'username': user_tuple[0],
'user_github': user_tuple[1],
'user_forum_id': user_tuple[2],
'user_forum_username': user_tuple[3],
'email': user_tuple[4]}
for user_tuple
in zip(raw.getlist('username'),
raw.getlist('user_github'),
raw.getlist('user_forum_id'),
raw.getlist('user_forum_username'),
raw.getlist('email'))]})
return {
'Id': '1',
'MessageBody': body,
Expand Down

0 comments on commit 38aa44b

Please sign in to comment.