diff --git a/INTEGRATION.md b/INTEGRATION.md new file mode 100644 index 00000000..8942b503 --- /dev/null +++ b/INTEGRATION.md @@ -0,0 +1,585 @@ +# GitHub Copilot CLI Integration Guide + +This guide provides comprehensive instructions for integrating GitHub Copilot CLI with various tools, environments, and workflows. + +## Table of Contents + +- [Terminal Integration](#terminal-integration) +- [VS Code Integration](#vs-code-integration) +- [MCP Server Configuration](#mcp-server-configuration) +- [Shell Completions](#shell-completions) +- [Git Hooks Integration](#git-hooks-integration) +- [CI/CD Integration](#cicd-integration) +- [Custom Workflows](#custom-workflows) + +--- + +## Terminal Integration + +### Bash + +Add to your `~/.bashrc` or `~/.bash_profile`: + +```bash +# GitHub Copilot CLI alias +alias ai='copilot' + +# Quick prompt mode +alias aip='copilot -p' + +# Enable terminal integration +eval "$(copilot /terminal-setup bash)" +``` + +### Zsh + +Add to your `~/.zshrc`: + +```zsh +# GitHub Copilot CLI alias +alias ai='copilot' + +# Quick prompt mode +alias aip='copilot -p' + +# Enable terminal integration +eval "$(copilot /terminal-setup zsh)" +``` + +### PowerShell + +Add to your PowerShell profile (`$PROFILE`): + +```powershell +# GitHub Copilot CLI alias +Set-Alias -Name ai -Value copilot + +# Quick prompt mode +function aip { copilot -p $args } + +# Enable terminal integration +Invoke-Expression (copilot /terminal-setup powershell) +``` + +### Fish + +Add to your `~/.config/fish/config.fish`: + +```fish +# GitHub Copilot CLI alias +alias ai='copilot' +alias aip='copilot -p' + +# Enable terminal integration +copilot /terminal-setup fish | source +``` + +--- + +## VS Code Integration + +### MCP Configuration Sharing + +Copilot CLI can leverage VS Code's MCP configuration. Create or update `~/.vscode/mcp.json`: + +```json +{ + "mcpServers": { + "filesystem": { + "type": "local", + "command": "npx", + "args": ["-y", "@modelcontextprotocol/server-filesystem", "/path/to/project"] + }, + "github": { + "type": "local", + "command": "npx", + "args": ["-y", "@modelcontextprotocol/server-github"], + "env": { + "GITHUB_TOKEN": "${GITHUB_TOKEN}" + } + } + } +} +``` + +### Workspace Integration + +In your VS Code workspace settings (`.vscode/settings.json`): + +```json +{ + "terminal.integrated.env.linux": { + "COPILOT_WORKSPACE": "${workspaceFolder}" + }, + "terminal.integrated.env.osx": { + "COPILOT_WORKSPACE": "${workspaceFolder}" + }, + "terminal.integrated.env.windows": { + "COPILOT_WORKSPACE": "${workspaceFolder}" + } +} +``` + +--- + +## MCP Server Configuration + +### Local Configuration + +Create `~/.copilot/mcp-config.json`: + +```json +{ + "mcpServers": { + "filesystem": { + "type": "local", + "command": "npx", + "args": ["-y", "@modelcontextprotocol/server-filesystem", "${HOME}/projects"], + "tools": ["*"] + }, + "git": { + "type": "local", + "command": "npx", + "args": ["-y", "@modelcontextprotocol/server-git"], + "tools": ["*"] + }, + "postgres": { + "type": "local", + "command": "npx", + "args": ["-y", "@modelcontextprotocol/server-postgres", "postgresql://localhost/mydb"], + "tools": ["*"] + }, + "sequential-thinking": { + "type": "local", + "command": "npx", + "args": ["-y", "@modelcontextprotocol/server-sequential-thinking"], + "tools": ["*"] + } + } +} +``` + +### Project-Specific Configuration + +Create `.copilot/mcp-config.json` in your project root: + +```json +{ + "mcpServers": { + "project-specific": { + "type": "local", + "command": "node", + "args": ["./tools/mcp-server.js"], + "tools": ["*"] + } + } +} +``` + +### Runtime Configuration + +Pass MCP configuration at runtime: + +```bash +# Inline JSON +copilot --additional-mcp-config '{"mcpServers": {"my-tool": {...}}}' + +# From file +copilot --additional-mcp-config @/path/to/config.json + +# Multiple configurations (later values override earlier ones) +copilot --additional-mcp-config @base.json --additional-mcp-config @overrides.json +``` + +--- + +## Shell Completions + +### Installing Completions + +For Bash, add to `~/.bashrc`: + +```bash +# Basic command completion +complete -C copilot copilot +``` + +For Zsh, add to `~/.zshrc`: + +```zsh +# Enable completion system +autoload -Uz compinit && compinit + +# Basic command completion +compdef _gnu_generic copilot +``` + +For PowerShell, add to your `$PROFILE`: + +```powershell +# Basic command completion +Register-ArgumentCompleter -Native -CommandName copilot -ScriptBlock { + param($wordToComplete, $commandAst, $cursorPosition) + copilot --help | Select-String "^\s*--" | ForEach-Object { + $_.Line.Trim() -split '\s+' | Select-Object -First 1 + } | Where-Object { $_ -like "$wordToComplete*" } +} +``` + +--- + +## Git Hooks Integration + +### Pre-commit Hook + +Create `.git/hooks/pre-commit`: + +```bash +#!/bin/bash + +# Use Copilot to review staged changes +echo "Running Copilot pre-commit review..." +git diff --cached | copilot -p "Review these changes for potential issues, security vulnerabilities, and code quality. Be concise." + +# Exit code doesn't block commit, just provides feedback +exit 0 +``` + +Make it executable: + +```bash +chmod +x .git/hooks/pre-commit +``` + +### Commit Message Hook + +Create `.git/hooks/prepare-commit-msg`: + +```bash +#!/bin/bash + +COMMIT_MSG_FILE=$1 +COMMIT_SOURCE=$2 + +# Only generate message for regular commits (not amend, merge, etc.) +if [ -z "$COMMIT_SOURCE" ]; then + # Get staged changes + DIFF=$(git diff --cached) + + # Generate commit message using Copilot + if [ -n "$DIFF" ]; then + MESSAGE=$(echo "$DIFF" | copilot -p "Generate a concise, conventional commit message for these changes. Use format: type(scope): description") + + # Prepend generated message to commit file + echo "$MESSAGE" > "$COMMIT_MSG_FILE.tmp" + echo "" >> "$COMMIT_MSG_FILE.tmp" + cat "$COMMIT_MSG_FILE" >> "$COMMIT_MSG_FILE.tmp" + mv "$COMMIT_MSG_FILE.tmp" "$COMMIT_MSG_FILE" + fi +fi +``` + +Make it executable: + +```bash +chmod +x .git/hooks/prepare-commit-msg +``` + +--- + +## CI/CD Integration + +### GitHub Actions + +Create `.github/workflows/copilot-review.yml`: + +```yaml +name: Copilot Code Review + +on: + pull_request: + types: [opened, synchronize] + +jobs: + review: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: '22' + + - name: Install Copilot CLI + run: npm install -g @github/copilot + + - name: Review Changes + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + # Get PR diff + git diff origin/${{ github.base_ref }}...HEAD > pr_diff.txt + + # Review with Copilot + copilot -p "Review this PR for code quality, security issues, and best practices. Provide specific, actionable feedback." < pr_diff.txt > review.txt + + # Post as comment (requires gh CLI) + gh pr comment ${{ github.event.pull_request.number }} --body-file review.txt +``` + +### GitLab CI + +Create `.gitlab-ci.yml`: + +```yaml +copilot-review: + stage: review + image: node:22 + before_script: + - npm install -g @github/copilot + script: + - git diff $CI_MERGE_REQUEST_TARGET_BRANCH_SHA...$CI_COMMIT_SHA > mr_diff.txt + - copilot -p "Review these changes for quality and security issues" < mr_diff.txt > review.txt + - cat review.txt + only: + - merge_requests + variables: + GITHUB_TOKEN: $COPILOT_TOKEN +``` + +### Jenkins Pipeline + +Create `Jenkinsfile`: + +```groovy +pipeline { + agent any + + environment { + GITHUB_TOKEN = credentials('github-token') + } + + stages { + stage('Setup') { + steps { + sh 'npm install -g @github/copilot' + } + } + + stage('Code Review') { + steps { + sh ''' + git diff ${GIT_PREVIOUS_COMMIT}..${GIT_COMMIT} > changes.txt + copilot -p "Review these changes for issues" < changes.txt > review.txt + cat review.txt + ''' + } + } + } +} +``` + +--- + +## Custom Workflows + +### Code Review Automation + +Create `scripts/copilot-review.sh`: + +```bash +#!/bin/bash + +# Review specific files or directories +TARGET=${1:-.} + +echo "Reviewing: $TARGET" + +# For files +if [ -f "$TARGET" ]; then + cat "$TARGET" | copilot -p "Review this code for quality, security, and best practices. Be specific and actionable." + exit 0 +fi + +# For directories +if [ -d "$TARGET" ]; then + find "$TARGET" -type f \( -name "*.js" -o -name "*.ts" -o -name "*.py" -o -name "*.go" \) | while read file; do + echo "=== Reviewing: $file ===" + cat "$file" | copilot -p "Quick security and quality review. Flag only critical issues." + echo "" + done +fi +``` + +### Documentation Generation + +Create `scripts/generate-docs.sh`: + +```bash +#!/bin/bash + +# Generate documentation for source files +SOURCE_DIR=${1:-src} +DOCS_DIR=${2:-docs} + +mkdir -p "$DOCS_DIR" + +find "$SOURCE_DIR" -type f \( -name "*.js" -o -name "*.ts" -o -name "*.py" \) | while read file; do + filename=$(basename "$file") + doc_file="$DOCS_DIR/${filename%.*}.md" + + echo "Generating docs for: $file" + cat "$file" | copilot -p "Generate comprehensive documentation for this code. Include function descriptions, parameters, return values, and usage examples in Markdown format." > "$doc_file" +done + +echo "Documentation generated in: $DOCS_DIR" +``` + +### Test Generation + +Create `scripts/generate-tests.sh`: + +```bash +#!/bin/bash + +# Generate tests for source files +SOURCE_FILE=$1 + +if [ -z "$SOURCE_FILE" ]; then + echo "Usage: $0 " + exit 1 +fi + +# Determine test file path +case "$SOURCE_FILE" in + *.js) TEST_FILE="${SOURCE_FILE%.js}.test.js" ;; + *.ts) TEST_FILE="${SOURCE_FILE%.ts}.test.ts" ;; + *.py) TEST_FILE="${SOURCE_FILE%.py}_test.py" ;; + *) echo "Unsupported file type"; exit 1 ;; +esac + +echo "Generating tests for: $SOURCE_FILE" +echo "Output: $TEST_FILE" + +cat "$SOURCE_FILE" | copilot -p "Generate comprehensive unit tests for this code. Include edge cases, error handling, and integration scenarios. Use appropriate testing framework for the language." > "$TEST_FILE" + +echo "Tests generated: $TEST_FILE" +``` + +### Refactoring Assistant + +Create `scripts/refactor-code.sh`: + +```bash +#!/bin/bash + +FILE=$1 +GOAL=${2:-"improve code quality and maintainability"} + +if [ -z "$FILE" ]; then + echo "Usage: $0 [goal]" + exit 1 +fi + +echo "Refactoring: $FILE" +echo "Goal: $GOAL" + +# Backup original +cp "$FILE" "$FILE.backup" + +# Generate refactored version +cat "$FILE" | copilot -p "Refactor this code to $GOAL. Maintain functionality but improve structure, readability, and performance. Provide only the refactored code." > "$FILE.new" + +# Show diff +echo "=== Changes ===" +diff -u "$FILE" "$FILE.new" + +echo "" +echo "Review the changes above." +echo "To apply: mv $FILE.new $FILE" +echo "To revert: mv $FILE.backup $FILE" +``` + +--- + +## Environment Variables + +Copilot CLI recognizes these environment variables: + +```bash +# Authentication +export GITHUB_TOKEN="your-token-here" +export GH_TOKEN="your-token-here" # Alternative + +# Configuration +export COPILOT_WORKSPACE="/path/to/workspace" +export COPILOT_MODEL="claude-sonnet-4.5" # Default model + +# MCP Configuration +export COPILOT_MCP_CONFIG="/path/to/mcp-config.json" + +# Behavior +export COPILOT_STREAM="on" # Enable streaming +export COPILOT_DEBUG="true" # Enable debug logging +``` + +--- + +## Troubleshooting + +### MCP Server Issues + +If MCP tools are not visible: + +1. Verify MCP configuration file location: `~/.copilot/mcp-config.json` +2. Check server executables are in PATH: `which npx`, `which uvx` +3. Test server startup manually: `npx -y @modelcontextprotocol/server-filesystem` +4. Check server processes: `ps aux | grep mcp` +5. Enable debug logging: `COPILOT_DEBUG=true copilot` + +### Authentication Issues + +If authentication fails: + +1. Verify token is set: `echo $GITHUB_TOKEN` +2. Check token permissions at: https://github.com/settings/tokens +3. Ensure "Copilot Requests" permission is enabled +4. Try re-authenticating: `/login` command in Copilot CLI + +### Performance Issues + +If Copilot is slow: + +1. Reduce context size by limiting file access +2. Disable unnecessary MCP servers +3. Use `--stream off` if streaming causes issues +4. Check network connectivity +5. Verify system resources (RAM, CPU) + +--- + +## Best Practices + +1. **Use Project-Specific Configuration**: Keep MCP configs in project root +2. **Secure Tokens**: Never commit tokens to version control +3. **Limit Tool Access**: Only enable MCP tools you need (`tools: ["specific-tool"]`) +4. **Version Control Hooks**: Make hooks non-blocking (always exit 0) +5. **CI/CD Integration**: Use read-only operations in CI pipelines +6. **Regular Updates**: Keep Copilot CLI updated: `npm update -g @github/copilot` + +--- + +## Additional Resources + +- [Official Documentation](https://docs.github.com/copilot/concepts/agents/about-copilot-cli) +- [MCP Specification](https://modelcontextprotocol.io/) +- [GitHub CLI](https://cli.github.com/) +- [Community Discussions](https://github.com/github/copilot-cli/discussions) + +--- + +For issues or feature requests, visit: https://github.com/github/copilot-cli/issues diff --git a/README.md b/README.md index 04a0bcab..28e86d41 100644 --- a/README.md +++ b/README.md @@ -73,6 +73,19 @@ Each time you submit a prompt to GitHub Copilot CLI, your monthly quota of premi For more information about how to use the GitHub Copilot CLI, see [our official documentation](https://docs.github.com/copilot/concepts/agents/about-copilot-cli). +## ๐Ÿ”ง Integration + +Looking to integrate Copilot CLI into your development workflow? Check out our comprehensive resources: + +- **[Integration Guide](INTEGRATION.md)** - Detailed instructions for terminal, VS Code, MCP servers, Git hooks, and CI/CD integration +- **[Examples Directory](examples/)** - Ready-to-use scripts, configurations, and workflow templates + +Quick start integrations: + +- **Terminal Setup**: Run `/terminal-setup` in Copilot CLI to set up shell integration +- **MCP Servers**: Configure custom tools via `~/.copilot/mcp-config.json` ([examples](examples/mcp-configs/)) +- **Automation Scripts**: Use our [example scripts](examples/scripts/) for code review, test generation, and more +- **CI/CD**: Add automated reviews with our [GitHub Actions](examples/workflows/github-actions-review.yml) or [GitLab CI](examples/workflows/gitlab-ci-review.yml) templates ## ๐Ÿ“ข Feedback and Participation diff --git a/examples/README.md b/examples/README.md new file mode 100644 index 00000000..69b92491 --- /dev/null +++ b/examples/README.md @@ -0,0 +1,259 @@ +# GitHub Copilot CLI Examples + +This directory contains practical examples and templates for integrating GitHub Copilot CLI into your development workflow. + +## Directory Structure + +``` +examples/ +โ”œโ”€โ”€ mcp-configs/ # MCP server configuration examples +โ”œโ”€โ”€ scripts/ # Shell scripts for automation +โ”œโ”€โ”€ workflows/ # CI/CD workflow examples +โ””โ”€โ”€ README.md # This file +``` + +## MCP Configurations + +Located in `mcp-configs/`: + +- **`basic-mcp-config.json`** - Basic setup with filesystem, GitHub, and Git MCP servers +- **`advanced-mcp-config.json`** - Advanced setup with database, search, and communication integrations +- **`development-mcp-config.json`** - Development-focused configuration with limited GitHub tools + +### Usage + +Copy a configuration file to your home directory: + +```bash +# For system-wide configuration +cp examples/mcp-configs/basic-mcp-config.json ~/.copilot/mcp-config.json + +# For project-specific configuration +cp examples/mcp-configs/development-mcp-config.json .copilot/mcp-config.json +``` + +Don't forget to set required environment variables: + +```bash +export GITHUB_TOKEN="your-token" +export WORKSPACE="$(pwd)" +``` + +## Scripts + +Located in `scripts/`: + +### Code Review Script + +**`copilot-review.sh`** - Review code files or directories for issues + +```bash +# Make executable +chmod +x examples/scripts/copilot-review.sh + +# Review a single file +./examples/scripts/copilot-review.sh src/utils.js + +# Review entire directory +./examples/scripts/copilot-review.sh src/ +``` + +### Commit Message Generator + +**`generate-commit-message.sh`** - Generate conventional commit messages + +```bash +# Make executable +chmod +x examples/scripts/generate-commit-message.sh + +# Stage your changes +git add . + +# Generate and commit +./examples/scripts/generate-commit-message.sh +``` + +### Test Generator + +**`generate-tests.sh`** - Generate unit tests for source files + +```bash +# Make executable +chmod +x examples/scripts/generate-tests.sh + +# Generate tests +./examples/scripts/generate-tests.sh src/utils.js +# Creates: src/utils.test.js + +./examples/scripts/generate-tests.sh lib/parser.py +# Creates: lib/parser_test.py +``` + +Supports: +- JavaScript (`.js`) โ†’ Jest +- TypeScript (`.ts`) โ†’ Jest +- React (`.jsx`, `.tsx`) โ†’ React Testing Library +- Python (`.py`) โ†’ pytest +- Go (`.go`) โ†’ Go testing +- Rust (`.rs`) โ†’ Rust testing +- Java (`.java`) โ†’ JUnit 5 + +### Documentation Generator + +**`generate-docs.sh`** - Generate API documentation + +```bash +# Make executable +chmod +x examples/scripts/generate-docs.sh + +# Generate docs for single file +./examples/scripts/generate-docs.sh src/utils.js + +# Generate docs for directory +./examples/scripts/generate-docs.sh src/ docs/api +``` + +## Workflows + +Located in `workflows/`: + +### GitHub Actions + +**`github-actions-review.yml`** - Automated PR reviews + +Copy to your repository: + +```bash +cp examples/workflows/github-actions-review.yml .github/workflows/ +``` + +Requires: +- GitHub token with Copilot access (automatically provided) +- PR permissions (configured in workflow) + +### GitLab CI + +**`gitlab-ci-review.yml`** - Automated MR reviews + +Copy to your repository: + +```bash +cp examples/workflows/gitlab-ci-review.yml .gitlab-ci.yml +``` + +Or merge with existing `.gitlab-ci.yml`: + +```yaml +include: + - local: examples/workflows/gitlab-ci-review.yml +``` + +Requires: +- `COPILOT_GITHUB_TOKEN` variable (with Copilot access) +- `GITLAB_TOKEN` variable (optional, for posting comments) + +## Quick Start + +1. **Install Copilot CLI**: + ```bash + npm install -g @github/copilot + ``` + +2. **Set up authentication**: + ```bash + export GITHUB_TOKEN="your-personal-access-token" + ``` + +3. **Copy and customize MCP config**: + ```bash + mkdir -p ~/.copilot + cp examples/mcp-configs/basic-mcp-config.json ~/.copilot/mcp-config.json + ``` + +4. **Make scripts executable**: + ```bash + chmod +x examples/scripts/*.sh + ``` + +5. **Test it out**: + ```bash + # Review a file + ./examples/scripts/copilot-review.sh README.md + ``` + +## Environment Variables + +Scripts and workflows use these environment variables: + +| Variable | Description | Required | +|----------|-------------|----------| +| `GITHUB_TOKEN` | GitHub personal access token with Copilot access | Yes | +| `WORKSPACE` | Current workspace/project directory | No (defaults to pwd) | +| `COPILOT_MODEL` | Model to use (e.g., claude-sonnet-4.5) | No | +| `PGUSER` | PostgreSQL username (for postgres MCP) | If using postgres | +| `PGPASSWORD` | PostgreSQL password (for postgres MCP) | If using postgres | +| `BRAVE_API_KEY` | Brave Search API key (for search MCP) | If using Brave Search | +| `SLACK_BOT_TOKEN` | Slack bot token (for Slack MCP) | If using Slack | +| `SLACK_TEAM_ID` | Slack team ID (for Slack MCP) | If using Slack | + +## Best Practices + +1. **Start Simple**: Begin with `basic-mcp-config.json` and add servers as needed +2. **Secure Tokens**: Never commit tokens to version control; use environment variables +3. **Test Scripts**: Review generated code/tests/docs before using in production +4. **Customize Prompts**: Adjust prompts in scripts to match your team's standards +5. **CI/CD Integration**: Make CI checks advisory, not blocking, initially + +## Troubleshooting + +### MCP servers not connecting + +```bash +# Check if executables are in PATH +which npx + +# Test server startup manually +npx -y @modelcontextprotocol/server-filesystem ~/projects + +# Check Copilot logs +COPILOT_DEBUG=true copilot +``` + +### Scripts not working + +```bash +# Ensure scripts are executable +chmod +x examples/scripts/*.sh + +# Check Copilot is installed +copilot --version + +# Verify authentication +echo $GITHUB_TOKEN +``` + +### Workflow failures + +- Check GitHub token has Copilot access +- Verify token permissions in repository secrets +- Review workflow logs for specific errors + +## Contributing + +Have a useful script or configuration? Contributions are welcome! + +1. Add your example with clear comments +2. Update this README with usage instructions +3. Test thoroughly before submitting + +## Additional Resources + +- [Integration Guide](../INTEGRATION.md) - Comprehensive integration documentation +- [Official Docs](https://docs.github.com/copilot/concepts/agents/about-copilot-cli) +- [MCP Specification](https://modelcontextprotocol.io/) + +## Support + +For issues or questions: +- [GitHub Copilot CLI Issues](https://github.com/github/copilot-cli/issues) +- [Community Discussions](https://github.com/github/copilot-cli/discussions) diff --git a/examples/mcp-configs/advanced-mcp-config.json b/examples/mcp-configs/advanced-mcp-config.json new file mode 100644 index 00000000..ab69aadd --- /dev/null +++ b/examples/mcp-configs/advanced-mcp-config.json @@ -0,0 +1,70 @@ +{ + "mcpServers": { + "filesystem": { + "type": "local", + "command": "npx", + "args": ["-y", "@modelcontextprotocol/server-filesystem", "${HOME}/projects"], + "tools": ["*"] + }, + "github": { + "type": "local", + "command": "npx", + "args": ["-y", "@modelcontextprotocol/server-github"], + "env": { + "GITHUB_TOKEN": "${GITHUB_TOKEN}" + }, + "tools": ["*"] + }, + "git": { + "type": "local", + "command": "npx", + "args": ["-y", "@modelcontextprotocol/server-git"], + "tools": ["*"] + }, + "postgres": { + "type": "local", + "command": "npx", + "args": [ + "-y", + "@modelcontextprotocol/server-postgres", + "postgresql://localhost:5432/mydb" + ], + "env": { + "PGUSER": "${PGUSER}", + "PGPASSWORD": "${PGPASSWORD}" + }, + "tools": ["*"] + }, + "sequential-thinking": { + "type": "local", + "command": "npx", + "args": ["-y", "@modelcontextprotocol/server-sequential-thinking"], + "tools": ["*"] + }, + "puppeteer": { + "type": "local", + "command": "npx", + "args": ["-y", "@modelcontextprotocol/server-puppeteer"], + "tools": ["*"] + }, + "brave-search": { + "type": "local", + "command": "npx", + "args": ["-y", "@modelcontextprotocol/server-brave-search"], + "env": { + "BRAVE_API_KEY": "${BRAVE_API_KEY}" + }, + "tools": ["*"] + }, + "slack": { + "type": "local", + "command": "npx", + "args": ["-y", "@modelcontextprotocol/server-slack"], + "env": { + "SLACK_BOT_TOKEN": "${SLACK_BOT_TOKEN}", + "SLACK_TEAM_ID": "${SLACK_TEAM_ID}" + }, + "tools": ["*"] + } + } +} diff --git a/examples/mcp-configs/basic-mcp-config.json b/examples/mcp-configs/basic-mcp-config.json new file mode 100644 index 00000000..794d7660 --- /dev/null +++ b/examples/mcp-configs/basic-mcp-config.json @@ -0,0 +1,25 @@ +{ + "mcpServers": { + "filesystem": { + "type": "local", + "command": "npx", + "args": ["-y", "@modelcontextprotocol/server-filesystem", "${HOME}/projects"], + "tools": ["*"] + }, + "github": { + "type": "local", + "command": "npx", + "args": ["-y", "@modelcontextprotocol/server-github"], + "env": { + "GITHUB_TOKEN": "${GITHUB_TOKEN}" + }, + "tools": ["*"] + }, + "git": { + "type": "local", + "command": "npx", + "args": ["-y", "@modelcontextprotocol/server-git"], + "tools": ["*"] + } + } +} diff --git a/examples/mcp-configs/development-mcp-config.json b/examples/mcp-configs/development-mcp-config.json new file mode 100644 index 00000000..9d42e61c --- /dev/null +++ b/examples/mcp-configs/development-mcp-config.json @@ -0,0 +1,41 @@ +{ + "mcpServers": { + "filesystem": { + "type": "local", + "command": "npx", + "args": ["-y", "@modelcontextprotocol/server-filesystem", "${WORKSPACE}"], + "tools": ["*"] + }, + "git": { + "type": "local", + "command": "npx", + "args": ["-y", "@modelcontextprotocol/server-git"], + "tools": ["*"] + }, + "github": { + "type": "local", + "command": "npx", + "args": ["-y", "@modelcontextprotocol/server-github"], + "env": { + "GITHUB_TOKEN": "${GITHUB_TOKEN}" + }, + "tools": [ + "create_or_update_file", + "search_repositories", + "create_repository", + "get_file_contents", + "push_files", + "create_issue", + "create_pull_request", + "fork_repository", + "create_branch" + ] + }, + "sequential-thinking": { + "type": "local", + "command": "npx", + "args": ["-y", "@modelcontextprotocol/server-sequential-thinking"], + "tools": ["*"] + } + } +} diff --git a/examples/scripts/copilot-review.sh b/examples/scripts/copilot-review.sh new file mode 100755 index 00000000..2c7dd2b9 --- /dev/null +++ b/examples/scripts/copilot-review.sh @@ -0,0 +1,65 @@ +#!/bin/bash +# Copilot Code Review Script +# Usage: ./copilot-review.sh [file-or-directory] + +set -e + +TARGET=${1:-.} + +if [ ! -e "$TARGET" ]; then + echo "Error: '$TARGET' does not exist" + exit 1 +fi + +echo "๐Ÿ” Starting Copilot review of: $TARGET" +echo "" + +# Function to review a single file +review_file() { + local file=$1 + echo "๐Ÿ“„ Reviewing: $file" + echo "โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”" + + cat "$file" | copilot -p "Review this code for: + 1. Security vulnerabilities + 2. Code quality issues + 3. Performance problems + 4. Best practices violations + + Be specific and provide actionable feedback with line numbers when possible." + + echo "" + echo "" +} + +# Review single file +if [ -f "$TARGET" ]; then + review_file "$TARGET" + exit 0 +fi + +# Review directory +if [ -d "$TARGET" ]; then + # Find all code files + find "$TARGET" -type f \( \ + -name "*.js" -o \ + -name "*.ts" -o \ + -name "*.jsx" -o \ + -name "*.tsx" -o \ + -name "*.py" -o \ + -name "*.go" -o \ + -name "*.rs" -o \ + -name "*.java" -o \ + -name "*.cpp" -o \ + -name "*.c" -o \ + -name "*.h" \ + \) | while read file; do + review_file "$file" + done + + echo "โœ… Review complete!" + exit 0 +fi + +echo "Error: '$TARGET' is neither a file nor directory" +exit 1 diff --git a/examples/scripts/generate-commit-message.sh b/examples/scripts/generate-commit-message.sh new file mode 100755 index 00000000..85ef3630 --- /dev/null +++ b/examples/scripts/generate-commit-message.sh @@ -0,0 +1,49 @@ +#!/bin/bash +# Generate conventional commit messages using Copilot +# Usage: ./generate-commit-message.sh + +set -e + +# Check if there are staged changes +if ! git diff --cached --quiet; then + echo "๐Ÿ“ Generating commit message for staged changes..." + echo "" + + # Get the diff of staged changes + DIFF=$(git diff --cached) + + # Generate commit message using Copilot + MESSAGE=$(echo "$DIFF" | copilot -p "Generate a conventional commit message for these changes. + + Format: (): + + Types: feat, fix, docs, style, refactor, test, chore + + Rules: + - Use lowercase for type and description + - Keep description under 72 characters + - Be specific but concise + - Focus on WHAT changed and WHY + + Provide only the commit message, nothing else.") + + echo "Generated commit message:" + echo "โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”" + echo "$MESSAGE" + echo "โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”" + echo "" + + read -p "Use this commit message? (y/n): " -n 1 -r + echo "" + + if [[ $REPLY =~ ^[Yy]$ ]]; then + git commit -m "$MESSAGE" + echo "โœ… Changes committed!" + else + echo "โŒ Commit cancelled" + exit 1 + fi +else + echo "No staged changes found. Stage changes with: git add " + exit 1 +fi diff --git a/examples/scripts/generate-docs.sh b/examples/scripts/generate-docs.sh new file mode 100755 index 00000000..2e7c1908 --- /dev/null +++ b/examples/scripts/generate-docs.sh @@ -0,0 +1,104 @@ +#!/bin/bash +# Generate documentation for source files using Copilot +# Usage: ./generate-docs.sh [output-directory] + +set -e + +SOURCE=$1 +DOCS_DIR=${2:-docs} + +if [ -z "$SOURCE" ]; then + echo "Usage: $0 [output-directory]" + echo "" + echo "Examples:" + echo " $0 src/utils.js" + echo " $0 src/ docs/api" + exit 1 +fi + +if [ ! -e "$SOURCE" ]; then + echo "Error: '$SOURCE' does not exist" + exit 1 +fi + +mkdir -p "$DOCS_DIR" + +# Function to generate docs for a single file +generate_docs() { + local file=$1 + local filename=$(basename "$file") + local doc_file="$DOCS_DIR/${filename%.*}.md" + + echo "๐Ÿ“„ Generating docs for: $file" + + cat "$file" | copilot -p "Generate comprehensive API documentation for this code in Markdown format. + +Include: +1. File overview and purpose +2. All public functions/methods/classes with: + - Description + - Parameters (name, type, description) + - Return values (type, description) + - Exceptions/Errors + - Usage examples +3. Code examples showing common use cases +4. Any important notes or warnings + +Format in clean Markdown suitable for documentation sites." > "$doc_file" + + echo " โœ… Created: $doc_file" +} + +echo "๐Ÿ“š Generating documentation..." +echo "๐Ÿ“‚ Output directory: $DOCS_DIR" +echo "" + +# Generate for single file +if [ -f "$SOURCE" ]; then + generate_docs "$SOURCE" + echo "" + echo "โœ… Documentation generated!" + exit 0 +fi + +# Generate for directory +if [ -d "$SOURCE" ]; then + find "$SOURCE" -type f \( \ + -name "*.js" -o \ + -name "*.ts" -o \ + -name "*.jsx" -o \ + -name "*.tsx" -o \ + -name "*.py" -o \ + -name "*.go" -o \ + -name "*.rs" -o \ + -name "*.java" \ + \) | while read file; do + generate_docs "$file" + done + + # Generate index + echo "๐Ÿ“‘ Generating index..." + INDEX_FILE="$DOCS_DIR/README.md" + + { + echo "# API Documentation" + echo "" + echo "Generated documentation for source files in \`$SOURCE\`" + echo "" + echo "## Files" + echo "" + + find "$DOCS_DIR" -name "*.md" ! -name "README.md" | sort | while read doc; do + filename=$(basename "$doc" .md) + echo "- [$filename](./$filename.md)" + done + } > "$INDEX_FILE" + + echo " โœ… Created: $INDEX_FILE" + echo "" + echo "โœ… Documentation generated in: $DOCS_DIR" + exit 0 +fi + +echo "Error: '$SOURCE' is neither a file nor directory" +exit 1 diff --git a/examples/scripts/generate-tests.sh b/examples/scripts/generate-tests.sh new file mode 100755 index 00000000..b893a641 --- /dev/null +++ b/examples/scripts/generate-tests.sh @@ -0,0 +1,102 @@ +#!/bin/bash +# Generate unit tests for source files using Copilot +# Usage: ./generate-tests.sh + +set -e + +SOURCE_FILE=$1 + +if [ -z "$SOURCE_FILE" ]; then + echo "Usage: $0 " + echo "" + echo "Examples:" + echo " $0 src/utils.js" + echo " $0 lib/parser.py" + echo " $0 pkg/handler.go" + exit 1 +fi + +if [ ! -f "$SOURCE_FILE" ]; then + echo "Error: File '$SOURCE_FILE' does not exist" + exit 1 +fi + +# Determine test file path based on language +case "$SOURCE_FILE" in + *.js) + TEST_FILE="${SOURCE_FILE%.js}.test.js" + FRAMEWORK="Jest" + ;; + *.ts) + TEST_FILE="${SOURCE_FILE%.ts}.test.ts" + FRAMEWORK="Jest with TypeScript" + ;; + *.jsx) + TEST_FILE="${SOURCE_FILE%.jsx}.test.jsx" + FRAMEWORK="Jest with React Testing Library" + ;; + *.tsx) + TEST_FILE="${SOURCE_FILE%.tsx}.test.tsx" + FRAMEWORK="Jest with React Testing Library and TypeScript" + ;; + *.py) + TEST_FILE="${SOURCE_FILE%.py}_test.py" + FRAMEWORK="pytest" + ;; + *.go) + TEST_FILE="${SOURCE_FILE%.go}_test.go" + FRAMEWORK="Go testing package" + ;; + *.rs) + # Rust tests usually in same file, but can be separate + TEST_FILE="${SOURCE_FILE%.rs}_test.rs" + FRAMEWORK="Rust built-in testing" + ;; + *.java) + # Java test in test directory + TEST_FILE=$(echo "$SOURCE_FILE" | sed 's/src\/main/src\/test/' | sed 's/\.java$/Test.java/') + FRAMEWORK="JUnit 5" + ;; + *) + echo "Error: Unsupported file type" + echo "Supported: .js, .ts, .jsx, .tsx, .py, .go, .rs, .java" + exit 1 + ;; +esac + +echo "๐Ÿงช Generating tests for: $SOURCE_FILE" +echo "๐Ÿ“ Output file: $TEST_FILE" +echo "๐Ÿ”ง Framework: $FRAMEWORK" +echo "" + +# Check if test file already exists +if [ -f "$TEST_FILE" ]; then + read -p "Test file already exists. Overwrite? (y/n): " -n 1 -r + echo "" + if [[ ! $REPLY =~ ^[Yy]$ ]]; then + echo "โŒ Cancelled" + exit 1 + fi +fi + +# Generate tests using Copilot +cat "$SOURCE_FILE" | copilot -p "Generate comprehensive unit tests for this code using $FRAMEWORK. + +Requirements: +1. Test all public functions/methods +2. Include edge cases and error handling +3. Test boundary conditions +4. Mock external dependencies appropriately +5. Follow testing best practices for the language +6. Include descriptive test names +7. Add comments explaining complex test scenarios + +Provide ONLY the test code, no explanations." > "$TEST_FILE" + +echo "" +echo "โœ… Tests generated: $TEST_FILE" +echo "" +echo "Next steps:" +echo " 1. Review the generated tests" +echo " 2. Run tests: [your test command]" +echo " 3. Adjust as needed" diff --git a/examples/workflows/github-actions-review.yml b/examples/workflows/github-actions-review.yml new file mode 100644 index 00000000..b6116a22 --- /dev/null +++ b/examples/workflows/github-actions-review.yml @@ -0,0 +1,64 @@ +name: Copilot Code Review + +on: + pull_request: + types: [opened, synchronize, reopened] + +permissions: + contents: read + pull-requests: write + +jobs: + copilot-review: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: '22' + + - name: Install GitHub Copilot CLI + run: npm install -g @github/copilot + + - name: Get PR diff + id: diff + run: | + git diff origin/${{ github.base_ref }}...HEAD > pr_diff.txt + echo "Generated PR diff" + + - name: Review with Copilot + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + copilot -p "Review this pull request for: + 1. Code quality and best practices + 2. Security vulnerabilities + 3. Performance issues + 4. Potential bugs + 5. Documentation needs + + Provide specific, actionable feedback with file names and line numbers when possible. + Be constructive and focus on important issues." < pr_diff.txt > review.txt + + echo "Review completed" + + - name: Post review comment + if: always() + uses: actions/github-script@v7 + with: + script: | + const fs = require('fs'); + const review = fs.readFileSync('review.txt', 'utf8'); + + await github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number, + body: `## ๐Ÿค– Copilot CLI Review\n\n${review}\n\n---\n*This review was automatically generated by GitHub Copilot CLI*` + }); diff --git a/examples/workflows/gitlab-ci-review.yml b/examples/workflows/gitlab-ci-review.yml new file mode 100644 index 00000000..3ebbabfc --- /dev/null +++ b/examples/workflows/gitlab-ci-review.yml @@ -0,0 +1,48 @@ +stages: + - review + +copilot-review: + stage: review + image: node:22 + + before_script: + - npm install -g @github/copilot + + script: + # Get merge request diff + - git diff ${CI_MERGE_REQUEST_TARGET_BRANCH_SHA}...${CI_COMMIT_SHA} > mr_diff.txt + + # Review with Copilot + - | + copilot -p "Review these changes for: + 1. Code quality issues + 2. Security vulnerabilities + 3. Performance problems + 4. Best practices violations + + Provide specific, actionable feedback." < mr_diff.txt > review.txt + + # Display review + - cat review.txt + + # Post as MR comment (requires GitLab token with api scope) + - | + if [ -n "$GITLAB_TOKEN" ]; then + COMMENT=$(cat review.txt | jq -Rs .) + curl --request POST \ + --header "PRIVATE-TOKEN: $GITLAB_TOKEN" \ + --header "Content-Type: application/json" \ + --data "{\"body\": \"## ๐Ÿค– Copilot CLI Review\n\n$COMMENT\"}" \ + "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/merge_requests/${CI_MERGE_REQUEST_IID}/notes" + fi + + only: + - merge_requests + + variables: + GITHUB_TOKEN: $COPILOT_GITHUB_TOKEN + + artifacts: + paths: + - review.txt + expire_in: 1 week