-
-
Notifications
You must be signed in to change notification settings - Fork 6
feat: interactive GitHub issues wizard (ralph-starter github) #270
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d6d1d09
feat(wizard): add shared wizard utilities (credential prompt, browse-…
rubenmarcus 7633fba
feat(wizard): add GitHub interactive wizard command
rubenmarcus 439e017
feat(cli): register ralph-starter github command + run --from fallback
rubenmarcus b3e759b
docs: add GitHub wizard documentation and examples
rubenmarcus f9a1394
fix: anchor regex patterns and use type over interface
rubenmarcus ee91700
fix: resolve merge conflicts with main (add github, linear, notion wi…
rubenmarcus File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,299 @@ | ||
| /** | ||
| * ralph-starter github — Interactive GitHub issues wizard | ||
| * | ||
| * Guides the user through selecting GitHub issues to work on: | ||
| * 1. Authenticate (gh CLI or token) | ||
| * 2. Browse repos + issues or paste a URL | ||
| * 3. Select issues (multi-select) | ||
| * 4. Delegate to run command | ||
| */ | ||
|
|
||
| import chalk from 'chalk'; | ||
| import inquirer from 'inquirer'; | ||
| import { askBrowseOrUrl, askForUrl, ensureCredentials } from '../integrations/wizards/shared.js'; | ||
| import { type RunCommandOptions, runCommand } from './run.js'; | ||
|
|
||
| export type GitHubWizardOptions = { | ||
| commit?: boolean; | ||
| push?: boolean; | ||
| pr?: boolean; | ||
| validate?: boolean; | ||
| maxIterations?: number; | ||
| agent?: string; | ||
| }; | ||
|
|
||
| type GitHubRepo = { | ||
| name: string; | ||
| owner: { login: string }; | ||
| description: string; | ||
| }; | ||
|
|
||
| type GitHubIssue = { | ||
| number: number; | ||
| title: string; | ||
| labels: Array<{ name: string }>; | ||
| }; | ||
|
|
||
| type GitHubLabel = { | ||
| name: string; | ||
| }; | ||
|
|
||
| /** Check if gh CLI is available and authenticated */ | ||
| async function isGhCliAvailable(): Promise<boolean> { | ||
| try { | ||
| const { execa } = await import('execa'); | ||
| await execa('gh', ['auth', 'status']); | ||
| return true; | ||
| } catch { | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| /** Fetch user's repos via gh CLI */ | ||
| async function fetchReposViaCli(limit = 30): Promise<GitHubRepo[]> { | ||
| const { execa } = await import('execa'); | ||
| const result = await execa('gh', [ | ||
| 'repo', | ||
| 'list', | ||
| '--json', | ||
| 'name,owner,description', | ||
| '--limit', | ||
| String(limit), | ||
| '--sort', | ||
| 'updated', | ||
| ]); | ||
| return JSON.parse(result.stdout); | ||
| } | ||
|
|
||
| /** Fetch open issues for a repo via gh CLI */ | ||
| async function fetchIssuesViaCli( | ||
| owner: string, | ||
| repo: string, | ||
| label?: string, | ||
| limit = 30 | ||
| ): Promise<GitHubIssue[]> { | ||
| const { execa } = await import('execa'); | ||
| const args = [ | ||
| 'issue', | ||
| 'list', | ||
| '-R', | ||
| `${owner}/${repo}`, | ||
| '--json', | ||
| 'number,title,labels', | ||
| '--limit', | ||
| String(limit), | ||
| '--state', | ||
| 'open', | ||
| ]; | ||
| if (label) { | ||
| args.push('--label', label); | ||
| } | ||
| const result = await execa('gh', args); | ||
| return JSON.parse(result.stdout); | ||
| } | ||
|
|
||
| /** Fetch labels for a repo via gh CLI */ | ||
| async function fetchLabelsViaCli(owner: string, repo: string): Promise<GitHubLabel[]> { | ||
| const { execa } = await import('execa'); | ||
| const result = await execa('gh', [ | ||
| 'label', | ||
| 'list', | ||
| '-R', | ||
| `${owner}/${repo}`, | ||
| '--json', | ||
| 'name', | ||
| '--limit', | ||
| '50', | ||
| ]); | ||
| return JSON.parse(result.stdout); | ||
| } | ||
|
|
||
| /** Parse a GitHub URL into owner/repo and optional issue number */ | ||
| function parseGitHubUrl(url: string): { owner: string; repo: string; issue?: number } | null { | ||
| // Match: https://github.com/owner/repo/issues/123 | ||
| const issueMatch = url.match(/^https?:\/\/github\.com\/([^/]+)\/([^/]+)\/issues\/(\d+)/); | ||
| if (issueMatch) { | ||
| return { | ||
| owner: issueMatch[1], | ||
| repo: issueMatch[2].replace(/\.git$/, ''), | ||
| issue: parseInt(issueMatch[3], 10), | ||
| }; | ||
| } | ||
|
|
||
| // Match: https://github.com/owner/repo | ||
| const repoMatch = url.match(/^https?:\/\/github\.com\/([^/]+)\/([^/]+)/); | ||
| if (repoMatch) { | ||
| return { | ||
| owner: repoMatch[1], | ||
| repo: repoMatch[2].replace(/\.git$/, '').replace(/\/$/, ''), | ||
| }; | ||
| } | ||
|
|
||
| return null; | ||
| } | ||
|
|
||
| export async function githubCommand(options: GitHubWizardOptions): Promise<void> { | ||
| console.log(); | ||
| console.log(chalk.cyan.bold(' GitHub Issues')); | ||
| console.log(chalk.dim(' Build from GitHub issues interactively')); | ||
| console.log(); | ||
|
|
||
| // Step 1: Ensure credentials | ||
| await ensureCredentials('github', 'GitHub', { | ||
| credKey: 'token', | ||
| consoleUrl: 'https://github.com/settings/tokens', | ||
| envVar: 'GITHUB_TOKEN', | ||
| checkCliAuth: isGhCliAvailable, | ||
| }); | ||
|
|
||
| // Step 2: Browse or URL? | ||
| const mode = await askBrowseOrUrl('GitHub'); | ||
|
|
||
| if (mode === 'url') { | ||
| const url = await askForUrl('GitHub', /^https?:\/\/github\.com\//); | ||
| const parsed = parseGitHubUrl(url); | ||
| if (!parsed) { | ||
| console.log( | ||
| chalk.red(' Could not parse GitHub URL. Expected format: github.com/owner/repo') | ||
| ); | ||
| return; | ||
| } | ||
|
|
||
| const runOpts: RunCommandOptions = { | ||
| from: 'github', | ||
| project: `${parsed.owner}/${parsed.repo}`, | ||
| issue: parsed.issue, | ||
| auto: true, | ||
| commit: options.commit ?? false, | ||
| push: options.push, | ||
| pr: options.pr, | ||
| validate: options.validate ?? true, | ||
| maxIterations: options.maxIterations, | ||
| agent: options.agent, | ||
| }; | ||
|
|
||
| await runCommand(undefined, runOpts); | ||
| return; | ||
| } | ||
|
|
||
| // Browse mode | ||
| // Step 3: Fetch and select repository | ||
| console.log(chalk.dim(' Fetching your repositories...')); | ||
| let repos: GitHubRepo[]; | ||
| try { | ||
| repos = await fetchReposViaCli(); | ||
| } catch (err) { | ||
| console.log(chalk.red(' Failed to fetch repositories. Check your authentication.')); | ||
| console.log(chalk.dim(` Error: ${err instanceof Error ? err.message : String(err)}`)); | ||
| return; | ||
| } | ||
|
rubenmarcus marked this conversation as resolved.
|
||
|
|
||
| if (repos.length === 0) { | ||
| console.log(chalk.yellow(' No repositories found.')); | ||
| return; | ||
| } | ||
|
|
||
| const { selectedRepo } = await inquirer.prompt([ | ||
| { | ||
| type: 'select', | ||
| name: 'selectedRepo', | ||
| message: 'Select a repository:', | ||
| choices: repos.map((r) => ({ | ||
| name: `${r.owner.login}/${r.name}${r.description ? chalk.dim(` — ${r.description.slice(0, 60)}`) : ''}`, | ||
| value: `${r.owner.login}/${r.name}`, | ||
| })), | ||
| }, | ||
| ]); | ||
|
|
||
| const [owner, repo] = selectedRepo.split('/'); | ||
|
|
||
| // Step 4: Optional label filter | ||
| let selectedLabel: string | undefined; | ||
| try { | ||
| const labels = await fetchLabelsViaCli(owner, repo); | ||
| if (labels.length > 0) { | ||
| const { labelChoice } = await inquirer.prompt([ | ||
| { | ||
| type: 'select', | ||
| name: 'labelChoice', | ||
| message: 'Filter by label?', | ||
| choices: [ | ||
| { name: 'All issues (no filter)', value: '__none__' }, | ||
| ...labels.map((l) => ({ name: l.name, value: l.name })), | ||
| ], | ||
| }, | ||
| ]); | ||
| if (labelChoice !== '__none__') { | ||
| selectedLabel = labelChoice; | ||
| } | ||
| } | ||
| } catch { | ||
| // Labels fetch failed, skip filter | ||
| } | ||
|
|
||
| // Step 5: Fetch and select issues | ||
| console.log(chalk.dim(` Fetching open issues for ${owner}/${repo}...`)); | ||
| let issues: GitHubIssue[]; | ||
| try { | ||
| issues = await fetchIssuesViaCli(owner, repo, selectedLabel); | ||
| } catch (err) { | ||
| console.log(chalk.red(' Failed to fetch issues.')); | ||
| console.log(chalk.dim(` Error: ${err instanceof Error ? err.message : String(err)}`)); | ||
| return; | ||
| } | ||
|
|
||
| if (issues.length === 0) { | ||
| console.log( | ||
| chalk.yellow( | ||
| ` No open issues found${selectedLabel ? ` with label "${selectedLabel}"` : ''}.` | ||
| ) | ||
| ); | ||
| return; | ||
| } | ||
|
|
||
| const { selectedIssues } = await inquirer.prompt([ | ||
| { | ||
| type: 'checkbox', | ||
| name: 'selectedIssues', | ||
| message: 'Select issues to work on:', | ||
| choices: issues.map((issue) => { | ||
| const labelTags = | ||
| issue.labels.length > 0 | ||
| ? ` ${chalk.dim(`[${issue.labels.map((l) => l.name).join(', ')}]`)}` | ||
| : ''; | ||
| return { | ||
| name: `#${issue.number} — ${issue.title}${labelTags}`, | ||
| value: issue.number, | ||
| }; | ||
| }), | ||
| validate: (input: number[]) => (input.length > 0 ? true : 'Please select at least one issue'), | ||
| }, | ||
| ]); | ||
|
|
||
| // Step 6: Run for each selected issue | ||
| console.log(); | ||
| console.log( | ||
| chalk.green( | ||
| ` Starting build for ${selectedIssues.length} issue${selectedIssues.length > 1 ? 's' : ''}...` | ||
| ) | ||
| ); | ||
| console.log(); | ||
|
|
||
| for (const issueNumber of selectedIssues) { | ||
| const runOpts: RunCommandOptions = { | ||
| from: 'github', | ||
| project: `${owner}/${repo}`, | ||
| issue: issueNumber, | ||
| label: selectedLabel, | ||
| auto: true, | ||
| commit: options.commit ?? false, | ||
| push: options.push, | ||
| pr: options.pr, | ||
| validate: options.validate ?? true, | ||
| maxIterations: options.maxIterations, | ||
| agent: options.agent, | ||
| }; | ||
|
|
||
| await runCommand(undefined, runOpts); | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.