|
| 1 | +--- |
| 2 | +sidebar_position: 6 |
| 3 | +--- |
| 4 | + |
| 5 | +# GitHub Action Integration |
| 6 | + |
| 7 | +MyCoder can be seamlessly integrated into your GitHub workflow through GitHub Actions, enabling powerful automation for your repositories. This guide focuses on the `issue-comment.yml` GitHub Action, which allows you to trigger MyCoder directly from issue or PR comments. |
| 8 | + |
| 9 | +## How It Works |
| 10 | + |
| 11 | +The `issue-comment.yml` GitHub Action monitors comments on issues and pull requests for a specific trigger phrase (typically `/mycoder`). When detected, it launches MyCoder with the context of the issue or PR, allowing it to: |
| 12 | + |
| 13 | +- Analyze and respond to issues |
| 14 | +- Implement requested features |
| 15 | +- Review pull requests |
| 16 | +- Generate documentation |
| 17 | +- Create new PRs with changes |
| 18 | +- And much more |
| 19 | + |
| 20 | +This integration creates a convenient, chat-like interface with MyCoder directly within your GitHub workflow. |
| 21 | + |
| 22 | +## Benefits |
| 23 | + |
| 24 | +- **Seamless Workflow Integration**: Interact with MyCoder without leaving GitHub |
| 25 | +- **Parallel Processing**: Run multiple MyCoder instances simultaneously on different tasks |
| 26 | +- **Contextual Understanding**: MyCoder has full access to the repository, issues, and PRs |
| 27 | +- **Automated Task Execution**: Trigger complex tasks with a simple comment |
| 28 | +- **Collaboration Enhancement**: AI assistance directly in your team's workflow |
| 29 | + |
| 30 | +## Setup Guide |
| 31 | + |
| 32 | +To add the MyCoder GitHub Action to your repository, create a file at `.github/workflows/issue-comment.yml` with the following configuration: |
| 33 | + |
| 34 | +```yaml |
| 35 | +name: MyCoder Issue Comment Action |
| 36 | + |
| 37 | +on: |
| 38 | + issue_comment: |
| 39 | + types: [created] |
| 40 | + |
| 41 | +# Top-level permissions for all jobs |
| 42 | +permissions: |
| 43 | + contents: write # Required for checkout, commit, push |
| 44 | + issues: write # Required for issue comments |
| 45 | + pull-requests: write # Required for creating PRs |
| 46 | + discussions: write # For interaction capabilities |
| 47 | + statuses: write # For creating commit statuses |
| 48 | + checks: write # For creating check runs |
| 49 | + actions: read # For inspecting workflow runs |
| 50 | + packages: read # In case you need to access GitHub packages |
| 51 | + |
| 52 | +env: |
| 53 | + PNPM_VERSION: 10.2.1 # Adjust based on your project requirements |
| 54 | + |
| 55 | +jobs: |
| 56 | + process-comment: |
| 57 | + runs-on: ubuntu-latest |
| 58 | + # Only run if comment contains '/mycoder' AND commenter is authorized |
| 59 | + if: | |
| 60 | + contains(github.event.comment.body, '/mycoder') && |
| 61 | + contains(fromJson('["username1", "username2"]'), github.event.comment.user.login) |
| 62 | + steps: |
| 63 | + - name: Extract prompt from comment |
| 64 | + id: extract-prompt |
| 65 | + run: | |
| 66 | + echo "comment_url=${{ github.event.comment.html_url }}" >> $GITHUB_OUTPUT |
| 67 | + echo "comment_id=${{ github.event.comment.id }}" >> $GITHUB_OUTPUT |
| 68 | +
|
| 69 | + - name: Checkout repository |
| 70 | + uses: actions/checkout@v3 |
| 71 | + |
| 72 | + - uses: actions/setup-node@v4 |
| 73 | + with: |
| 74 | + node-version-file: .nvmrc |
| 75 | + |
| 76 | + - uses: pnpm/action-setup@v2 |
| 77 | + with: |
| 78 | + version: ${{ env.PNPM_VERSION }} |
| 79 | + |
| 80 | + - name: Install dependencies |
| 81 | + run: pnpm install |
| 82 | + |
| 83 | + - name: Install browsers |
| 84 | + run: cd packages/agent && pnpm exec playwright install --with-deps chromium |
| 85 | + |
| 86 | + - name: Configure Git |
| 87 | + run: | |
| 88 | + git config --global user.name "Your Name (via MyCoder)" |
| 89 | + git config --global user.email "[email protected]" |
| 90 | +
|
| 91 | + - run: |
| 92 | + pnpm install -g mycoder |
| 93 | + |
| 94 | + # Auth GitHub CLI with the token |
| 95 | + - name: Configure GitHub CLI |
| 96 | + run: | |
| 97 | + echo "${{ secrets.GH_PAT }}" | gh auth login --with-token |
| 98 | + # Verify auth status |
| 99 | + gh auth status |
| 100 | +
|
| 101 | + - env: |
| 102 | + ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} |
| 103 | + run: | |
| 104 | + echo "Running MyCoder for issue #${{ github.event.issue.number }}" |
| 105 | + mycoder --userWarning false --upgradeCheck false --githubMode true --userPrompt false "On issue #${{ github.event.issue.number }} in comment ${{ steps.extract-prompt.outputs.comment_url }} the user invoked the mycoder CLI via /mycoder. Can you try to do what they requested or if it is unclear, respond with a comment to that effect to encourage them to be more clear." |
| 106 | +``` |
| 107 | +
|
| 108 | +## Best Practices |
| 109 | +
|
| 110 | +### Security Considerations |
| 111 | +
|
| 112 | +:::caution Important Security Warning |
| 113 | +Only allow trusted individuals to trigger MyCoder via comments. With full repository access, MyCoder could potentially make significant changes if instructed maliciously. |
| 114 | +::: |
| 115 | +
|
| 116 | +Restrict execution by specifying authorized users: |
| 117 | +
|
| 118 | +```yaml |
| 119 | +if: | |
| 120 | + contains(github.event.comment.body, '/mycoder') && |
| 121 | + contains(fromJson('["trusted-user1", "trusted-user2"]'), github.event.comment.user.login) |
| 122 | +``` |
| 123 | +
|
| 124 | +For open source projects, be especially careful about who can trigger automated workflows. |
| 125 | +
|
| 126 | +### Using Personal Access Tokens |
| 127 | +
|
| 128 | +While GitHub Actions provides a built-in `GITHUB_TOKEN`, using a Personal Access Token (PAT) is recommended: |
| 129 | + |
| 130 | +- **Why**: Using a PAT preserves standard CI behavior on submitted PRs |
| 131 | +- **How**: Store your PAT as a repository secret (`GH_PAT`) and reference it in the workflow |
| 132 | + |
| 133 | +```yaml |
| 134 | +- name: Configure GitHub CLI |
| 135 | + run: | |
| 136 | + echo "${{ secrets.GH_PAT }}" | gh auth login --with-token |
| 137 | +``` |
| 138 | + |
| 139 | +### Disable User Prompts |
| 140 | + |
| 141 | +Always run MyCoder with user prompts disabled in GitHub Actions: |
| 142 | + |
| 143 | +```bash |
| 144 | +mycoder --userPrompt false |
| 145 | +``` |
| 146 | + |
| 147 | +This prevents the workflow from hanging indefinitely waiting for user input. |
| 148 | + |
| 149 | +### Git Configuration |
| 150 | + |
| 151 | +Configure Git with appropriate user information for commits made by MyCoder: |
| 152 | + |
| 153 | +```yaml |
| 154 | +- name: Configure Git |
| 155 | + run: | |
| 156 | + git config --global user.name "Your Name (via MyCoder)" |
| 157 | + git config --global user.email "[email protected]" |
| 158 | +``` |
| 159 | + |
| 160 | +This clearly identifies commits made automatically by MyCoder. |
| 161 | + |
| 162 | +## Usage Examples |
| 163 | + |
| 164 | +### Trigger MyCoder on an Issue |
| 165 | + |
| 166 | +Comment on any issue with: |
| 167 | + |
| 168 | +``` |
| 169 | +/mycoder Please analyze this issue and suggest a solution. |
| 170 | +``` |
| 171 | + |
| 172 | +### Request Documentation |
| 173 | + |
| 174 | +``` |
| 175 | +/mycoder Please create documentation for the recently added feature XYZ. |
| 176 | +``` |
| 177 | +
|
| 178 | +### Code Review |
| 179 | +
|
| 180 | +``` |
| 181 | +/mycoder Please review this PR and suggest improvements. |
| 182 | +``` |
| 183 | +
|
| 184 | +### Feature Implementation |
| 185 | +
|
| 186 | +``` |
| 187 | +/mycoder Please implement the feature described in this issue and create a PR. |
| 188 | +``` |
| 189 | +
|
| 190 | +## Troubleshooting |
| 191 | +
|
| 192 | +If you encounter issues with the GitHub Action: |
| 193 | +
|
| 194 | +1. Check the Action logs for error messages |
| 195 | +2. Verify that all required secrets are properly configured |
| 196 | +3. Ensure the permissions are correctly set |
| 197 | +4. Confirm that the commenter is in the authorized users list |
| 198 | +
|
| 199 | +## Conclusion |
| 200 | +
|
| 201 | +The MyCoder GitHub Action integration provides a powerful way to incorporate AI assistance directly into your development workflow. By following the best practices outlined above, you can safely leverage MyCoder to enhance productivity and collaboration within your GitHub repositories. |
0 commit comments