Skip to content

Commit

Permalink
add support for gitlab issue button (#740)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
akhmerov and pre-commit-ci[bot] authored Jul 3, 2023
1 parent ce55a46 commit a9794b7
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
12 changes: 8 additions & 4 deletions src/sphinx_book_theme/header_buttons/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions tests/test_build/header__source-buttons--gitlab.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
<i class="fas fa-code"></i>
https://gitlab.com/gitlab-org/gitlab/-/edit/main/section1/ntbk.ipynb
<i class="fas fa-pencil-alt"></i>
https://gitlab.com/gitlab-org/gitlab/-/issues/new?issue[title]=Issue%20on%20page%20%2Fsection1/ntbk.html&issue[description]=Your%20issue%20content%20here.
<i class="fas fa-lightbulb"></i>
2 changes: 2 additions & 0 deletions tests/test_build/header__source-buttons--gitlab_manual.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
<i class="fas fa-code"></i>
https://mywebsite.com/gitlab/gitlab-org/gitlab/-/edit/main/section1/ntbk.ipynb
<i class="fas fa-pencil-alt"></i>
https://mywebsite.com/gitlab/gitlab-org/gitlab/-/issues/new?issue[title]=Issue%20on%20page%20%2Fsection1/ntbk.html&issue[description]=Your%20issue%20content%20here.
<i class="fas fa-lightbulb"></i>

0 comments on commit a9794b7

Please sign in to comment.