diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e44ffae..11f8a09 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -39,6 +39,9 @@ jobs: run: cd packages/agent && pnpm exec playwright install --with-deps chromium - name: Test + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} run: pnpm test - name: Lint diff --git a/.github/workflows/issue-comment.yml b/.github/workflows/issue-comment.yml new file mode 100644 index 0000000..4015c38 --- /dev/null +++ b/.github/workflows/issue-comment.yml @@ -0,0 +1,62 @@ +name: MyCoder Issue Comment Action + +on: + issue_comment: + types: [created] + +permissions: + contents: write + issues: write + pull-requests: write + +env: + PNPM_VERSION: 10.2.1 + +jobs: + process-comment: + runs-on: ubuntu-latest + if: contains(github.event.comment.body, '/mycoder') + steps: + - name: Extract prompt from comment + id: extract-prompt + run: | + COMMENT="${{ github.event.comment.body }}" + if [[ "$COMMENT" =~ "/mycoder "(.+) ]]; then + PROMPT="${BASH_REMATCH[1]}" + elif [[ "$COMMENT" =~ "/mycoder" ]]; then + # If just /mycoder with no text after, use a default prompt + PROMPT="Please review this issue and suggest next steps." + else + echo "No valid /mycoder command found" + exit 1 + fi + echo "prompt=$PROMPT" >> $GITHUB_OUTPUT + echo "comment_url=${{ github.event.comment.html_url }}" >> $GITHUB_OUTPUT + echo "comment_id=${{ github.event.comment.id }}" >> $GITHUB_OUTPUT + + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Set up pnpm + uses: pnpm/action-setup@v2 + with: + version: ${{ env.PNPM_VERSION }} + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version-file: .nvmrc + cache: 'pnpm' + + - name: Install MyCoder globally + run: | + # Skip tests when installing globally + pnpm install -g mycoder --no-frozen-lockfile --ignore-scripts + + - name: Run MyCoder with prompt + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} + run: | + echo "Running MyCoder for issue #${{ github.event.issue.number }} with prompt: ${{ steps.extract-prompt.outputs.prompt }}" + mycoder --githubMode true --userPrompt false "On issue #${{ github.event.issue.number }} the user asked: '${{ steps.extract-prompt.outputs.prompt }}' in comment ${{ steps.extract-prompt.outputs.comment_url }}. Please address this request. If you create a PR or take actions outside the scope of this issue, please report back to the issue with a comment explaining what you did." \ No newline at end of file diff --git a/README.md b/README.md index f4f2365..56cf4c5 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,21 @@ mycoder -f prompt.txt mycoder config set githubMode true ``` +### GitHub Comment Commands + +MyCoder can be triggered directly from GitHub issue comments using the flexible `/mycoder` command: + +``` +/mycoder [your instructions here] +``` + +Examples: +- `/mycoder implement a PR for this issue` +- `/mycoder create an implementation plan` +- `/mycoder suggest test cases for this feature` + +[Learn more about GitHub comment commands](docs/github-comment-commands.md) + ## Packages - [mycoder](packages/cli) - Command-line interface for MyCoder diff --git a/docs/github-comment-commands.md b/docs/github-comment-commands.md new file mode 100644 index 0000000..531fac6 --- /dev/null +++ b/docs/github-comment-commands.md @@ -0,0 +1,80 @@ +# GitHub Comment Commands + +MyCoder provides automated actions in response to `/mycoder` commands in GitHub issue comments. This feature allows you to trigger MyCoder directly from GitHub issues with flexible prompts. + +## How to Use + +Simply add a comment to any GitHub issue with `/mycoder` followed by your instructions: + +``` +/mycoder [your instructions here] +``` + +MyCoder will process your instructions in the context of the issue and respond accordingly. + +## Examples + +### Creating a PR + +``` +/mycoder implement a PR for this issue +``` + +MyCoder will: +1. Check out the repository +2. Review the issue details +3. Implement a solution according to the requirements +4. Create a pull request that addresses the issue + +### Creating an Implementation Plan + +``` +/mycoder create an implementation plan for this issue +``` + +MyCoder will: +1. Review the issue details +2. Create a comprehensive implementation plan +3. Post the plan as a comment on the issue + +### Other Use Cases + +The `/mycoder` command is flexible and can handle various requests: + +``` +/mycoder suggest test cases for this feature +``` + +``` +/mycoder analyze the performance implications of this change +``` + +``` +/mycoder recommend libraries we could use for this implementation +``` + +## How It Works + +This functionality is implemented as a GitHub Action that runs whenever a new comment is added to an issue. The action checks for the `/mycoder` command pattern and triggers MyCoder with the appropriate instructions. + +MyCoder receives context about: +- The issue number +- The specific prompt you provided +- The comment URL where the command was triggered + +If MyCoder creates a PR or takes actions outside the scope of the issue, it will report back to the issue with a comment explaining what was done. + +## Requirements + +For this feature to work in your repository: + +1. The GitHub Action workflow must be present in your repository +2. You need to configure the necessary API keys as GitHub secrets: + - `GITHUB_TOKEN` (automatically provided) + - `ANTHROPIC_API_KEY`, `OPENAI_API_KEY`, `XAI_API_KEY`, or `MISTRAL_API_KEY` (depending on your preferred model) + +## Limitations + +- The action runs with GitHub's default timeout limits +- Complex implementations may require multiple iterations +- The AI model's capabilities determine the quality of the results \ No newline at end of file