ewjoachim / sphinx-github-changelog

Build a sphinx changelog from GitHub Releases
https://sphinx-github-changelog.readthedocs.io
MIT License
27 stars 4 forks source link

use of substitutions doesn't appear to be supported? #137

Open jrouly opened 2 months ago

jrouly commented 2 months ago

I have the following substitutions defined in my rst_prolog in conf.py:

rst_prolog = f"""
.. |repo_link| replace:: {repo_link}
"""

where the repo_link is set from an environment variable. I want to use this in my index.rst as below:

Changelog
---------

.. changelog::
    :github: |repo_link|/releases/

but it seems like the literal string |repo_link| is what's getting processed by the sphinx-github-changelog extension, rather than the substituted value coming in from rst_prolog/rst_epilog.

I'm a pretty new sphinx/rst user, so not really sure where to go from here.

ewjoachim commented 2 months ago

Hm, I've never used the substitution, and I don't have a large experience in sphinx, so it's hard to say. I don't know if it's a good idea to make it work that way: the idea of requesting the user to put the link this way is so that if we display this page on GitHub (where it won't be processed by Sphinx), there's at least a usable link to the changelog source.

An alternative would be to allow removing the link altogether and set the default value for all changelog elements in conf.py. This way, you wouldn't have to use your substitution.

This would require a PR to the project.

jrouly commented 2 months ago

@ewjoachim I ended up coming to a similar conclusion. My implementation (which ended up working) is to specialize the directive provided by this plugin to allow for programmatic specification of the changelog elements (specifically the GitHub URL).

from sphinx_github_changelog.changelog import ChangelogDirective

# Set the GitHub Token from the environment so the extension can pull the latest releases.
repo_link = os.environ.get("WHATEVER", "no-repo-link")

# Customize the extension directive so the repo link can be pulled from the environment, rather than from static RST.
class CustomChangelogDirective(ChangelogDirective):
    def run(self):
        self.options["github"] = f"{repo_link}/releases"
        return super().run()

def setup(app):
    # Override the Sphinx GitHub Changelog directive with our customized directive.
    app.add_directive("changelog", CustomChangelogDirective)
Changelog
---------

.. changelog::
jrouly commented 2 months ago

I agree a PR could be contributed to this project to allow the directive to read options programmatically or via RST out of the box, without requiring downstream specialization.

ewjoachim commented 2 months ago

I agree a PR could be contributed to this project

Would you be interested in crafting such a PR ? :D