|
| 1 | +# GitHub Copilot CLI Examples |
| 2 | + |
| 3 | +This directory contains practical examples and templates for integrating GitHub Copilot CLI into your development workflow. |
| 4 | + |
| 5 | +## Directory Structure |
| 6 | + |
| 7 | +``` |
| 8 | +examples/ |
| 9 | +├── mcp-configs/ # MCP server configuration examples |
| 10 | +├── scripts/ # Shell scripts for automation |
| 11 | +├── workflows/ # CI/CD workflow examples |
| 12 | +└── README.md # This file |
| 13 | +``` |
| 14 | + |
| 15 | +## MCP Configurations |
| 16 | + |
| 17 | +Located in `mcp-configs/`: |
| 18 | + |
| 19 | +- **`basic-mcp-config.json`** - Basic setup with filesystem, GitHub, and Git MCP servers |
| 20 | +- **`advanced-mcp-config.json`** - Advanced setup with database, search, and communication integrations |
| 21 | +- **`development-mcp-config.json`** - Development-focused configuration with limited GitHub tools |
| 22 | + |
| 23 | +### Usage |
| 24 | + |
| 25 | +Copy a configuration file to your home directory: |
| 26 | + |
| 27 | +```bash |
| 28 | +# For system-wide configuration |
| 29 | +cp examples/mcp-configs/basic-mcp-config.json ~/.copilot/mcp-config.json |
| 30 | + |
| 31 | +# For project-specific configuration |
| 32 | +cp examples/mcp-configs/development-mcp-config.json .copilot/mcp-config.json |
| 33 | +``` |
| 34 | + |
| 35 | +Don't forget to set required environment variables: |
| 36 | + |
| 37 | +```bash |
| 38 | +export GITHUB_TOKEN="your-token" |
| 39 | +export WORKSPACE="$(pwd)" |
| 40 | +``` |
| 41 | + |
| 42 | +## Scripts |
| 43 | + |
| 44 | +Located in `scripts/`: |
| 45 | + |
| 46 | +### Code Review Script |
| 47 | + |
| 48 | +**`copilot-review.sh`** - Review code files or directories for issues |
| 49 | + |
| 50 | +```bash |
| 51 | +# Make executable |
| 52 | +chmod +x examples/scripts/copilot-review.sh |
| 53 | + |
| 54 | +# Review a single file |
| 55 | +./examples/scripts/copilot-review.sh src/utils.js |
| 56 | + |
| 57 | +# Review entire directory |
| 58 | +./examples/scripts/copilot-review.sh src/ |
| 59 | +``` |
| 60 | + |
| 61 | +### Commit Message Generator |
| 62 | + |
| 63 | +**`generate-commit-message.sh`** - Generate conventional commit messages |
| 64 | + |
| 65 | +```bash |
| 66 | +# Make executable |
| 67 | +chmod +x examples/scripts/generate-commit-message.sh |
| 68 | + |
| 69 | +# Stage your changes |
| 70 | +git add . |
| 71 | + |
| 72 | +# Generate and commit |
| 73 | +./examples/scripts/generate-commit-message.sh |
| 74 | +``` |
| 75 | + |
| 76 | +### Test Generator |
| 77 | + |
| 78 | +**`generate-tests.sh`** - Generate unit tests for source files |
| 79 | + |
| 80 | +```bash |
| 81 | +# Make executable |
| 82 | +chmod +x examples/scripts/generate-tests.sh |
| 83 | + |
| 84 | +# Generate tests |
| 85 | +./examples/scripts/generate-tests.sh src/utils.js |
| 86 | +# Creates: src/utils.test.js |
| 87 | + |
| 88 | +./examples/scripts/generate-tests.sh lib/parser.py |
| 89 | +# Creates: lib/parser_test.py |
| 90 | +``` |
| 91 | + |
| 92 | +Supports: |
| 93 | +- JavaScript (`.js`) → Jest |
| 94 | +- TypeScript (`.ts`) → Jest |
| 95 | +- React (`.jsx`, `.tsx`) → React Testing Library |
| 96 | +- Python (`.py`) → pytest |
| 97 | +- Go (`.go`) → Go testing |
| 98 | +- Rust (`.rs`) → Rust testing |
| 99 | +- Java (`.java`) → JUnit 5 |
| 100 | + |
| 101 | +### Documentation Generator |
| 102 | + |
| 103 | +**`generate-docs.sh`** - Generate API documentation |
| 104 | + |
| 105 | +```bash |
| 106 | +# Make executable |
| 107 | +chmod +x examples/scripts/generate-docs.sh |
| 108 | + |
| 109 | +# Generate docs for single file |
| 110 | +./examples/scripts/generate-docs.sh src/utils.js |
| 111 | + |
| 112 | +# Generate docs for directory |
| 113 | +./examples/scripts/generate-docs.sh src/ docs/api |
| 114 | +``` |
| 115 | + |
| 116 | +## Workflows |
| 117 | + |
| 118 | +Located in `workflows/`: |
| 119 | + |
| 120 | +### GitHub Actions |
| 121 | + |
| 122 | +**`github-actions-review.yml`** - Automated PR reviews |
| 123 | + |
| 124 | +Copy to your repository: |
| 125 | + |
| 126 | +```bash |
| 127 | +cp examples/workflows/github-actions-review.yml .github/workflows/ |
| 128 | +``` |
| 129 | + |
| 130 | +Requires: |
| 131 | +- GitHub token with Copilot access (automatically provided) |
| 132 | +- PR permissions (configured in workflow) |
| 133 | + |
| 134 | +### GitLab CI |
| 135 | + |
| 136 | +**`gitlab-ci-review.yml`** - Automated MR reviews |
| 137 | + |
| 138 | +Copy to your repository: |
| 139 | + |
| 140 | +```bash |
| 141 | +cp examples/workflows/gitlab-ci-review.yml .gitlab-ci.yml |
| 142 | +``` |
| 143 | + |
| 144 | +Or merge with existing `.gitlab-ci.yml`: |
| 145 | + |
| 146 | +```yaml |
| 147 | +include: |
| 148 | + - local: examples/workflows/gitlab-ci-review.yml |
| 149 | +``` |
| 150 | +
|
| 151 | +Requires: |
| 152 | +- `COPILOT_GITHUB_TOKEN` variable (with Copilot access) |
| 153 | +- `GITLAB_TOKEN` variable (optional, for posting comments) |
| 154 | + |
| 155 | +## Quick Start |
| 156 | + |
| 157 | +1. **Install Copilot CLI**: |
| 158 | + ```bash |
| 159 | + npm install -g @github/copilot |
| 160 | + ``` |
| 161 | + |
| 162 | +2. **Set up authentication**: |
| 163 | + ```bash |
| 164 | + export GITHUB_TOKEN="your-personal-access-token" |
| 165 | + ``` |
| 166 | + |
| 167 | +3. **Copy and customize MCP config**: |
| 168 | + ```bash |
| 169 | + mkdir -p ~/.copilot |
| 170 | + cp examples/mcp-configs/basic-mcp-config.json ~/.copilot/mcp-config.json |
| 171 | + ``` |
| 172 | + |
| 173 | +4. **Make scripts executable**: |
| 174 | + ```bash |
| 175 | + chmod +x examples/scripts/*.sh |
| 176 | + ``` |
| 177 | + |
| 178 | +5. **Test it out**: |
| 179 | + ```bash |
| 180 | + # Review a file |
| 181 | + ./examples/scripts/copilot-review.sh README.md |
| 182 | + ``` |
| 183 | + |
| 184 | +## Environment Variables |
| 185 | + |
| 186 | +Scripts and workflows use these environment variables: |
| 187 | + |
| 188 | +| Variable | Description | Required | |
| 189 | +|----------|-------------|----------| |
| 190 | +| `GITHUB_TOKEN` | GitHub personal access token with Copilot access | Yes | |
| 191 | +| `WORKSPACE` | Current workspace/project directory | No (defaults to pwd) | |
| 192 | +| `COPILOT_MODEL` | Model to use (e.g., claude-sonnet-4.5) | No | |
| 193 | +| `PGUSER` | PostgreSQL username (for postgres MCP) | If using postgres | |
| 194 | +| `PGPASSWORD` | PostgreSQL password (for postgres MCP) | If using postgres | |
| 195 | +| `BRAVE_API_KEY` | Brave Search API key (for search MCP) | If using Brave Search | |
| 196 | +| `SLACK_BOT_TOKEN` | Slack bot token (for Slack MCP) | If using Slack | |
| 197 | +| `SLACK_TEAM_ID` | Slack team ID (for Slack MCP) | If using Slack | |
| 198 | + |
| 199 | +## Best Practices |
| 200 | + |
| 201 | +1. **Start Simple**: Begin with `basic-mcp-config.json` and add servers as needed |
| 202 | +2. **Secure Tokens**: Never commit tokens to version control; use environment variables |
| 203 | +3. **Test Scripts**: Review generated code/tests/docs before using in production |
| 204 | +4. **Customize Prompts**: Adjust prompts in scripts to match your team's standards |
| 205 | +5. **CI/CD Integration**: Make CI checks advisory, not blocking, initially |
| 206 | + |
| 207 | +## Troubleshooting |
| 208 | + |
| 209 | +### MCP servers not connecting |
| 210 | + |
| 211 | +```bash |
| 212 | +# Check if executables are in PATH |
| 213 | +which npx |
| 214 | +
|
| 215 | +# Test server startup manually |
| 216 | +npx -y @modelcontextprotocol/server-filesystem ~/projects |
| 217 | +
|
| 218 | +# Check Copilot logs |
| 219 | +COPILOT_DEBUG=true copilot |
| 220 | +``` |
| 221 | + |
| 222 | +### Scripts not working |
| 223 | + |
| 224 | +```bash |
| 225 | +# Ensure scripts are executable |
| 226 | +chmod +x examples/scripts/*.sh |
| 227 | +
|
| 228 | +# Check Copilot is installed |
| 229 | +copilot --version |
| 230 | +
|
| 231 | +# Verify authentication |
| 232 | +echo $GITHUB_TOKEN |
| 233 | +``` |
| 234 | + |
| 235 | +### Workflow failures |
| 236 | + |
| 237 | +- Check GitHub token has Copilot access |
| 238 | +- Verify token permissions in repository secrets |
| 239 | +- Review workflow logs for specific errors |
| 240 | + |
| 241 | +## Contributing |
| 242 | + |
| 243 | +Have a useful script or configuration? Contributions are welcome! |
| 244 | + |
| 245 | +1. Add your example with clear comments |
| 246 | +2. Update this README with usage instructions |
| 247 | +3. Test thoroughly before submitting |
| 248 | + |
| 249 | +## Additional Resources |
| 250 | + |
| 251 | +- [Integration Guide](../INTEGRATION.md) - Comprehensive integration documentation |
| 252 | +- [Official Docs](https://docs.github.com/copilot/concepts/agents/about-copilot-cli) |
| 253 | +- [MCP Specification](https://modelcontextprotocol.io/) |
| 254 | + |
| 255 | +## Support |
| 256 | + |
| 257 | +For issues or questions: |
| 258 | +- [GitHub Copilot CLI Issues](https://github.com/github/copilot-cli/issues) |
| 259 | +- [Community Discussions](https://github.com/github/copilot-cli/discussions) |
0 commit comments