From 47d0ca70af79d2a18df35607894706f0cb9bc9e0 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Mon, 8 Aug 2022 22:02:37 +0300 Subject: [PATCH 1/3] Add a Sphinx role to link to GitHub labels --- _extensions/custom_roles.py | 33 ++++++++++++++++++++ conf.py | 6 ++++ triage/labels.rst | 62 ++++++++++++++++++------------------- 3 files changed, 70 insertions(+), 31 deletions(-) create mode 100644 _extensions/custom_roles.py diff --git a/_extensions/custom_roles.py b/_extensions/custom_roles.py new file mode 100644 index 0000000000..adcf129724 --- /dev/null +++ b/_extensions/custom_roles.py @@ -0,0 +1,33 @@ +"""Sphinx extension to add custom roles. + +Based on https://protips.readthedocs.io/link-roles.html +""" +import urllib.parse + +from docutils import nodes + + +def setup(app): + app.add_role( + "gh-label", + autolink( + "https://github.com/python/cpython/issues" + "?q=is%%3Aopen+sort%%3Aupdated-desc+label%%3A%s" + ), + ) + # Parallel safety: + # https://www.sphinx-doc.org/en/master/extdev/index.html#extension-metadata + return {"parallel_read_safe": True, "parallel_write_safe": True} + + +def autolink(pattern): + def role(name, rawtext, text, lineno, inliner, options={}, content=[]): + if " " in text: + url_text = urllib.parse.quote_plus(f'"{text}"') + else: + url_text = text + url = pattern % (url_text,) + node = nodes.reference(rawtext, text, refuri=url, **options) + return [node], [] + + return role diff --git a/conf.py b/conf.py index ba3b164a02..327615bdba 100644 --- a/conf.py +++ b/conf.py @@ -1,6 +1,12 @@ +import os +import sys import time +# Location of custom extensions. +sys.path.insert(0, os.path.abspath(".") + "/_extensions") + extensions = [ + 'custom_roles', 'sphinx.ext.intersphinx', 'sphinx.ext.todo', 'sphinx_copybutton', diff --git a/triage/labels.rst b/triage/labels.rst index 78a5ac9b52..f409f84cee 100644 --- a/triage/labels.rst +++ b/triage/labels.rst @@ -13,35 +13,35 @@ you going. For a full list, see `here `_ file. -awaiting changes +:gh-label:`awaiting changes` A reviewer required changes to proceed with the PR. -awaiting change review +:gh-label:`awaiting change review` The PR author made requested changes, and they are waiting for review. -awaiting merge +:gh-label:`awaiting merge` The PR has been approved by a core developer and is ready to merge. -test-with-buildbots +:gh-label:`test-with-buildbots` Used on PRs to test the latest commit with the buildbot fleet. Generally for PRs with large code changes requiring more testing before merging. This may take multiple hours to complete. Triagers can also stop a stuck build From 8928ba6a88ce85921a6d75614be5f7c228794aed Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Wed, 10 Aug 2022 08:27:41 +0300 Subject: [PATCH 2/3] Link to https://github.com/python/cpython/labels/{LABEL-NAME} --- _extensions/custom_roles.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/_extensions/custom_roles.py b/_extensions/custom_roles.py index adcf129724..ceba4909e7 100644 --- a/_extensions/custom_roles.py +++ b/_extensions/custom_roles.py @@ -10,10 +10,7 @@ def setup(app): app.add_role( "gh-label", - autolink( - "https://github.com/python/cpython/issues" - "?q=is%%3Aopen+sort%%3Aupdated-desc+label%%3A%s" - ), + autolink("https://github.com/python/cpython/labels/%s"), ) # Parallel safety: # https://www.sphinx-doc.org/en/master/extdev/index.html#extension-metadata @@ -23,7 +20,7 @@ def setup(app): def autolink(pattern): def role(name, rawtext, text, lineno, inliner, options={}, content=[]): if " " in text: - url_text = urllib.parse.quote_plus(f'"{text}"') + url_text = urllib.parse.quote(f"{text}") else: url_text = text url = pattern % (url_text,) From cb311389b496495f659f9d532e26a21abb8bf750 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Wed, 10 Aug 2022 08:40:30 +0300 Subject: [PATCH 3/3] Add a working example for 'needs backport to X.Y' --- triage/labels.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/triage/labels.rst b/triage/labels.rst index f409f84cee..60f2556410 100644 --- a/triage/labels.rst +++ b/triage/labels.rst @@ -110,7 +110,8 @@ Labels specific to PRs Hacktoberfest, this label will prevent the PR from counting toward the author's contributions. -:gh-label:`needs backport to X.Y` +needs backport to X.Y + For example, :gh-label:`needs backport to 3.11`. Used for PRs which are appropriate to backport to branches prior to main. Generally, backports to the maintenance branches are primarily bugfixes and documentation clarifications. Backports to the