Skip to main content

read_link_with_pr_detection

Function read_link_with_pr_detection 

Source
pub fn read_link_with_pr_detection(
    repo: &Repository,
    branch: &str,
    slug: &str,
) -> Result<BranchLink>
Expand description

Resolve the link for branch and, unless a PR is explicitly linked, auto-detect the branch’s PR from GitHub via gh (issue #181). The detected PR is marked LinkSource::Detected.

A persisted auto-detection (gwm-pr-detected, issue #283) does NOT pin the result here: this is the live-detection path (gwm status / gwm list --detect-pr), so it re-runs gh pr list to reflect a PR that was opened / closed / replaced since the last detection, rather than echoing a stale stored number (Codex review #284). Only an explicit gwm link --pr short-circuits the probe.

On a successful probe this also reconciles the persisted cache (gwm-pr-detected): it rewrites the stored number to the fresh result, or clears it when the PR vanished, so the no-fetch consumers (read_link, the TUI table at startup, gwm open pr) don’t resurrect a stale number after this path saw it change (Codex review #284). The cache write is best-effort — a read-only repo must not turn gwm status into an error.

Detection is best-effort: a gh failure (not installed, no network) leaves the link untouched — a persisted detection survives the failed probe rather than being wiped — and the local link is still returned. This shells out, so callers on hot paths (per-worktree listing) must opt in deliberately rather than route every read through here.