Skip to content

Commit

Permalink
Render replies differently than annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
mtomilov committed Dec 10, 2024
1 parent cd86af9 commit c0f2834
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 33 deletions.
33 changes: 22 additions & 11 deletions src/slack_annotations/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,28 @@ def _build_annotation_summary(annotation: dict[str, Any]) -> str:


def _build_annotation_fields(annotation: dict[str, Any]) -> list[dict[str, Any]]:
quote = None
try:
quote = _get_quote(annotation)
except Exception: # pylint:disable=broad-exception-caught
quote = NONE_TEXT

return [
{"type": "mrkdwn", "text": "*Quote:*"},
{
"type": "mrkdwn",
"text": f"*Annotation* (<{annotation['links']['incontext']}|in-context link>):",
},
{"type": "plain_text", "text": quote},
{"type": "plain_text", "text": _get_text(annotation)},
]
pass
incontext_link = annotation["links"]["incontext"]

if annotation.get("references"):
fields = [
{
"type": "mrkdwn",
"text": f"*Reply* (<{incontext_link}|in-context link>):",
},
]
else:
fields = [
{"type": "mrkdwn", "text": "*Quote:*"},
{
"type": "mrkdwn",
"text": f"*Annotation* (<{incontext_link}|in-context link>):",
},
{"type": "plain_text", "text": quote or NONE_TEXT},
]
fields.append({"type": "plain_text", "text": _get_text(annotation)})
return fields
69 changes: 47 additions & 22 deletions tests/unit/slack_annotations/format_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,27 +41,52 @@ def test_format_empty_annotations():
assert not format_annotations([])


def test_format_annotation_without_title():
annotation = {
"user": "acct:[email protected]",
"uri": "https://example.com/",
"links": {"incontext": "https://hyp.is/test_annotation_id_1/example.com/"},
"user_info": {"display_name": "md............................"},
}

assert _format_annotation(annotation) == {
"type": "section",
"text": {
"type": "mrkdwn",
"text": "`test_user_1` (md............................) annotated https://example.com/:",
},
"fields": [
{"type": "mrkdwn", "text": "*Quote:*"},
{
class TestFormatAnnotation:
def test_without_title(self):
annotation = {
"user": "acct:[email protected]",
"uri": "https://example.com/",
"links": {"incontext": "https://hyp.is/test_annotation_id_1/example.com/"},
"user_info": {"display_name": "md............................"},
}

assert _format_annotation(annotation) == {
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*Annotation* (<https://hyp.is/test_annotation_id_1/example.com/|in-context link>):",
"text": "`test_user_1` (md............................) annotated https://example.com/:",
},
{"type": "plain_text", "text": "(None)"},
{"type": "plain_text", "text": "(None)"},
],
}
"fields": [
{"type": "mrkdwn", "text": "*Quote:*"},
{
"type": "mrkdwn",
"text": "*Annotation* (<https://hyp.is/test_annotation_id_1/example.com/|in-context link>):",
},
{"type": "plain_text", "text": "(None)"},
{"type": "plain_text", "text": "(None)"},
],
}

def test_reply(self):
annotation = {
"user": "acct:[email protected]",
"uri": "https://example.com/",
"links": {"incontext": "https://hyp.is/test_annotation_id_1/example.com/"},
"user_info": {"display_name": None},
"references": ["test_annotation_id_2"],
}

assert _format_annotation(annotation) == {
"type": "section",
"text": {
"type": "mrkdwn",
"text": "`test_user_1` (None) annotated https://example.com/:",
},
"fields": [
{
"type": "mrkdwn",
"text": "*Reply* (<https://hyp.is/test_annotation_id_1/example.com/|in-context link>):",
},
{"type": "plain_text", "text": "(None)"},
],
}

0 comments on commit c0f2834

Please sign in to comment.