Skip to content

Commit

Permalink
Adding include_prereleases flag and ignoring draft releases
Browse files Browse the repository at this point in the history
  • Loading branch information
djpugh committed Jan 7, 2025
1 parent ce13c2c commit d8b3d60
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
3 changes: 3 additions & 0 deletions docs/source/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ plugins:
# Regex string for matching the release name.
autoprocess: True
# Autoprocess the body for user and issue/pull request links
include_prereleases: False
# Include prereleases
enabled: True
# Enable or disable the plugin.
```
Expand All @@ -50,6 +52,7 @@ markdown
github_api_url: <url>
release_template: <jinja2 str>
match: '[0-9+].[0-9+].[0-9]+'
include_prereleases: false
autoprocess: true
```

Expand Down
12 changes: 9 additions & 3 deletions src/mkdocs_github_changelog/get_releases.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,14 @@ def github_issue_link(match_obj):
return release


def _process_releases(releases, match: str | None = None, autoprocess: bool = True):
def _process_releases(releases, match: str | None = None, autoprocess: bool = True, include_prerelease: bool = False):
selected_releases = []
for release in releases:
# Ignore draft releases:
if release.draft:
continue
if release.prelease and not include_prerelease:
continue
# Convert the published_at to datetime object
if not isinstance(release.published_at, datetime):
if sys.version_info.major >= 3 and sys.version_info.minor < 11:
Expand All @@ -118,7 +123,8 @@ def get_releases_as_markdown(
release_template: str | None = RELEASE_TEMPLATE,
github_api_url: str | None = None,
match: str | None = None,
autoprocess: bool | None = True
autoprocess: bool | None = True,
include_prerelease: bool | None = False
):
"""Get the releases from github as a list of rendered markdown strings."""
if github_api_url is not None:
Expand All @@ -130,7 +136,7 @@ def get_releases_as_markdown(
releases += page
logger.info(f'Processing releases from github, {len(releases)} found')
jinja_environment = JINJA_ENVIRONMENT_FACTORY.environment
selected_releases = _process_releases(releases, match=match, autoprocess=autoprocess)
selected_releases = _process_releases(releases, match=match, autoprocess=autoprocess, include_prerelease=include_prerelease)
if release_template is None:
release_template = RELEASE_TEMPLATE
logger.info(f'Rendering releases from github, {len(releases)} selected')
Expand Down
2 changes: 2 additions & 0 deletions src/mkdocs_github_changelog/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class PluginConfig(Config):
"""Regex string for matching the rleease name."""
autoprocess = opt.Type(bool, default=True)
"""Autoprocess the release bodies for issue and username links."""
include_prereleases = opt.Type(bool, default=False)
"""Include prereleases."""
enabled = opt.Type(bool, default=True)
"""Enable or disable the plugin."""

Expand Down

0 comments on commit d8b3d60

Please sign in to comment.