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 emote processing #8

Merged
merged 3 commits into from
Nov 12, 2024
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
4 changes: 2 additions & 2 deletions .github/workflows/action-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ jobs:
steps:
- name: Run action
id: test-action
uses: ynput/github-query@generate-changelog
uses: ynput/github-query@add-icons
with:
repo: "ynput/ayon-addon-action-testing"
date: "2024-08-20T12:03:23Z"
query_parameters: "body,labels,title,number,url,id"
changelog_labels: "feature,enhancement,bugfix,refactor,docs,test,pr"
changelog_labels: "feature(🎉),enhancement(💚),bugfix(🐛),refactor,docs,test,pr"

- name: Show results
run: |
Expand Down
34 changes: 29 additions & 5 deletions src/conversion_logic.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
import re
import unicodedata

from typing import NamedTuple, List

Expand Down Expand Up @@ -167,14 +168,16 @@ def format_changelog_markdown(changes: List[Changelog], changelog_label_list: Li
change_label_list: set[str] = {label for change in changes for label in change.labels}

for label in changelog_label_list:
if label not in change_label_list:
filtered_label: str = filter_emote(label)

if filtered_label not in change_label_list:
continue

formatted_label: str = label.removeprefix("type: ").capitalize()
changelog += f"\n### **{formatted_label}**\n\n"
formatted_label: str = format_label(label)
changelog += f"\n### {formatted_label}\n\n"

for change in changes:
if label in change.labels:
if filtered_label in change.labels:
changelog += f"<details>\n"
changelog += f"<summary>{change.title} - <a href=\"{change.url}\")>#{change.number}</a></summary>\n\n"

Expand All @@ -188,4 +191,25 @@ def format_changelog_markdown(changes: List[Changelog], changelog_label_list: Li
changelog += f"\n___\n\n"
changelog += f"</details>\n"

return changelog
return changelog

def filter_emote(text: str) -> str:
emojis: List[str] = [char for char in text if unicodedata.category(char) == 'So']

if emojis:
return text.split("(")[0]

return text

def format_label(text: str) -> str:
emojis: List[str] = [char for char in text if unicodedata.category(char) == 'So']

if not text:
return ""

if emojis:
label: str = text.split("(")[0]

return f"{emojis[0]} **{label.removeprefix('type: ').capitalize()}**"

return f"**{text.removeprefix('type: ').capitalize()}**"
2 changes: 1 addition & 1 deletion tests/formatted_changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ ___

</details>

### **Bug**
### **Bugfix**

<details>
<summary>AY-6654 Look: Fix None values in collecting and applying attributes - <a href="https://github.com/ynput/ayon-maya/pull/89")>#89</a></summary>
Expand Down
83 changes: 83 additions & 0 deletions tests/formatted_changelog_icons.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# Changelog

### 💚 **Enhancement**

<details>
<summary>Improve applying render resolution and aspect ratio on render settings reset - <a href="https://github.com/ynput/ayon-maya/pull/75")>#75</a></summary>


Fix pixel aspect ratio / device aspect ratio getting messed up for Arnold renderer on render settings reset.

Additionally:
- This now applies the resolution from the task entity, not the folder entity.
- This now also applies pixel aspect ratio as defined on the entity.

___

</details>
<details>
<summary>Validate unique names only within the instance not in full scene - <a href="https://github.com/ynput/ayon-maya/pull/70")>#70</a></summary>


Validate unique names only within the instance not in full scene

___

</details>

### 🐛 **Bugfix**

<details>
<summary>AY-6654 Look: Fix None values in collecting and applying attributes - <a href="https://github.com/ynput/ayon-maya/pull/89")>#89</a></summary>


This fixes a case where looks failed to apply due to `None` values being present in the collected attributes.
These will now be ignored in collected. There's an edge case where Maya returns `None` for string attributes that have no values set - those are captured now explicitly to just `""` to still collect and apply them later.

Existing looks will now also apply correctly with `None` value in their look attributes, but the attributes with `None` values will be ignored with a warning.

___

</details>
<details>
<summary>Fix settings for Maya USD Animation Extractor - <a href="https://github.com/ynput/ayon-maya/pull/77")>#77</a></summary>


Fix name in settings to match with name of plug-in to ensure settings are actually applied

___

</details>
<details>
<summary>Improve applying render resolution and aspect ratio on render settings reset - <a href="https://github.com/ynput/ayon-maya/pull/75")>#75</a></summary>


Fix pixel aspect ratio / device aspect ratio getting messed up for Arnold renderer on render settings reset.

Additionally:
- This now applies the resolution from the task entity, not the folder entity.
- This now also applies pixel aspect ratio as defined on the entity.

___

</details>
<details>
<summary>Maya Scene exports do not default to including nodes that not children of members - <a href="https://github.com/ynput/ayon-maya/pull/71")>#71</a></summary>


On Maya scene exports only include the relevant history for the selected nodes downstream and upstream and not upstream, and also their downstream descendant children.

___

</details>

### **Maintenance**

<details>
<summary>Skip extraction of active view for automatic tests - <a href="https://github.com/ynput/ayon-maya/pull/126")>#126</a></summary>

It seems that Maya UI is not completely visible or shutting down, `view.readColorBuffer` causes RuntimeError: (kFailure): Unexpected Internal Failure aas view is not visible.

___

</details>
8 changes: 4 additions & 4 deletions tests/merged_pr_query.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"labels": [
{
"id": "LA_kwDOMQ8b8s8AAAABqmH60w",
"name": "type: bug",
"name": "type: bugfix",
"description": "Something isn't working",
"color": "FFA696"
},
Expand All @@ -56,7 +56,7 @@
"labels": [
{
"id": "LA_kwDOMQ8b8s8AAAABqmH60w",
"name": "type: bug",
"name": "type: bugfix",
"description": "Something isn't working",
"color": "FFA696"
}
Expand All @@ -71,7 +71,7 @@
"labels": [
{
"id": "LA_kwDOMQ8b8s8AAAABqmH60w",
"name": "type: bug",
"name": "type: bugfix",
"description": "Something isn't working",
"color": "FFA696"
},
Expand All @@ -98,7 +98,7 @@
"labels": [
{
"id": "LA_kwDOMQ8b8s8AAAABqmH60w",
"name": "type: bug",
"name": "type: bugfix",
"description": "Something isn't working",
"color": "FFA696"
}
Expand Down
64 changes: 58 additions & 6 deletions tests/test_github_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ def changelog_markdown() -> str:
with open("formatted_changelog.md") as file:
return file.read()

@pytest.fixture
def changelog_markdown_icons() -> str:
with open("formatted_changelog_icons.md") as file:
return file.read()

@pytest.fixture
def changelog_body() -> str:
with open("changelog.md") as file:
Expand Down Expand Up @@ -86,12 +91,24 @@ def csv_string_no_comma() -> Literal['bugfix']:
return "bugfix"

@pytest.fixture
def csv_string_empty() -> Literal['']:
def empty_string() -> str:
return ""

@pytest.fixture
def changelog_label_list() -> list[str]:
return ["type: enhancement", "type: bug", "type: maintenance"]
return ["type: enhancement", "type: bugfix", "type: maintenance"]

@pytest.fixture
def label_with_emote() -> str:
return "type: bugfix(🐛)"

@pytest.fixture
def label_type_prefix() -> str:
return "type: bugfix"

@pytest.fixture
def changelog_label_list_icons() -> list[str]:
return ["feature(🎉)", "type: enhancement(💚)", "type: bugfix(🐛)", "type: maintenance"]

@pytest.fixture
def changelog_exclude_label_list() -> List[str]:
Expand Down Expand Up @@ -132,9 +149,9 @@ def test_csv_string_to_list_no_comma(csv_string_no_comma: Literal['bugfix']) ->

assert string_list == ["bugfix"]

def test_csv_string_to_list_empty(csv_string_empty: Literal['']) -> None:
string_list: List[str] = conversion_logic.csv_string_to_list(csv_string_empty)
string_list: List[str] = conversion_logic.csv_string_to_list(csv_string_empty)
def test_csv_string_to_list_empty(empty_string: Literal['']) -> None:
string_list: List[str] = conversion_logic.csv_string_to_list(empty_string)
string_list: List[str] = conversion_logic.csv_string_to_list(empty_string)

assert string_list == []

Expand Down Expand Up @@ -222,11 +239,46 @@ def test_format_changelog_markdown(merged_pr_samples: List[dict[str, str]], chan
filtered_pr_list: List[conversion_logic.Changelog] = conversion_logic.filter_changes_per_label(pr_data=merged_pr_samples, changelog_label_list=changelog_label_list)
changelog_result: str = conversion_logic.format_changelog_markdown(changes=filtered_pr_list, changelog_label_list=changelog_label_list)

print(changelog_result)
assert changelog_result == changelog_markdown

def test_format_changelog_markdown_no_data(changelog_label_list: List[str]) -> None:
filtered_pr_list: List[conversion_logic.Changelog] = conversion_logic.filter_changes_per_label(pr_data=[], changelog_label_list=changelog_label_list)
changelog_result: str = conversion_logic.format_changelog_markdown(changes=filtered_pr_list, changelog_label_list=changelog_label_list)

assert changelog_result == "# Changelog\n"

def test_filter_emote(label_with_emote: str) -> None:
filter_result: str = conversion_logic.filter_emote(text=label_with_emote)

assert filter_result == "type: bugfix"

def test_filter_emote_no_emote(label_type_prefix: str) -> None:
filter_result: str = conversion_logic.filter_emote(text=label_type_prefix)

assert filter_result == "type: bugfix"

def test_filter_emote_empty(empty_string: str) -> None:
filter_result: str = conversion_logic.filter_emote(text=empty_string)

assert filter_result == ""

def test_format_label_emote(label_with_emote: str) -> None:
formatted_label: str = conversion_logic.format_label(text=label_with_emote)

assert formatted_label == "🐛 **Bugfix**"

def test_format_label_empty(empty_string: str) -> None:
formatted_label: str = conversion_logic.format_label(text=empty_string)

assert formatted_label == ""

def test_format_label(label_type_prefix: str) -> None:
formatted_label: str = conversion_logic.format_label(text=label_type_prefix)

assert formatted_label == "**Bugfix**"

def test_format_changelog_markdown_icons(merged_pr_samples: List[dict[str, str]], changelog_label_list_icons: List[str], changelog_markdown_icons: str) -> None:
filtered_pr_list: List[conversion_logic.Changelog] = conversion_logic.filter_changes_per_label(pr_data=merged_pr_samples, changelog_label_list=changelog_label_list_icons)
changelog_result: str = conversion_logic.format_changelog_markdown(changes=filtered_pr_list, changelog_label_list=changelog_label_list_icons)

assert changelog_result == changelog_markdown_icons