From a9794b73cec766e01bee35a96f7d44e22851f278 Mon Sep 17 00:00:00 2001 From: Anton Akhmerov Date: Mon, 3 Jul 2023 14:28:02 +0200 Subject: [PATCH] add support for gitlab issue button (#740) * add support for gitlab issue button * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * update tests --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- src/sphinx_book_theme/header_buttons/source.py | 12 ++++++++---- tests/test_build.py | 2 +- tests/test_build/header__source-buttons--gitlab.html | 2 ++ .../header__source-buttons--gitlab_manual.html | 2 ++ 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/sphinx_book_theme/header_buttons/source.py b/src/sphinx_book_theme/header_buttons/source.py index 63f29763..40e32b9a 100644 --- a/src/sphinx_book_theme/header_buttons/source.py +++ b/src/sphinx_book_theme/header_buttons/source.py @@ -86,19 +86,23 @@ def add_source_buttons(app, pagename, templatename, context, doctree): if opts.get("use_issues_button"): repo_url, provider = get_repo_url(context) - if provider != "github": - LOGGER.warning(f"Open issue button not yet supported for {provider}") - else: + if provider in ("github", "gitlab"): + if provider == "github": + url = f"{repo_url}/issues/new?title=Issue%20on%20page%20%2F{context['pagename']}.html&body=Your%20issue%20content%20here." # noqa: E501 + elif provider == "gitlab": + url = f"{repo_url}/-/issues/new?issue[title]=Issue%20on%20page%20%2F{context['pagename']}.html&issue[description]=Your%20issue%20content%20here." # noqa: E501 repo_buttons.append( { "type": "link", - "url": f"{repo_url}/issues/new?title=Issue%20on%20page%20%2F{context['pagename']}.html&body=Your%20issue%20content%20here.", # noqa: E501 + "url": url, "text": translation("Open issue"), "tooltip": translation("Open an issue"), "icon": "fas fa-lightbulb", "label": "source-issues-button", } ) + else: + LOGGER.warning(f"Open issue button not yet supported for {provider}") # If we have multiple repo buttons enabled, add a group, otherwise just 1 button if len(repo_buttons) > 1: diff --git a/tests/test_build.py b/tests/test_build.py index 43572fcb..fa864fef 100644 --- a/tests/test_build.py +++ b/tests/test_build.py @@ -215,7 +215,7 @@ def test_header_repository_buttons( def test_source_button_url(sphinx_build_factory, file_regression, provider, repo): """Test that source button URLs are properly constructed.""" # All buttons on - use_issues = "github.com" in repo + use_issues = "github.com" in repo or "gitlab.com" in repo or provider == "gitlab" confoverrides = { "html_theme_options": { "repository_url": repo, diff --git a/tests/test_build/header__source-buttons--gitlab.html b/tests/test_build/header__source-buttons--gitlab.html index ff3e38dd..deac2e8e 100644 --- a/tests/test_build/header__source-buttons--gitlab.html +++ b/tests/test_build/header__source-buttons--gitlab.html @@ -4,3 +4,5 @@ https://gitlab.com/gitlab-org/gitlab/-/edit/main/section1/ntbk.ipynb +https://gitlab.com/gitlab-org/gitlab/-/issues/new?issue[title]=Issue%20on%20page%20%2Fsection1/ntbk.html&issue[description]=Your%20issue%20content%20here. + diff --git a/tests/test_build/header__source-buttons--gitlab_manual.html b/tests/test_build/header__source-buttons--gitlab_manual.html index 8aba85ed..7b7925de 100644 --- a/tests/test_build/header__source-buttons--gitlab_manual.html +++ b/tests/test_build/header__source-buttons--gitlab_manual.html @@ -4,3 +4,5 @@ https://mywebsite.com/gitlab/gitlab-org/gitlab/-/edit/main/section1/ntbk.ipynb +https://mywebsite.com/gitlab/gitlab-org/gitlab/-/issues/new?issue[title]=Issue%20on%20page%20%2Fsection1/ntbk.html&issue[description]=Your%20issue%20content%20here. +