Skip to content

Commit

Permalink
Sonar fixes (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
djpugh authored Dec 27, 2023
1 parent 27c890f commit 75c88ca
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 15 deletions.
1 change: 1 addition & 0 deletions .github/workflows/pipeline.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ jobs:
-Dsonar.projectKey=djpugh_mkdocs_github_changelog
-Dsonar.organization=djpugh
-Dsonar.coverage.exclusions=**/*.*
-Dsonar.sources=src
# No coverage as handled separately

license-scan:
Expand Down
7 changes: 4 additions & 3 deletions src/mkdocs_github_changelog/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
def __get_version() -> str:
"""Get version information or return default if unable to do so."""
# Default
version = '0+unknown'
default_version = '0+unknown'
version = default_version
# Development installation only
try:
# Look here for setuptools scm to update the version - for development environments only
Expand All @@ -20,13 +21,13 @@ def __get_version() -> str:
pass
# Development installation without setuptools_scm or installed package
# try loading from file
if version == '0+unknown':
if version == default_version:
try:
from mkdocs_github_changelog._version import __version__ # noqa: F401
except ImportError:
pass
# Development installation without setuptools_scm
if version == '0+unknown':
if version == default_version:
# Use the metadata
import sys
if sys.version_info.major >= 3 and sys.version_info.minor >= 8:
Expand Down
1 change: 0 additions & 1 deletion src/mkdocs_github_changelog/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ def run(self, parent: Element, blocks: MutableSequence[str]) -> None:
# insert it back into the blocks to be processed as markdown
block = self._process_block(match.groupdict()['org'], match.groupdict()['repo'], block, heading_level)
blocks.insert(0, block)
return False

def _process_block(
self,
Expand Down
35 changes: 24 additions & 11 deletions src/mkdocs_github_changelog/get_releases.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ def autoprocess_github_links(release):
base_url = release.html_url.split('releases')[0]
# We also want to parse this to get the
root_url = '/'.join(base_url.split('/')[:-3])
user_re = '@[a-zA-Z0-9-]+'
issue_re = '#[0-9]+'
user_re = r'@[a-zA-Z\d-]+'
issue_re = r'#[\d]+'

def github_user_link(match_obj):
user_name = match_obj.string[match_obj.start(): match_obj.end()]
Expand All @@ -93,15 +93,7 @@ def github_issue_link(match_obj):
return release


def get_releases_as_markdown(organisation_or_user: str, repository: str, token: str | None = None, release_template: str | None = RELEASE_TEMPLATE, github_api_url: str | None = None, match: str | None = None, autoprocess: bool | None = True):
"""Get the releases from github as a list of rendered markdown strings."""
if github_api_url is not None:
github_api_url = github_api_url.rstrip('/')
api = GhApi(token=token, gh_host=github_api_url)
releases = []
for page in paged(api.repos.list_releases, organisation_or_user, repository, per_page=100):
releases += page
jinja_environment = JINJA_ENVIRONMENT_FACTORY.environment
def _process_releases(releases, match: str | None = None, autoprocess: bool = True):
selected_releases = []
for release in releases:
# Convert the published_at to datetime object
Expand All @@ -114,6 +106,27 @@ def get_releases_as_markdown(organisation_or_user: str, repository: str, token:
autoprocess_github_links(release)
if (match and re.match(match, release.name) is not None) or not match:
selected_releases.append(release)
return selected_releases


def get_releases_as_markdown(
organisation_or_user: str,
repository: str,
token: str | None = None,
release_template: str | None = RELEASE_TEMPLATE,
github_api_url: str | None = None,
match: str | None = None,
autoprocess: bool | None = True
):
"""Get the releases from github as a list of rendered markdown strings."""
if github_api_url is not None:
github_api_url = github_api_url.rstrip('/')
api = GhApi(token=token, gh_host=github_api_url)
releases = []
for page in paged(api.repos.list_releases, organisation_or_user, repository, per_page=100):
releases += page
jinja_environment = JINJA_ENVIRONMENT_FACTORY.environment
selected_releases = _process_releases(releases, match=match, autoprocess=autoprocess)
if release_template is None:
release_template = RELEASE_TEMPLATE
return [jinja_environment.from_string(release_template).render(release=release) for release in selected_releases]

0 comments on commit 75c88ca

Please sign in to comment.