Create Your Own GitHub Copilot

Create Your Own GitHub Copilot
Photo by friend and her cats @Texas, USA

Ever since GitHub Copilot was introduced, the speed and capabilities of my programming have significantly improved. For someone who is not a full-time programmer (My role is architect, not SWE), this is quite a substantial help.

The post Tips and tricks for Copilot in VS Code is well worth reading before you are ready to use GitHub Copilot

Personalize Copilot with instructions files

Based on Customize chat responses in VS Code document states that you can configure custom instructions for the following 5 types:

  1. Code generation: github.copilot.chat.codeGeneration.instructions
  2. Test generation: github.copilot.chat.testGeneration.instructions
  3. Code review: github.copilot.chat.reviewSelection.instructions
  4. Commit message generation: github.copilot.chat.commitMessageGeneration.instructions
  5. Pull request title and description: github.copilot.chat.pullRequestDescriptionGeneration.instructions

I will share insights on the 2 commonly used types: Code generation / Commit message generation

Multiple Languages within 1 project

Personally, I often write both Python and Bash scrtips within the same Git project. However, since the coding styles of these 2 programming languages are diffrent, I need to write seperate instructions for each language.

.github
└── instructions
    ├── bash.instructions.md
    ├── general-coding.instructions.md
    └── python.instructions.md

project-structure

---
applyTo: "**"
---
# Project general coding standards

Keep it simple, stupid

.github/instructions/general-coding.instructions.md

---
applyTo: "**/*.sh"
---
# Project coding standards for Shell scripts

Apply the [general coding guidelines](./general-coding.instructions.md) to all code.

## Shell guidelines

### Code Style

- Use POSIX compliant shell scripts
- Follow [ShellCheck](https://www.shellcheck.net/) recommendations
- Use 2 spaces for indentation, instead of tabs

.github/instructions/bash.instructions.md

---
applyTo: "**/*.py"
---
# Project coding standards for Python

Apply the [general coding guidelines](./general-coding.instructions.md) to all code.

## Python guidelines

### Code Style

- Use Python3 syntax
- Follow [PEP 8](https://www.python.org/dev/peps/pep-0008/) for style guidelines
- Use [PEP 257](https://www.python.org/dev/peps/pep-0257/) for docstrings
- Use 4 spaces for indentation, instead of tabs
- Use `snake_case` for variable and function names
- Use `CamelCase` for class names
- Use `UPPER_CASE` for constants
- Use `f-strings` for string formatting
- Use double quotes for strings
- One blank lines before top-level functions/classes

.github/instructions/python.instructions.md

github copilot w/ python
github copilot w/ bash

If you are also writing other programming languages at the same time, simply add a new file and ensure that applyTo matches the filename

Git Commit Generation

git-commit-generation
git-commit-history

This is probably my favorite feature since the birth of GitHub Copilot. Many times, it's just about making small changes, but coming up with what to write in the commit message is a very troublesome task. The advent of this feature has greatly solved the problem of insufficient content in git commits.

    "github.copilot.chat.commitMessageGeneration.instructions": [
        {
            "text": "Start each commit message with an emoji representing the change type, then provide a concise summary of what changed and why. Write the message in English."
        },
        {
            "file": "copilot-commit-message-instructions.md"
        }
    ],

.vscode/settings.json

Since git commit applies to any projects, the instructions are placed in github.copilot.chat.commitMessageGeneration.instructions to ensure they can be used for any project. Of course, if you have specific requirements, you still can write them seperately in .github/copilot-commit-message-instructions.md after defined