review: Generate thanks commit URLs for known repositories automatically
PATCH v2 1/1 review: Generate thanks commit URLs for known repositories automatically
At present generating links to commits in web interfaces for inclusion in thanks mails requires manual configuration of a global configuration option b4.thanks-commit-url-mask, or the per remote equivalent b4-thanks-url-mask. Given that we also have the b4-check-repo option to configure where to check to see if thanks are ready to be sent and practically speaking this is likely to be one of a very small set of hosting providers this is all a bit redundant.
If one of git.kernel.org, github or gitlab is configured for the check repo or remote URL for the branch then default to generating a link based on our knowledge of the remote, a manual configuration will still override the default.
---
Also fall back to the remote URL.
docs/config.rst | 32 ++++- docs/maintainer/review.rst | 15 +-- src/b4/command.py | 4 + src/b4/review_tui/_tracking_app.py | 4 +- src/b4/templates/thanks-am-template.example | 3 + src/b4/templates/thanks-pr-template.example | 3 + src/b4/ty.py | 131 +++++++++++++++----- src/tests/test_tui_tracking.py | 45 +++++++ src/tests/test_ty.py | 88 +++++++++++++ 9 files changed, 281 insertions(+), 44 deletions(-)
docs/config.rst +26 -6
@@ -463,6 +463,11 @@ Attestation settings [remote "spi"] b4-check-repo = https://git.kernel.org/pub/scm/linux/kernel/git/username/spi.git + For recognized HTTP(S) web hosts (currently git.kernel.org, + github.com, and gitlab.com), b4 also uses this URL to link commits in + the thank-you message. Other transports and hosting layouts can use + the per-remote ``b4-commit-url-mask`` described below. + See :ref:`queuing thanks <thanks_queue>` for details. Default: ``None``
@@ -471,14 +476,29 @@ Attestation settings Used when creating summaries for ``b4 ty`` and the review TUI thank-you flow. Can be a value like:: - thanks-commit-url-mask = https://git.kernel.org/username/c/%.12s + thanks-commit-url-mask = https://git.kernel.org/username/tree/c/%.12s + + If no explicit mask or recognized check-repository URL is available, + b4 falls back to using commit hashes. - If not set, b4 falls back to using commit hashes. + For repositories with multiple remotes, an explicit per-remote mask + takes precedence over this setting:: - When this option is set, the review TUI's thank-you preview offers - a **Queue** option that stores the message for delayed delivery. - Queued messages are held until their commit is verified published, - so you can push your commits before the thank-you is sent. + [remote "spi"] + b4-commit-url-mask = https://git.kernel.org/username/spi/c/%.12s + + When no explicit per-remote mask is set, b4 automatically derives one + from that remote's ``b4-check-repo`` for recognized HTTP(S) web hosts. + The same derivation is attempted from :term:`b4.thanks-check-repo`, and + then from the URL of the remote the target branch tracks, when neither + a per-remote nor this global mask is available — the same repository + URLs, in the same order, that :term:`b4.thanks-check-repo` resolution + uses. A URL that is not a recognized web host is simply skipped. + + When a commit URL can be generated, the review TUI's thank-you preview + offers a **Queue** option that stores the message for delayed delivery. + Queued messages are held until their commit is verified published, so + you can push your commits before the thank-you is sent. See :ref:`queuing thanks <thanks_queue>` for details. .. note::
docs/maintainer/review.rst +8 -7
@@ -1023,13 +1023,14 @@ screen shows the generated message with keybindings to **Send** **Queuing thanks for delayed delivery** -When :term:`b4.thanks-commit-url-mask` is configured, the thank-you -preview also offers a **Queue** option (``W``). Queuing writes the -message as an RFC 2822 file in ``.git/b4-review/queue/`` instead of -sending it immediately. This is useful when you want to push your -commits to a public tree before sending thank-you messages — the -message references commit URLs that may not resolve until the push is -complete. +When b4 can generate a web link for the commit — from +:term:`b4.thanks-commit-url-mask`, a per-remote ``b4-commit-url-mask``, or +a recognized HTTP(S) check-repository or remote URL — the thank-you preview +also offers a **Queue** option (``W``). Queuing writes the message as an RFC 2822 +file in ``.git/b4-review/queue/`` instead of sending it immediately. This +is useful when you want to push your commits to a public tree before +sending thank-you messages — the message references commit URLs that may +not resolve until the push is complete. Files are named ``{change-id}-v{revision}.msg`` and the check target is recorded as ``X-Check-URL``, ``X-Check-Commit``, ``X-Check-Repo`` and
src/b4/command.py +4 -0
@@ -249,6 +249,10 @@ def cmd_pr(cmdargs: argparse.Namespace) -> None: def cmd_ty(cmdargs: argparse.Namespace) -> None: import b4.ty + if cmdargs.gitdir: + # The initial setup happens relative to cwd. Reload repository-local + # thank-you settings when -g names a different tree. + b4.setup_config(cmdargs, topdir=cmdargs.gitdir) b4.ty.main(cmdargs)
src/b4/review_tui/_tracking_app.py +2 -2
@@ -4926,8 +4926,8 @@ class TrackingApp(LoreNodeShutdownMixin, CheckRunnerMixin, App[Optional[str]]): # Compute checkurl from last taken commit for queue support checkurl: Optional[str] = None checkcommit: Optional[str] = None - cidmask = config.get('thanks-commit-url-mask') - if isinstance(cidmask, str) and cidmask and '%' in cidmask: + cidmask = b4.ty.get_commit_url_mask(topdir, target_branch) + if cidmask and '%' in cidmask: # Find the last commit ID (highest patch index with a commit) last_cid: Optional[str] = None for _idx, cid in commits:
src/b4/templates/thanks-am-template.example +3 -0
@@ -20,6 +20,9 @@ ${quote} # url = https://... # fetch = ... # b4-treename = uname/sound.git +# b4-check-repo = https://git.kernel.org/pub/scm/linux/kernel/git/uname/sound.git +# The check repo is also used to generate commit links for known web hosts. +# For other hosts, or to choose a different link format, set an explicit mask: # b4-commit-url-mask = https://git.kernel.org/uname/sound/c/%.8s Applied to ${branch}, thanks!
src/b4/templates/thanks-pr-template.example +3 -0
@@ -20,6 +20,9 @@ ${quote} # url = https://... # fetch = ... # b4-treename = uname/sound.git +# b4-check-repo = https://git.kernel.org/pub/scm/linux/kernel/git/uname/sound.git +# The check repo is also used to generate commit links for known web hosts. +# For other hosts, or to choose a different link format, set an explicit mask: # b4-commit-url-mask = https://git.kernel.org/uname/sound/c/%.8s Merged into ${branch}, thanks!
src/b4/ty.py +102 -29
217 lines not on this page · raw message
src/tests/test_tui_tracking.py +45 -0
51 lines not on this page · raw message
src/tests/test_ty.py +88 -0
106 lines not on this page · raw message
Signature · 1 line
2.47.3
Quoted 8 lines · Mark Brown
At present generating links to commits in web interfaces for inclusion in thanks mails requires manual configuration of a global configuration option b4.thanks-commit-url-mask, or the per remote equivalent b4-thanks-url-mask. Given that we also have the b4-check-repo option to configure where to check to see if thanks are ready to be sent and practically speaking this is likely to be one of a very small set of hosting providers this is all a bit redundant.
Quoted 4 lines
If one of git.kernel.org, github or gitlab is configured for the check repo or remote URL for the branch then default to generating a link based on our knowledge of the remote, a manual configuration will still override the default.
I didn't take this directly, but I did work it into a set of commits that expanded this into a few other affected areas. It's largely based on your work, so I added a Co-Developed-By to give you credit.
Thanks!
-K
Signature · 1 line
Konstantin Ryabitsev <[email protected]>