GitHub Copilot - Everything you need to know

Let's talk about a very exciting product that was recently launched by GitHub, which is called GitHub Copilot.
GitHub Copilot is your new AI Pair programmer, powered by OpenAI. It helps you to write utilify functions, tests, and explore new API(s) without having to lookup for answers on internet. It generates or autocomplete code for you.

Installation

It's currently not available publicly, so if you want to use it, you've to join the waiting list by visiting GitHub Copilot and head over to Sign up page.

After installation and authenticating it with your GitHub, you'll see Copilot icon in Visual Studio Code at bottom right.
Extension Icon
You can enable/disable Copilot by tapping this icon.

Usage

Let's start with some simple and basic utilify functions.

Suppose, I want to have a function which accepts a number as an argument and returns the double of it, here's how Copilot helps me.
Double The Number Code

Let's try with a function that finds even numbers in an array
Even Number Function

Maybe try something related to dates?
Days in Year Function

When Copilot gives you a suggestion and you hover the mouse on last character, it gives you options to navigate between Next and Previous , Accept current suggestion or Open Copilot which shows list of all the suggestions available.
Open Copilot

These were some simple utility functions, maybe we should give a try to use Node.js default modules, such as fs.
Depending on the what function name you use, Copilot gives different suggestions.

Okay, enough of simple examples, let's quickly build a simple CLI based application that fetch user GitHub details (api.github.com/users...)

CLI Applications start with a shebang which syntax I always forget, but now no more (Yes, Copilot also works for comments
Shebang Suggestion

Here's the basic template
CLI application template

Now let's start using copilot. The very first thing is to extract username from arguments as the user will be passing it dynamically

./cli.js khattakdev

Here khattakdev is a GitHub Handle

Here's the code for extracting username from arguments
Get Values Function

and here's the code for making an API call, since axios is imported, so copilot suggests an axios call
Make an API Call

Here's the whole code for CLI application, which we created in a minute using copilot.
CLI application Code

Conclusion

Copilot is an awesome tool that works for creating utility functions, writing test cases, and exploring new API(s). It also works for comments and it gives you multiple suggestions.

43