/** * GitHub CLI (gh) backlog provider implementation. * * Provides access to GitHub Issues as a ticket/backlog system using * the `gh` CLI tool instead of the Octokit REST API. * * This implementation offers a simpler authentication experience via * `gh auth login` compared to managing GITHUB_TOKEN environment variables. * * @example * ```typescript * import { GitHubCliProvider } from './github-cli.js'; * * const provider = new GitHubCliProvider(config); * * // Check authentication * const auth = await provider.checkAuth(); * if (!auth.ok) throw new Error(auth.message); * * // Fetch a ticket * const ticket = await provider.getTicket('#123'); * ``` */ import type { TicketRef } from '../types/ticket.js'; import type { BacklogProvider, BacklogProviderName, Ticket, TicketCreateParams, TicketUpdates, AuthCheckResult } from './types.js'; import { AuthError, NotFoundError, ProviderError } from './errors.js'; import type { SpecKitConfig } from '../config.js'; /** * Base error class for gh CLI operations. * * Extends ProviderError with optional command context for debugging. * * @example * ```typescript * throw new GitHubCliError('Failed to execute gh command', 'gh issue view 123'); * ``` */ export declare class GitHubCliError extends ProviderError { /** * The gh CLI command that caused the error (for debugging). */ readonly command?: string; /** * Creates a new GitHubCliError. * * @param message - Human-readable error message * @param command - Optional gh CLI command that failed */ constructor(message: string, command?: string); } /** * Error thrown when gh CLI authentication fails. * * This typically means the user needs to run `gh auth login`. * * @example * ```typescript * throw new GitHubCliAuthError('Not authenticated. Run: gh auth login'); * ``` */ export declare class GitHubCliAuthError extends AuthError { /** * Creates a new GitHubCliAuthError. * * @param message - Human-readable error message */ constructor(message: string); } /** * Error thrown when a GitHub resource is not found. * * @example * ```typescript * throw new GitHubCliNotFoundError('Issue #123 not found', '#123'); * ``` */ export declare class GitHubCliNotFoundError extends NotFoundError { /** * Creates a new GitHubCliNotFoundError. * * @param message - Human-readable error message * @param ref - Optional reference that was not found */ constructor(message: string, ref?: string); } /** * GitHub backlog provider using the gh CLI. * * Implements the BacklogProvider interface for GitHub Issues using * the gh CLI tool. Requires gh to be installed and authenticated * via `gh auth login`. * * Advantages over Octokit-based GitHubProvider: * - Simpler authentication (browser-based via gh auth login) * - Automatic credential management via system keychain * - Built-in rate limiting feedback * * @example * ```typescript * const provider = new GitHubCliProvider(config); * * // Auto-detects repo from git remote * const ticket = await provider.getTicket('#123'); * * // Create a new issue * const newTicket = await provider.createTicket({ * title: 'New feature request', * body: 'Description here', * labels: ['feature'], * }); * ``` */ export declare class GitHubCliProvider implements BacklogProvider { readonly name: BacklogProviderName; private readonly config; private repoContext; /** * Create a new GitHub CLI provider. * * @param config - SpecKit configuration */ constructor(config: SpecKitConfig); /** * Auto-detect repository context from the current git directory. * * Uses `gh repo view --json nameWithOwner` to determine the owner/repo. * Results are cached for subsequent calls. * * @returns Repository context with owner and repo * @throws GitHubCliError if not in a git repo with GitHub remote */ private ensureRepoContext; /** * Set the repository context manually. * * Use this to override auto-detection or when working outside a git repo. * * @param owner - Repository owner * @param repo - Repository name */ setRepoContext(owner: string, repo: string): void; /** * Parse user input to a TicketRef. * * Handles various GitHub input formats: * - `#123` - Local issue number * - `123` - Plain issue number * - `owner/repo#123` - Cross-repo reference * - `https://github.com/owner/repo/issues/123` - Full URL * * @param input - User-provided reference string * @returns Parsed TicketRef or null if invalid for this provider */ parseRef(input: string): TicketRef | null; /** * Generate the web URL for a ticket. * * @param ref - GitHub reference * @returns Full URL to view the issue */ getTicketUrl(ref: string): string; /** * Check if gh CLI authentication is valid. * * Uses `gh auth status` to verify the user is logged in. * * @returns Authentication check result */ checkAuth(): Promise; /** * Fetch a ticket by reference string. * * @param ref - GitHub reference (#123, owner/repo#123, or full URL) * @returns Normalized Ticket object * @throws GitHubCliNotFoundError if issue doesn't exist * @throws GitHubCliAuthError if authentication fails */ getTicket(ref: string): Promise; /** * Create a new ticket. * * @param params - Ticket creation parameters * @returns Created Ticket object * @throws GitHubCliAuthError if authentication fails */ createTicket(params: TicketCreateParams): Promise; /** * Update an existing ticket. * * @param ref - GitHub reference * @param updates - Fields to update * @returns Updated Ticket object * @throws GitHubCliNotFoundError if issue doesn't exist * @throws GitHubCliAuthError if authentication fails */ updateTicket(ref: string, updates: TicketUpdates): Promise; /** * Get current labels on a ticket. * * @param ref - GitHub reference * @returns Array of label names * @throws GitHubCliNotFoundError if issue doesn't exist */ getLabels(ref: string): Promise; /** * Replace all labels on a ticket. * * This implementation calculates the diff between current and desired labels, * then uses --add-label and --remove-label to apply the changes. * * @param ref - GitHub reference * @param labels - Labels to set (replaces all existing labels) * @throws GitHubCliNotFoundError if issue doesn't exist * @throws GitHubCliAuthError if authentication fails */ setLabels(ref: string, labels: string[]): Promise; /** * Search for tickets matching a query. * * Uses `gh search issues` with GitHub search syntax. * * @param query - GitHub search syntax (e.g., 'is:open label:bug') * @returns Array of matching tickets * @throws GitHubCliAuthError if authentication fails */ searchTickets(query: string): Promise; /** * Map a GitHub issue JSON response to normalized Ticket format. */ private mapIssueToTicket; /** * Map GitHub issue state to normalized TicketState. */ private mapState; /** * Map search result state string to TicketState. */ private mapSearchState; } //# sourceMappingURL=github-cli.d.ts.map