spacr.qt.ai.github_auth

GitHub authentication + direct issue creation for spaCR.

Lets users file approved issues WITHOUT a browser round-trip. A token is resolved from the GITHUB_TOKEN / GH_TOKEN environment or the GitHub CLI (gh auth token). spaCR does not capture or persist credentials; the official CLI owns interactive login and its platform credential store.

When a token is available, create_issue() POSTs straight to the GitHub REST API and returns the created issue’s URL. When none is available the caller falls back to opening the pre-filled issues/new URL in the browser.

Public API:

github_auth.is_authenticated()      -> bool
github_auth.auth_source()            -> "token" | "env" | "gh" | None
github_auth.create_issue(repo, title, body, labels) -> (ok, url_or_error)

Functions

auth_source(→ Optional[str])

Where the active token comes from — 'token' | 'env' | 'gh' | None.

comment_on_issue(→ Tuple[bool, str])

Add a comment to an existing issue.

create_issue(→ Tuple[bool, str])

Create a GitHub issue directly via the REST API.

find_issue_by_fingerprint(→ Tuple[bool, Optional[dict]])

Find an open GitHub issue containing a diagnostic fingerprint.

get_stored_token(→ str)

Return a process-only token, after erasing insecure legacy storage.

is_authenticated(→ bool)

True iff a GitHub token is available from any source.

resolve_token(→ Tuple[str, Optional[str]])

Return (token, source) — source is 'token' | 'env' | 'gh' | None.

set_stored_token(→ None)

Set a process-only compatibility token; never persist it.

Module Contents

spacr.qt.ai.github_auth.auth_source() → str | None[source]

Where the active token comes from — ‘token’ | ‘env’ | ‘gh’ | None.

spacr.qt.ai.github_auth.comment_on_issue(repo: str, number: int, body: str) → Tuple[bool, str][source]

Add a comment to an existing issue.

Parameters:
  • repo – owner/name slug.

  • number – the issue number.

  • body – markdown comment body.

Returns:

(True, comment_html_url) on success, else (False, error).

spacr.qt.ai.github_auth.create_issue(repo: str, title: str, body: str, labels: List[str] | None = None) → Tuple[bool, str][source]

Create a GitHub issue directly via the REST API.

Parameters:
  • repo – owner/name slug.

  • title – issue title.

  • body – markdown body.

  • labels – labels to attach (created lazily by GitHub if new).

Returns:

(True, issue_html_url) on success, else (False, error).

spacr.qt.ai.github_auth.find_issue_by_fingerprint(repo: str, fingerprint: str) → Tuple[bool, dict | None][source]

Find an open GitHub issue containing a diagnostic fingerprint.

Parameters:
  • repo (str) – Repository slug in owner/name form.

  • fingerprint (str) – Short diagnostic hash stored in the issue body.

Returns:

  • search_completed (bool) – True when GitHub returned a search result, including no matches. False when authentication is unavailable or the search fails.

  • issue (dict or None) – First matching issue, or None when no issue was found or the search could not be completed.

spacr.qt.ai.github_auth.get_stored_token() → str[source]

Return a process-only token, after erasing insecure legacy storage.

spacr.qt.ai.github_auth.is_authenticated() → bool[source]

True iff a GitHub token is available from any source.

spacr.qt.ai.github_auth.resolve_token() → Tuple[str, str | None][source]

Return (token, source) — source is ‘token’ | ‘env’ | ‘gh’ | None.

spacr.qt.ai.github_auth.set_stored_token(token: str) → None[source]

Set a process-only compatibility token; never persist it.

The GUI no longer exposes this function. It remains for API callers and offline transport tests that need to inject a credential for one process. Interactive users authenticate with gh auth login.

Parameters:

token – the GitHub token to hold in memory for this process; surrounding whitespace is stripped, and an empty value or None clears it. Any token left in QSettings by older builds is removed.