From 920b3a9c09346ac0c670ed802f88d425cbb8e26c Mon Sep 17 00:00:00 2001 From: Oleksandr Akhtyrskiy Date: Sat, 17 Jan 2026 12:46:35 -0700 Subject: [PATCH 1/2] Add command for creating pull requests via gh CLI --- .claude/commands/pr-create.md | 168 ++++++++++++++++++++++++++++++++++ 1 file changed, 168 insertions(+) create mode 100644 .claude/commands/pr-create.md diff --git a/.claude/commands/pr-create.md b/.claude/commands/pr-create.md new file mode 100644 index 0000000..81654a3 --- /dev/null +++ b/.claude/commands/pr-create.md @@ -0,0 +1,168 @@ +# Pull Request Creation Command + +Create a pull request following the project's PR template and conventions. + +## Arguments: $ARGUMENTS + +## Instructions + +### 1. Gather Context + +Run these commands in parallel to gather context: + +```bash +# Get current branch name +git branch --show-current + +# Get commits on this branch (since diverging from main) +git log main..HEAD --oneline + +# Check for uncommitted changes +git status --short +``` + +### 2. Extract Issue Reference + +Parse the branch name to extract the issue number: + +- Branch format: `-` (e.g., + `31-add-claude-code-command-for-creating-pull-requests-via-gh-cli`) +- Extract the leading number as the issue reference +- If no issue number is found, ask the user if this PR relates to an issue + +### 3. Fetch Issue Details + +If an issue number was found, fetch the issue to understand the scope: + +```bash +gh issue view --repo knight-owl-dev/keystone-cli +``` + +Use the issue's Goal, Scope, and context to inform the PR summary. + +### 4. Analyze Commits + +Review the git log output to understand what changes were made: + +- Group related commits conceptually +- Identify the high-level changes (not commit-by-commit detail) +- Focus on what behavior/functionality changed + +### 5. Determine Labels + +Based on the issue labels and commit content, recommend applicable labels: + +| Label | When to suggest | +|-------------------|----------------------------------------| +| `bug` | Fixes something broken | +| `enhancement` | New feature or improvement | +| `documentation` | Documentation-only changes | +| `security` | Security-related fixes or improvements | +| `breaking-change` | Changes that break existing behavior | +| `dependencies` | Dependency updates | + +If the related issue has labels, prefer to match them. + +### 6. Draft PR Content + +Follow the PR template (`.github/pull_request_template.md`): + +**Formatting**: Write paragraphs as flowing text without hard line breaks. GitHub's +markdown renderer handles wrapping automatically. Only use line breaks between sections +or for bullet lists. + +```markdown +## Summary + +[Describe the outcome this PR delivers, derived from the issue's Goal. +Focus on the WHY, not the HOW. Use flowing prose, not bullets.] + +## Related Issues + +[Use "Refs #NN" or "Fixes #NN" based on whether PR fully completes the issue] + +Refs # + +## Changes + +[High-level bullets derived from analyzing commits. Avoid commit-level detail. +Group related changes conceptually.] + +- [Change 1] +- [Change 2] +- [Change 3] + +## Further Comments + +[Optional: testing notes, migration steps, or anything reviewers should know. +Omit this section if not needed.] +``` + +### 7. Generate PR Title + +Create an outcome-focused title that: + +- Describes what the PR achieves (not what it does) +- Uses imperative mood ("Add...", "Enable...", "Fix...") +- Matches the issue title style when applicable +- Is concise (50-72 characters preferred) + +### 8. Preview and Confirm + +Show the user a preview of: + +- Title +- Labels +- Full body content + +Use AskUserQuestion to confirm before creating, with options to: + +- Create the PR as shown +- Edit the title +- Edit the content +- Add/remove labels + +### 9. Push Branch if Needed + +Check if the branch has been pushed to remote: + +```bash +git status -sb +``` + +If not pushed (no upstream), push with tracking: + +```bash +git push -u origin +``` + +### 10. Create the Pull Request + +Use gh CLI to create the PR: + +```bash +gh pr create \ + --repo knight-owl-dev/keystone-cli \ + --base main \ + --head \ + --label "" \ + --title "" \ + --body "<body>" +``` + +### 11. Output + +After successful creation: + +- Display the PR URL +- Ask if the user wants to open it in browser: + ```bash + gh pr view <pr-number> --repo knight-owl-dev/keystone-cli --web + ``` + +### Error Handling + +- **Uncommitted changes**: Warn the user and ask if they want to commit first +- **No commits**: Inform user there are no changes to create a PR for +- **Branch not pushed**: Offer to push the branch automatically +- **PR already exists**: Show the existing PR URL instead From b6c8d1eb834d1dd7361f03a8cc49319561825140 Mon Sep 17 00:00:00 2001 From: Oleksandr Akhtyrskiy <lex57ukr@gmail.com> Date: Sat, 17 Jan 2026 12:51:02 -0700 Subject: [PATCH 2/2] Update CONTRIBUTING.md to include pull request creation command for Claude Code --- CONTRIBUTING.md | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 75894e5..b5cde5f 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -47,16 +47,25 @@ planned work. Focus on outcomes rather than implementation details. ### Using Claude Code -If you use [Claude Code](https://claude.ai/code), you can create issues directly from the -terminal using the `/issue-create` command. It will: +If you use [Claude Code](https://claude.ai/code), you can create issues and pull requests +directly from the terminal. -- Prompt for a description (or accept one as an argument) -- Determine the appropriate template (bug or task) -- Suggest labels based on the content -- Preview the issue before creation -- Create the issue via `gh` CLI +**Creating issues** with `/issue-create`: -This requires the [GitHub CLI](https://cli.github.com/) to be installed and authenticated. +- Prompts for a description (or accepts one as an argument) +- Determines the appropriate template (bug or task) +- Suggests labels based on the content +- Previews the issue before creation + +**Creating pull requests** with `/pr-create`: + +- Extracts the issue number from the branch name (e.g., `42-fix-login-bug`) +- Fetches the related issue to understand scope and context +- Analyzes commits to compose the Changes section +- Generates a PR following the project template +- Suggests labels based on the related issue + +Both commands require the [GitHub CLI](https://cli.github.com/) to be installed and authenticated. ## Submitting Changes