Skip to content

Commit f5b9540

Browse files
committed
Release summary
1 parent 8b16dac commit f5b9540

File tree

3 files changed

+63
-1
lines changed

3 files changed

+63
-1
lines changed

IoTuring/Entity/Deployments/AppInfo/AppInfo.py

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
NO_REMOTE_INSTALL_AVAILABLE_MSG = "<b>⚠️ Currently the Install process cannot be started from HomeAssistant. Please update it manually. ⚠️</b>"
1818

19+
UPDATE_RELEASE_SUMMARY_MAX_CHARS = 255
20+
1921
class AppInfo(Entity):
2022
NAME = "AppInfo"
2123

@@ -76,9 +78,48 @@ def UpdateCommandCustomPayload(self):
7678
"title": App.getName(),
7779
"name": App.getName(),
7880
"release_url": App.getUrlReleases(),
79-
"release_summary": NO_REMOTE_INSTALL_AVAILABLE_MSG,
81+
"release_summary": + self.getReleaseNotes()
8082
}
8183

84+
def getReleaseNotes(self):
85+
release_notes = NO_REMOTE_INSTALL_AVAILABLE_MSG + "<br><ul>"
86+
notes = App.crawlReleaseNotes().split("\n")
87+
notes = ["<li>" + note + "</li>" for note in notes if len(note) > 0]
88+
# Sort by length
89+
notes.sort(key=len)
90+
list_end = "</ul>"
91+
cannot_complete_msg = "<li>...</li>"
92+
93+
# Append the list to the release notes until we have space
94+
# If no space, append "...": take into account that we can't place a note if then the next note is too long and
95+
# also there wouldn't be space for the "..."
96+
noteI = 0
97+
end = False
98+
while noteI < len(notes) and not end:
99+
# Last note: don't need to take into account the possibility of adding "..."
100+
if noteI == len(notes) - 1:
101+
if len(release_notes) + len(notes[noteI]) + len(list_end) <= UPDATE_RELEASE_SUMMARY_MAX_CHARS:
102+
release_notes += notes[noteI]
103+
else:
104+
release_notes += cannot_complete_msg
105+
else: # not last note: can I add it ? If I add it, will I be able to add "..." if I won't be able to add the next note ?
106+
if len(release_notes) + len(notes[noteI]) + len(notes[noteI + 1]) + len(list_end) <= UPDATE_RELEASE_SUMMARY_MAX_CHARS:
107+
# Both this and next note can be added -> free to add this
108+
release_notes += notes[noteI]
109+
else:
110+
# The next note can't be added but the three dots can (and so also this note) -> Free to add this
111+
if len(release_notes) + len(notes[noteI]) + len(cannot_complete_msg) + len(list_end) <= UPDATE_RELEASE_SUMMARY_MAX_CHARS:
112+
release_notes += notes[noteI]
113+
else:
114+
# The three dots can't be added -> end
115+
release_notes += cannot_complete_msg
116+
end = True
117+
noteI += 1
118+
119+
120+
release_notes += list_end
121+
return release_notes
122+
82123
def versionToInt(version: str):
83124
return int(''.join([i for i in version if i.isdigit()]))
84125

IoTuring/MyApp/App.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from importlib.metadata import metadata
22
from pathlib import Path
3+
import requests
4+
from bs4 import BeautifulSoup
35

46
class App():
57
METADATA = metadata('IoTuring')
@@ -50,6 +52,24 @@ def getRootPath() -> Path:
5052
"""
5153
return Path(__file__).parents[1]
5254

55+
@staticmethod
56+
def crawlReleaseNotes() -> str:
57+
"""Crawl the release notes from the Release page """
58+
try:
59+
res = requests.get(App.getUrlReleases())
60+
if res.status_code == 200:
61+
soup = BeautifulSoup(res.text, 'html.parser')
62+
# take the last release release notes
63+
release_notes = soup.find('div', class_='markdown-body')
64+
if release_notes:
65+
release_notes = release_notes.text.split("Changelog")[1]
66+
release_notes = release_notes.split("Commits")[0]
67+
return release_notes.strip()
68+
except Exception as e:
69+
return "Error fetching release notes"
70+
return "No release notes found"
71+
72+
5373
def __str__(self) -> str:
5474
msg = ""
5575
msg += "Name: " + App.getName() + "\n"

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ dependencies = [
2727
"PyYAML",
2828
"requests",
2929
"InquirerPy",
30+
"beautifulsoup4",
3031
"PyObjC; sys_platform == 'darwin'",
3132
"IoTuring-applesmc; sys_platform == 'darwin'",
3233
"tinyWinToast; sys_platform == 'win32'"

0 commit comments

Comments
 (0)