Branch: refs/heads/master
Author: Enrico Tröger <enrico.troeger(a)uvena.de>
Committer: Enrico Tröger <enrico.troeger(a)uvena.de>
Date: Wed, 01 May 2019 12:33:25 UTC
Commit: fc112eab784990ab8cd427fee8e9937b96d1822b
https://github.com/geany/www.geany.org/commit/fc112eab784990ab8cd427fee8e99…
Log Message:
-----------
Render the release notes to Markdown before displaying
This looks better and more integrated instead of displaying
a <pre> block which is rendered as code block.
Modified Paths:
--------------
static_docs/templates/pages/documentation/releasenotes.html
static_docs/views.py
Modified: static_docs/templates/pages/documentation/releasenotes.html
4 lines changed, 1 insertions(+), 3 deletions(-)
===================================================================
@@ -6,9 +6,7 @@
<h2>Geany {{ selected_release.version }} ({{ selected_release.release_date }})</h2>
-<pre>
-{{ selected_release.release_notes }}
-</pre>
+{{ selected_release.release_notes|safe }}
<h3>Older Releases</h3>
<div class="row">
Modified: static_docs/views.py
12 lines changed, 11 insertions(+), 1 deletions(-)
===================================================================
@@ -21,6 +21,7 @@
from django.conf import settings
from django.http import Http404
from django.views.generic.base import TemplateView
+from mezzanine_pagedown.filters import plain as markdown_plain
from geany.decorators import cache_function, CACHE_TIMEOUT_1HOUR, CACHE_TIMEOUT_24HOURS
from static_docs.github_client import GitHubApiClient
@@ -86,6 +87,9 @@ def get_context_data(self, **kwargs):
# use the first element in the list which is the latest
release = releases[0]
+ # convert the selected release (the one we want to display) to Markdown
+ release.release_notes = markdown_plain(release.release_notes)
+
context = super(ReleaseNotesView, self).get_context_data(**kwargs)
context['selected_release'] = release
context['releases'] = releases
@@ -119,7 +123,13 @@ def _parse_news_file(self):
releases.append(current_release)
current_release_notes = list()
else:
- current_release_notes.append(line)
+ line = line.lstrip() # remove any indentation
+ if line and not line.startswith('*'):
+ # we got a section: make it bold and add an additional new line
+ # to make Markdown recognise the following lines as list
+ current_release_notes.append('**{}**\n'.format(line))
+ else:
+ current_release_notes.append(line)
# compress the lines of the last release (the for loop ends before)
current_release.release_notes = '\n'.join(current_release_notes)
--------------
This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).
Branch: refs/heads/master
Author: Enrico Tröger <enrico.troeger(a)uvena.de>
Committer: Enrico Tröger <enrico.troeger(a)uvena.de>
Date: Wed, 01 May 2019 12:33:25 UTC
Commit: efbdab7096b5fc0f6c91860d4e17f0efb913f999
https://github.com/geany/www.geany.org/commit/efbdab7096b5fc0f6c91860d4e17f…
Log Message:
-----------
Try to read release notes from Github releases
This gets us already pretty Markdown with issue/PR links.
If no Github release is found, fallback to our already
parsed NEWS file content.
Modified Paths:
--------------
static_docs/github_client.py
static_docs/views.py
Modified: static_docs/github_client.py
27 lines changed, 26 insertions(+), 1 deletions(-)
===================================================================
@@ -12,7 +12,6 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-# try to get any json implementation
from base64 import standard_b64decode
import logging
@@ -58,3 +57,29 @@ def _parse_fetch_file_response(self, response_json):
content_utf8 = standard_b64decode(content)
return content_utf8.decode('utf-8')
return content
+
+ # ----------------------------------------------------------------------
+ def get_release_by_tag(self, tag_name):
+ url = 'https://api.github.com/repos/{user}/{repository}/releases/tags/{tag_name}'.format(
+ user=GITHUB_USER,
+ repository=GITHUB_REPOSITORY,
+ tag_name=tag_name)
+ with requests.get(url, timeout=HTTP_REQUEST_TIMEOUT, stream=False) as response:
+ response_json = response.json()
+ self._log_rate_limit(response)
+
+ if response.status_code == 404:
+ return None
+
+ return response_json
+
+ # ----------------------------------------------------------------------
+ def get_latest_release(self):
+ url = 'https://api.github.com/repos/{user}/{repository}/releases/latest'.format(
+ user=GITHUB_USER,
+ repository=GITHUB_REPOSITORY)
+ with requests.get(url, timeout=HTTP_REQUEST_TIMEOUT, stream=False) as response:
+ response_json = response.json()
+ self._log_rate_limit(response)
+
+ return response_json
Modified: static_docs/views.py
75 lines changed, 60 insertions(+), 15 deletions(-)
===================================================================
@@ -74,21 +74,7 @@ def get_context_data(self, **kwargs):
release = None
version = kwargs.get('version', None)
- if version is not None:
- # search for the requested release in the list (we could index the list into a
- # dictionary but we need the index only at this point)
- for rel in releases:
- if rel.version == version:
- release = rel
- break
- else:
- raise Http404()
- else:
- # use the first element in the list which is the latest
- release = releases[0]
-
- # convert the selected release (the one we want to display) to Markdown
- release.release_notes = markdown_plain(release.release_notes)
+ release = self._get_release_notes_for_version(releases, version=version)
context = super(ReleaseNotesView, self).get_context_data(**kwargs)
context['selected_release'] = release
@@ -147,6 +133,65 @@ def _parse_release_line(self, line):
logger.warning('Failed parsing NEWS file: release line "%s" invalid', line)
return None, None
+ # ----------------------------------------------------------------------
+ def _get_release_notes_for_version(self, releases, version=None):
+ """
+ If version is None: fetch the latest release from Github
+ If version is not None:
+ - check if the requested version has a release on Github and if it has release notes,
+ use it
+ - otherwise fetch the release notes from the already parsed NEWS file
+
+ Finally convert the release notes from Markdown.
+ """
+ if version is None:
+ release = self._get_release_from_github(version=None)
+ else:
+ # first search the release on Github
+ release = self._get_release_from_github(version=version)
+ if release is None:
+ # fallback to the NEWS file release notes
+ for rel in releases:
+ if rel.version == version:
+ release = rel
+ break
+ else:
+ raise Http404()
+
+ # convert the selected release (the one we want to display) to Markdown
+ release.release_notes = markdown_plain(release.release_notes)
+ return release
+
+ # ----------------------------------------------------------------------
+ @cache_function(CACHE_TIMEOUT_24HOURS)
+ def _get_release_from_github(self, version=None):
+ client = GitHubApiClient()
+ if version is None:
+ github_release = client.get_latest_release()
+ else:
+ tag_name = self._convert_version_to_tag_name(version)
+ github_release = client.get_release_by_tag(tag_name)
+
+ if github_release is None:
+ return None
+
+ # adapt date
+ release_datetime = datetime.strptime(github_release['published_at'], '%Y-%m-%dT%H:%M:%SZ')
+ release_date = release_datetime.strftime('%B %d, %Y')
+
+ release = ReleaseDto()
+ release.version = github_release['tag_name']
+ release.release_date = release_date
+ release.release_notes = github_release['body']
+ return release
+
+ # ----------------------------------------------------------------------
+ def _convert_version_to_tag_name(self, version):
+ if version.count('.') == 1:
+ return '{}.0'.format(version)
+
+ return version
+
class ToDoView(StaticDocsView):
"""
--------------
This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).