From 1b00527dfe74475b941dcdefe31048527b064277 Mon Sep 17 00:00:00 2001 From: Zhongwei Li Date: Sat, 29 Nov 2025 17:54:54 +0800 Subject: [PATCH] Initial commit --- .claude-plugin/plugin.json | 13 +++ README.md | 3 + commands/open-pr.md | 179 +++++++++++++++++++++++++++++++++++++ plugin.lock.json | 45 ++++++++++ 4 files changed, 240 insertions(+) create mode 100644 .claude-plugin/plugin.json create mode 100644 README.md create mode 100644 commands/open-pr.md create mode 100644 plugin.lock.json diff --git a/.claude-plugin/plugin.json b/.claude-plugin/plugin.json new file mode 100644 index 0000000..2fdb343 --- /dev/null +++ b/.claude-plugin/plugin.json @@ -0,0 +1,13 @@ +{ + "name": "github", + "description": "AI-powered github tools", + "version": "1.0.0", + "author": { + "name": "Andrzej Sliwa", + "email": "andrzej.sliwa@gmail.com", + "url": "https://github.com/andrzejsliwa" + }, + "commands": [ + "./commands" + ] +} \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..ebc30a3 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# github + +AI-powered github tools diff --git a/commands/open-pr.md b/commands/open-pr.md new file mode 100644 index 0000000..f453748 --- /dev/null +++ b/commands/open-pr.md @@ -0,0 +1,179 @@ +# Open Pull Request + +You are executing the `/open-pr` command. Follow these steps precisely: + +## Parameters + +- `draft` (optional): Create PR as draft if specified (e.g., `/open-pr draft`) + +## Step 0: Branch Check + +**CRITICAL: Run this check FIRST before any other steps.** + +Check current branch with `git branch --show-current`. + +**If on main or master branch:** + +1. Ask user for new branch name using AskUserQuestion: + - "You're on the main/master branch. What should the new branch be called?" + - Options: + - "Auto-generate from changes" - Claude creates descriptive branch name based on changes + - "Custom name" - User will provide branch name +2. Create and checkout new branch: + - If auto-generate: analyze changes briefly to create branch name (format: `feature/descriptive-name` or `fix/descriptive-name`) + - If custom: wait for user input, then `git checkout -b ` + +**If on any other branch:** Proceed to Step 1. + +## Step 1: Analyze Changes + +Run `git status` and `git diff` to analyze all changes: + +- Identify files modified/created by Claude in current session +- Identify unstaged/untracked files NOT modified by Claude +- Review conversation context to detect if session involved multiple distinct tasks (separate features, fixes, or refactorings discussed/implemented) + +## Step 2: Commit Strategy Questions + +If you detect multiple distinct tasks from conversation context, ask user using AskUserQuestion tool (both questions in same group): + +**Question 1** (always ask if multiple tasks detected): + +- "How should I commit these changes?" + - "Single commit" - Commit all changes together + - "Multiple logical commits" - Create separate commits for each distinct task/feature + +**Question 2** (ask ONLY if unstaged/untracked files exist that Claude didn't modify): + +- "There are uncommitted changes not made in this session. Include them?" + - "Yes, include all changes" - Stage and commit everything + - "No, only Claude's changes" - Commit only files Claude modified + - "Let me review first" - Show list of files and stop + +## Step 3: Create Commits + +**Commit Message Rules:** + +- **Style**: Concise, factual, savant-like. State what was done, not why (unless discussed during implementation) +- **Simple changes**: Title only (no description) +- **Complex changes**: Title + description + - Description adds context about what was changed + - Use facts, avoid self-praise adjectives ("improved", "optimized", "enhanced") + - Only state intents if explicitly discussed during implementation +- **Hard limit**: 80 words total +- **Format**: Always use heredoc for commit message +- **Footer**: Always append: + + ``` + + 🤖 Generated with [Claude Code](https://claude.com/claude-code) + + Co-Authored-By: Claude + ``` + +**Examples:** + +```bash +# Simple change +git commit -m "$(cat <<'EOF' +Add user authentication middleware + +🤖 Generated with [Claude Code](https://claude.com/claude-code) + +Co-Authored-By: Claude +EOF +)" + +# Complex change +git commit -m "$(cat <<'EOF' +Refactor database connection pooling + +Extracted connection logic into separate module. Added retry mechanism +for failed connections. Configured pool size based on environment variables. + +🤖 Generated with [Claude Code](https://claude.com/claude-code) + +Co-Authored-By: Claude +EOF +)" +``` + +If creating multiple logical commits: + +- Create commits in chronological order of implementation +- Each commit should be self-contained and logical +- Follow same message rules for each commit + +## Step 4: Push Branch + +Check if force-push is needed (`git status` shows diverged branch). + +**If force-push required**: Ask user for confirmation before proceeding. + +**Otherwise**: Auto-push with `git push -u origin ` + +**On push failure**: Explain error and ask if you should retry with alternative approach. + +## Step 5: Create Pull Request + +**PR Title**: Use title from commit message (if single commit) or summarize all commits (if multiple) + +**PR Description Rules:** + +- **Always include description** (even for simple changes) +- Same style as commit messages: factual, concise, savant-like +- For single commit: Expand on commit message with more context +- For multiple commits: List key changes made across commits +- Avoid self-praise language, state facts only +- **Hard limit**: 150 words +- **Footer**: Always append: + + ``` + + 🤖 Generated with [Claude Code](https://claude.com/claude-code) + ``` + +**PR Metadata:** + +- Auto-detect default branch (main/master) as base +- If `draft` parameter passed: add `--draft` flag +- No labels/reviewers unless user specifies + +**Create PR:** + +```bash +gh pr create --title "PR title" --body "$(cat <<'EOF' +PR description content here. + +🤖 Generated with [Claude Code](https://claude.com/claude-code) +EOF +)" [--draft] +``` + +**On PR creation failure**: Explain error and ask if you should retry with alternative approach. + +## Step 6: Open PR Page + +After successful PR creation, extract PR URL from `gh` output and open it: + +```bash +xdg-open +``` + +## Error Handling + +If any step fails: + +1. Explain what went wrong clearly +2. Provide the specific error message +3. Ask user if you should retry with an alternative approach +4. If user confirms, attempt automatic fix or provide manual commands + +## Final Output + +After successful completion, output: + +- Commit SHA(s) +- Branch name +- PR URL +- Confirmation that PR page was opened diff --git a/plugin.lock.json b/plugin.lock.json new file mode 100644 index 0000000..8c96883 --- /dev/null +++ b/plugin.lock.json @@ -0,0 +1,45 @@ +{ + "$schema": "internal://schemas/plugin.lock.v1.json", + "pluginId": "gh:andrzejsliwa/claude-code-marketplace:plugins/github", + "normalized": { + "repo": null, + "ref": "refs/tags/v20251128.0", + "commit": "30c3654d5f041a81204055fde2d21c874836fcef", + "treeHash": "8d9dfc5ac4cc292a10f0130783cc6e733e72252dda43ef7a72a1b1b8aa8d6f4d", + "generatedAt": "2025-11-28T10:13:43.465191Z", + "toolVersion": "publish_plugins.py@0.2.0" + }, + "origin": { + "remote": "git@github.com:zhongweili/42plugin-data.git", + "branch": "master", + "commit": "aa1497ed0949fd50e99e70d6324a29c5b34f9390", + "repoRoot": "/Users/zhongweili/projects/openmind/42plugin-data" + }, + "manifest": { + "name": "github", + "description": "AI-powered github tools", + "version": "1.0.0" + }, + "content": { + "files": [ + { + "path": "README.md", + "sha256": "9f2ef057bc0aaeaa46b909db7c1f2e7b10db0a3ea88e2ab44f4a3cd0a9094825" + }, + { + "path": ".claude-plugin/plugin.json", + "sha256": "c4f5be549498ca07a95521fd8e3e4f3637ab422c20887fe936b51e110e49ac5a" + }, + { + "path": "commands/open-pr.md", + "sha256": "0facce657fd8b330403e99170980766445d8587a9dc769ef3543f6f413da1dfd" + } + ], + "dirSha256": "8d9dfc5ac4cc292a10f0130783cc6e733e72252dda43ef7a72a1b1b8aa8d6f4d" + }, + "security": { + "scannedAt": null, + "scannerVersion": null, + "flags": [] + } +} \ No newline at end of file