OceanofPDF - Com Programming With GitHub Copilot - Kurt Dowswell
OceanofPDF - Com Programming With GitHub Copilot - Kurt Dowswell
Cover
Table of Contents
Title Page
Introduction
Part I: Getting Started with GitHub Copilot
CHAPTER 1: Get Started with GitHub Copilot
Learn Why GitHub Copilot Matters
Create a GitHub Account
Acquire a GitHub Copilot License
Install an IDE Extension
First Run: Test Copilot
Conclusion
Reference
CHAPTER 2: Decoding GitHub Copilot
Uncover the AI Behind GitHub Copilot
Understand Security, Privacy, and Data Handling
Understand Copyright Protections
Explore the GitHub Copilot Trust Center
Conclusion
References
Part II: GitHub Copilot Features in Action
CHAPTER 3: Exploring Code Completions
Introducing Code Completions
Working with Copilot Code Completions
Discovering the Toolbar and Panel
Updating Copilot Settings
Leveraging Keyboard Shortcuts
Conclusion
CHAPTER 4: Chatting with GitHub Copilot
Discovering Copilot Chat
Defining Prompt Engineering with Copilot Chat
Commanding Your Conversation with Precision
Conclusion
Part III: Practical Applications of GitHub Copilot
CHAPTER 5: Learning a New Programming Language
Introducing Language Education with Copilot
Setting Up Your Development Environment
Learning the Basics
Creating a Console Application
Explaining Code with Copilot
Adding New Code
Learning to Test
Conclusion
Reference
CHAPTER 6: Writing Tests with Copilot
Establishing the Example Project
Adding Unit Tests to Existing Code
Exploring Behavior-Driven Development with Copilot
Conclusion
CHAPTER 7: Diagnosing and Resolving Bugs
Establishing the Example Project
Fixing Syntax Errors
Resolving Runtime Exceptions
Resolving Terminal Errors
Conclusion
CHAPTER 8: Code Refactoring with Copilot
Introducing Code Refactoring with Copilot
Establishing the Example Project
Refactoring Duplicate Code
Refactoring Validators
Refactoring Bad Variable Names
Documenting and Commenting Code
Conclusion
CHAPTER 9: Enhancing Code Security
Detailing Code Security
Establishing the Example Project
Exploring Code Security
Finding and Fixing Security Issues
Conclusion
CHAPTER 10: Accelerating DevSecOps Practices
Detailing DevSecOps
Simplifying Containers
Automating Infrastructure as Code
Streamlining CI/CD Pipelines
Conclusion
CHAPTER 11: Enhancing Development Environments with
Copilot
Amplifying Visual Studio with Copilot
Elevating Azure Data Studio with Copilot
Boosting JetBrains IntelliJ IDEA with Copilot
Enhancing Neovim with Copilot
Consulting Copilot in the GitHub CLI
References
Conclusion
CHAPTER 12: Universal Conversion with GitHub Copilot
Translating Natural Language to Programming Languages
Converting JavaScript Components
Simplifying CSS Styles
Enhancing Nontyped Languages with Types
Transitioning Between Frameworks and Libraries
Converting Object-Oriented Languages
Migrating Databases
Transitioning CI/CD Platforms
Modernizing Legacy Systems
Conclusion
Reference
Part IV: Key Insights and Advanced Use Cases for GitHub Copilot
CHAPTER 13: Considering Responsible AI with GitHub Copilot
Introducing Responsible AI
Examining How Copilot Implements Responsible AI
Programming with AI Responsibly
Conclusion
References
CHAPTER 14: Augmenting the Software Development Life
Cycle with GitHub Copilot
Introducing the SDLC
Assessing the Adoption of AI in the SDLC
Detailing Levels of AI Integration in the SDLC
Showcasing GitHub Copilot in the SDLC
Addressing Concerns: AI Adoption and the Future of Work
Conclusion
References
CHAPTER 15: Exploring Copilot Business and Enterprise
Introducing Copilot Business and Enterprise
Chatting with Copilot in GitHub.com
Indexing Code Repositories to Improve Copilot's
Understanding
Getting Better Answers with the Knowledge Base
Leveraging Copilot Chat in Code Repository Files
Enhancing Pull Requests with Copilot
Managing GitHub Copilot
Looking Ahead
Conclusion
References
Conclusion
APPENDIX A: Resources for Further Learning
GitHub Copilot Overview and Subscription Plans
Community Engagement and Support
Legal and Ethical Considerations
Research and Insights
Glossary
Index
Copyright
Acknowledgments
About the Author
About the Technical Editor
End User License Agreement
List of Illustrations
Chapter 1
Figure 1.1: VS Code welcome screen
Figure 1.2: VS Code Extensions panel
Figure 1.3: Sign-in prompt
Figure 1.4: Signing in via the Action Bar
Figure 1.5: Copilot status menu
Figure 1.6: Open Folder button
Figure 1.7: Creating the palindrome-checker.js file
Figure 1.8: Copilot completion suggestion for top-level comment
Figure 1.9: Copilot completion suggestion for palindrome
function
Figure 1.10: Palindrome function with tests
Figure 1.11: Palindrome function terminal run with results
Chapter 3
Figure 3.1: Copilot code completion result
Figure 3.2: Additional code completion result
Figure 3.3: Panel visibility menu item
Figure 3.4: Method name driving code completion
Figure 3.5: Method code completion
Figure 3.6: Validation method output test
Figure 3.7: Inline comment with Copilot suggestion
Figure 3.8: Top-level comment and open tab adding context
Figure 3.9: Code completion toolbar
Figure 3.10: Completions panel
Figure 3.11: GitHub Copilot settings
Figure 3.12: GitHub Copilot advanced settings
Figure 3.13: Keyboard shortcut settings
Chapter 4
Figure 4.1: Copilot Chat sidebar
Figure 4.2: Copilot editor view for chatting
Figure 4.3: Opening the chat in a new window
Figure 4.4: New window chat with multiple conversation tabs
Figure 4.5: Right sidebar Copilot conversation
Figure 4.6: Inline chat
Figure 4.7: Copilot menu for inline chat
Figure 4.8: Copilot sparkle icon and quick-fix menu
Figure 4.9: Copilot quick chat with suggested fix
Figure 4.10: Basic prompt structure
Figure 4.11: Copilot prompt with the #editor tag
Figure 4.12: Copilot prompt with a #file tag
Figure 4.13: Copilot's Explain This command
Figure 4.14: Inline chat /explain command
Figure 4.15: Chat window /explain command
Figure 4.16: Sparkle menu's Explain using Copilot command
Figure 4.17: Terminal window's Copilot: Explain This command
Figure 4.18: Generate Tests command
Figure 4.19: Inline chat /tests command
Figure 4.20: Window chat /tests command
Figure 4.21: Copilot-generated test file
Figure 4.22: Compilation error with the /fix command
Figure 4.23: Compilation error solution using the /fix command
Figure 4.24: Copilot response from /new request
Figure 4.25: Copilot response to /newNotebook command
Figure 4.26: Copilot-generated Jupyter Notebook
Figure 4.27: @vscode question and answer
Figure 4.28: @terminal question and answer
Chapter 5
Figure 5.1: Copilot chat instructions
Figure 5.2: VS Code Extensions panel
Figure 5.3: Copilot response to C# language basics prompt
Figure 5.4: Copilot response for how to create C# console app
Figure 5.5: C# console application project in VS Code
Figure 5.6: Copilot chat response to request to create a Pirate
class
Figure 5.7: Copilot /explain chat command for Pirate class file
Figure 5.8: Copilot code completion for new method
Figure 5.9: Copilot chat response to learn how to create tests
Figure 5.10: Copilot chat insert into terminal
Figure 5.11: Copilot explaining the last terminal command via a
quick-fix me...
Figure 5.12: Successful run of unit tests via the dotnet test
command
Figure 5.13: Copilot chat response for Greeting method tests
Figure 5.14: Greeting method unit test for Pirate class
Chapter 6
Figure 6.1: Test code completion from an inline comment
Figure 6.2: Test failure from the new test
Figure 6.3: Is Completed Property added to the test object result
Figure 6.4: Service function refactored and passing test result
Figure 6.5: Inline chat with the /tests command provided
Figure 6.6: Test file created from inline chat request
Figure 6.7: User resource created
Figure 6.8: App end-to-end test
Figure 6.9: User creation e2e test file
Figure 6.10: User creation E2E test file with Copilot code
Suggestion
Figure 6.11: User creation E2E test file failing test run results
Chapter 7
Figure 7.1: Syntax error with highlighted code and error message
Figure 7.2: Inline chat response from Copilot
Figure 7.3: Bad inline chat response from Copilot
Figure 7.4: Inline comment for null parameter create method test
Figure 7.5: Create method test failure
Figure 7.6: User service create method guard statement code
suggestion
Figure 7.7: User service create method passing test for null
reference excep...
Figure 7.8: CLI error for the git checkout command
Figure 7.9: Copilot chat response
Chapter 8
Figure 8.1: User controller error logging
Figure 8.2: User controller test file with code completion for the
update fu...
Figure 8.3: User controller inline chat tests prompt
Figure 8.4: User controller inline chat tests prompt refactor
preview window...
Figure 8.5: User controller tests remove function result from
inline chat te...
Figure 8.6: User controller tests file with adjustment from inline
chat resu...
Figure 8.7: User controller code selected with inline chat prompt
for refact...
Figure 8.8: User controller code refactor result
Figure 8.9: User service create method validation code with tests
prompt
Figure 8.10: User service create validation test functions
Figure 8.11: User service create user validation extract function
Figure 8.12: User service create user validation refactored result
Figure 8.13: User service create method extended code
refactoring result
Figure 8.14: Copilot chat response to additional refactoring that
could be d...
Figure 8.15: Copilot inline chat refactor bad variable names
prompt
Figure 8.16: Copilot inline chat refactor bad variable names
refactor result...
Figure 8.17: Copilot inline chat add documentation to user service
class
Figure 8.18: Copilot inline chat add documentation to user service
class res...
Figure 8.19: Function documentation refactor completed
Figure 8.20: Copilot chat response to generate the project
README.md file
Chapter 9
Figure 9.1: Copilot Chat response for best practices for NestJS
APIs
Figure 9.2: Copilot Chat response for how to use HTTPS in a
NestJS API
Figure 9.3: Copilot Chat response for how to do input validation
in a NestJS...
Figure 9.4: Copilot Chat response for user service security issues
Figure 9.5: Copilot Chat response for how to fix weak password
hashing
Figure 9.6: Copilot Chat response for how to fix weak password
hashing
Figure 9.7: Copilot Chat response for how to fix SQL injection
Chapter 10
Figure 10.1: DevSecOps diagram detailing security considered at
each stage o...
Figure 10.2: Copilot Chat response for how to create a container
for a NestJ...
Figure 10.3: Copilot Chat response for how to deploy a
Dockerized NestJS API...
Figure 10.4: Copilot Chat response for what security controls can
be applied...
Figure 10.5: Copilot Chat response for what security controls can
be applied...
Figure 10.6: Copilot Chat response for how to deploy NestJS API
using Terraf...
Figure 10.7: Copilot Chat response for what security controls
should be adde...
Figure 10.8: Copilot Chat response for help creating a continuous
integratio...
Figure 10.9: Copilot Chat response for help creating security
scanning for a...
Figure 10.10: Copilot Chat response for help creating a
continuous deploymen...
Chapter 11
Figure 11.1: Visual Studio Manage Extensions window
Figure 11.2: Visual Studio GitHub Copilot extension installer
Figure 11.3: Visual Studio Add GitHub Account menu
Figure 11.4: Copilot completion suggestion for top-level
comment
Figure 11.5: Copilot completion suggestion for top-level
comment
Figure 11.6: Copilot Chat window with greeting
Figure 11.7: Copilot inline chat window
Figure 11.8: Copilot inline chat inline code diff
Figure 11.9: Azure Data Studio GitHub Copilot extension view
Figure 11.10: Enable GitHub Copilot globally
Figure 11.11: SQL Server database schema
Figure 11.12: Copilot-assisted test data creation
Figure 11.13: Copilot-assisted query creation
Figure 11.14: IntelliJ IDEA plugins search result screen with
GitHub Copilot...
Figure 11.15: IntelliJ IDEA new project window
Figure 11.16: IntelliJ IDEA GitHub Copilot welcome
Figure 11.17: Copilot completion suggestion for top-level
comment
Figure 11.18: Programing the test result with new code
Figure 11.19: Copilot Chat result with documentation
Figure 11.20: Copilot completing a comment in Neovim
Figure 11.21: Copilot completing the fetchDadJoke()function
Figure 11.22: Copilot completing the fetchDadJoke()function
Figure 11.23: Node.js call for dad jokes
Figure 11.24: Copilot in the GitHub CLI
Figure 11.25: Copilot suggest command result
Figure 11.26: Copilot suggest generic shell command result
Figure 11.27: Copilot explains and executes the generic shell
command.
Figure 11.28: Copilot explain command result
Chapter 12
Figure 12.1: English to JavaScript
Figure 12.2: Copilot /explain command results
Figure 12.3: React to Angular
Figure 12.4: React to Angular
Figure 12.5: Create profile page with CSS
Figure 12.6: Create profile HTML source file
Figure 12.7: Copilot response for converting the page to Tailwind
CSS
Figure 12.8: Create profile page with Tailwind CSS
Figure 12.9: Copilot response for converting the page to
Bootstrap
Figure 12.10: HTML page with Bootstrap framework powering
design and layout...
Figure 12.11: Calculate total function converted to TypeScript
Figure 12.12: Copilot response on how to update a JavaScript
project to Type...
Figure 12.13: Copilot response on how to convert an application
to use Polar...
Figure 12.14: Copilot response on how to convert application to
use Koa.js
Figure 12.15: Copilot code suggestion for person object in Swift
Figure 12.16: Copilot response for SQL Server to PostgreSQL
migration
Figure 12.17: Copilot response for Azure DevOps pipeline file to
GitHub Acti...
Figure 12.18: Copilot response for converting COBAL program
and DB2 to SQL S...
Chapter 13
Figure 13.1: Copilot extension settings for language
Figure 13.2: Copilot responding in multiple languages
Figure 13.3: Copilot resisting to provide details on a hacking
attempt
Figure 13.4: Copilot responding with secrets variables
Figure 13.5: Copilot explain command results
Figure 13.6: Copilot human-in-the-loop example
Chapter 14
Figure 14.1: Adoption of AI in the SDLC
Figure 14.2: Adoption of AI in the SDLC
Figure 14.3: Levels of adoption of AI in the SDLC
Figure 14.4: Copilot responding with user story titles for a feature
Figure 14.5: Copilot responding with user story acceptance
criteria in gherk...
Figure 14.6: Copilot responding with details on AI vision system
libraries
Figure 14.7: Copilot inline chat assisting in edits to a user story
scenario...
Figure 14.8: Copilot inline chat assisting in tasking of work for a
user sto...
Figure 14.9: Copilot inline chat assisting in installing and
importing a lib...
Figure 14.10: Copilot inline chat assisting in completing a
function for usi...
Figure 14.11: Copilot inline chat assisting in the creation of unit
tests
Figure 14.12: Copilot Chat response for integration pipeline
workflow file
Chapter 15
Figure 15.1: Copilot code completions
Figure 15.2: Copilot sidebar chat
Figure 15.3: Copilot in the CLI
Figure 15.4: Copilot in GitHub.com chat window
Figure 15.5: Copilot in GitHub.com chat window with CodeQL
results
Figure 15.6: Contribution guidelines for CodeQL results
Figure 15.7: Copilot in GitHub.com general-purpose chat window
Figure 15.8: Copilot in GitHub.com conversation about essential
concepts in ...
Figure 15.9: eShopOnWeb client application
Figure 15.10: Indexing your repository for GitHub Copilot in
GitHub.com
Figure 15.11: Copilot Chat response for how to run the API
locally
Figure 15.12: Copilot Chat response for where authentication is
handled in o...
Figure 15.13: Your organization settings menu
Figure 15.14: Organization Copilot Knowledge Bases screen
Figure 15.15: Organization Copilot knowledge front-end
development
Figure 15.16: Copilot Chat knowledge base menu
Figure 15.17: Copilot Chat bootstrap version question
Figure 15.18: Copilot Chat bootstrap version migration question
result
Figure 15.19: Copilot Chat response for what files are used when
updating a ...
Figure 15.20: Copilot buttons and menus within a file in your
codebase
Figure 15.21: Copilot conversation about selected code in file
Figure 15.22: Copilot inline menu for suggesting improvements
Figure 15.23: Copilot Chat response for improving basket item
addition code...
Figure 15.24: Copilot Chat window with attachment
Figure 15.25: Copilot Chat window with attachment response
Figure 15.26: Copilot Chat window attachment search for files
and symbols
Figure 15.27: Web application basket page to be modified with a
remove butto...
Figure 15.28: Copilot Chat response for how to add a remove
item feature to ...
Figure 15.29: Copilot Chat response for creating tests for the new
method
Figure 15.30: Copilot function creation for remove item from
basket function...
Figure 15.31: Basket page with new remove button for each item
Figure 15.32: GitHub Copilot commit message help feature
Figure 15.33: GitHub Copilot pull request summary feature
Figure 15.34: GitHub Copilot pull request summary feature
Figure 15.35: Organization settings for GitHub Copilot access
Figure 15.36: Organization settings for GitHub Copilot policies
Figure 15.37: Organization settings for GitHub Copilot content
exclusions
Figure 15.38: Organization audit logs for GitHub Copilot
OceanofPDF.com
Programming with GitHub®
Copilot
Write Better Code–Faster!
Kurt Dowswell
OceanofPDF.com
Introduction
Welcome to Programming with GitHub Copilot, your comprehensive guide
to GitHub Copilot. As programming evolves, the tools and techniques at
your disposal must adapt to meet the increasing complexity of projects and
the demand for faster, more efficient development cycles. GitHub Copilot
represents a monumental shift in how code is written, offering you an
exceptional partner in your coding journey.
GitHub Copilot is not just a tool; it's transforming the concept of pair
programming. Traditionally, pair programming involves two programmers
working together at one workstation, continuously collaborating to write
better code. However, finding a human partner for this task isn't always
feasible. Enter GitHub Copilot, your ever-present AI companion, ready to
assist by suggesting code, helping debug, and even writing blocks of code
autonomously.
This book is designed to give you practical applications of GitHub Copilot.
From setting up your environment to advanced topics like enhancing code
security and accelerating DevSecOps practices, each chapter dives deep
into real-world applications and provides insights into making the most of
this powerful tool.
On the book's website
(https://www.wiley.com/go/programminggithubcopilot), you will find
code files for the starter projects discussed in select chapters. These
companion files are designed to help you follow along with the practical
examples provided throughout the book.
Whether you're a seasoned developer or just starting out, this book will
enable you to harness the capabilities of GitHub Copilot to enhance your
programming skills, learn new languages, refactor code, and much more.
OceanofPDF.com
Part I
Getting Started with GitHub
Copilot
In This Part
Chapter 1: Get Started with GitHub Copilot
Chapter 2: Decoding GitHub Copilot
OceanofPDF.com
CHAPTER 1
Get Started with GitHub Copilot
Software development is full of challenges to overcome. For years, it has
been known that programming with a partner can help you learn more,
produce better work, and gain more satisfaction while accomplishing your
tasks. Although the benefits of pair programming are known, it isn't always
possible to have a pair programming partner with you—until now.
GitHub Copilot is your artificial intelligence (AI) pair programming
partner, always ready to assist and eager to help you learn! This book will
walk you through how to best utilize GitHub Copilot to help you write
better code and do it faster.
In this chapter, we will focus on the required steps for getting started with
GitHub Copilot. Let's begin!
Copilot Individual
Copilot Business
Copilot Enterprise
There are several factors to consider when choosing the correct plan. If you
are a student or a maintainer of a popular open-source project, you might be
eligible for a free Copilot Individual license.
You can get more information on licenses on this web page:
https://docs.github.com/enterprise-
cloud@latest/billing/managing-billing-for-github-copilot/about-
billing-for-github-copilot
NOTE In this book, we will be using the Visual Studio Code IDE
for most of the examples. If you use one of the other supported
IDEs as your preferred development platform, the information
shared in these examples will be transferrable. We will be covering
these additional IDEs later in the book when we detail how to set up
and configure them to work with GitHub Copilot.
Once you have installed VS Code on your computer, you should see a
welcome screen (see Figure 1.1).
Install Node.js
Lastly, Node.js will need to be installed to run the example. Node.js is an
open-source, cross-platform, back-end JavaScript runtime environment. It
allows us to execute JavaScript outside of the web browser.
The easiest way to install Node.js is to go to the website:
https://nodejs.org/en/download.
VS Code
GitHub account
GitHub Copilot license
GitHub Copilot extension
Node.js
Explore Copilot
Let's make sure that Copilot is working by writing a quick example
function. In this section, you will create a palindrome checker to showcase
some of the basic interactions you will have with Copilot within your editor.
Start by opening a folder in VS Code. You can do this via the Explorer
menu (see Figure 1.6) or the keyboard shortcut (Cmd+O/Ctrl+O).
With the comment at the top of the file, continue to the next line. You can
provide additional context by adding some examples of palindromes you
would like the checker to expect to receive.
// examples: racecar, taco cat
Without this example comment, there is a chance that the palindrome
function will not account for phrase inputs. Adding this context is a way for
you to continue to refine the context given to Copilot to get better output.
Now that you have a short, clear, and targeted comment for your file, you
can add two line returns to the file to move on to the function
implementation. If Copilot doesn't automatically give you the line you
would like as a suggestion, you can start typing the statement you would
prefer. Copilot will then use this additional context to drive a better
completion suggestion for the current line you are working on.
In my case, I will accept a line comment describing a function to check if a
string is a palindrome and implement the first line of the function name (see
Figure 1.9).
Figure 1.9: Copilot completion suggestion for palindrome function
You should now see output indicating the expected results from your
function (see Figure 1.11).
Figure 1.11: Palindrome function terminal run with results
Conclusion
There are a multitude of ways in which GitHub Copilot will assist you in
your developer workflow. So far, we have only scratched the surface of the
capabilities Copilot provides. Up next, you will learn more about GitHub
Copilot code suggestions, what data sources and training it uses, and
privacy and security considerations that are important to know.
Reference
[1] E. Kalliamvakou, 2022. “Research: quantifying GitHub Copilot's impact
on developer productivity and happiness,” https://github.blog/2022-
09-07-research-quantifying-github-copilots-impact-on-
developer-productivity-and-happiness
OceanofPDF.com
CHAPTER 2
Decoding GitHub Copilot
In this chapter, we will look at the AI behind GitHub. We will explore the
genesis, advancement, and capabilities of GitHub Copilot. We'll delve into
the security and privacy measures that safeguard our work, highlighting the
importance of secure data handling and the mechanisms in place to protect
our code. We will also explore the critical topic of copyright protections,
ensuring that our use of GitHub Copilot aligns with legal standards. Lastly,
we will review the GitHub Copilot Trust Center to equip ourselves with the
necessary knowledge to navigate the complexities of using this powerful
tool confidently.
Message Transmission
When interacting with GitHub Copilot, all the required context to resolve
your questions or completion suggestions must be transmitted to GitHub's
services running on Azure. This data is passed via Hypertext Transfer
Protocol Secure (HTTPS) over Transport Layer Security (TLS). This end-
to-end encryption process ensures your data, code, and queries are all
secure and processed only by the GitHub Copilot back-end services. HTTP
over TLS is the global standard for safe and secure message passing.
Data Storage
In this section, we will detail what GitHub Copilot data is stored at rest.
The LLM will then process these token inputs and identify the pattern that
is occurring. This will result in a predicted token that should occur next,
which, in this case, is 5.
Building on the numeric list example, let's see how this works when we are
coding a new method. If we have a Python function declaration such as this:
def greet(name):
then Copilot will split out our function declaration into a series of tokens:
[‘def’, ‘greet’, ‘(‘, ‘name’, ‘)’, ‘:’]
The LLM will then process these token inputs and identify the pattern that
is occurring. This will result in a predicted token that should occur next. In
this case, the token most likely would be print.
The model then continues to predict the next tokens, resulting in a
completed line of code.
def greet(name):
print(f"Hello, {name}!")
While the code is not saved to the model, due to the way in which the
training operations are conducted, there is a chance (less than 1%) that
Copilot will produce results that match the code used to train the model [3].
It is important to understand that this is not copy-and-pasting. It is
determining the best chain of code that matches the prompt and context it is
operating within.
GitHub, with the support of its parent company Microsoft, has always
provided copyright indemnification protections ensuring that you will be
protected if any legal action is brought against you because of the use of
GitHub Copilot.
At the Ignite conference in November 2023, Microsoft expanded its
copyright support to all of its generative AI solutions and tools, further
entrenching Microsoft's support to customers in this area. This commitment
is called the “Customer Copyright Commitment (CCC),” and it ensures that
all customers using Microsoft generative AI solutions are backed by the
legal support of Microsoft if faced with legal issues.
NOTE You must have the GitHub Copilot Policy setting called
Suggestions Matching Public Code set to Blocked to be eligible for
this legal protection. For more information, please see this page:
https://learn.microsoft.com/en-us/legal/cognitive-
services/openai/customer-copyright-commitment
Conclusion
In this chapter, our exploration of GitHub Copilot has unveiled the
remarkable AI driving this innovative tool, emphasizing its development,
security measures, and commitment to copyright compliance. Through
understanding the intricate layers of protection and legal foresight
integrated into GitHub Copilot, alongside the resources available in the
Trust Center, we are now better positioned to leverage this technology. As
we move forward, equipped with this knowledge, we can confidently
incorporate GitHub Copilot into our development workflows, harnessing its
potential to streamline our coding processes and enhance our productivity.
References
[1] S. Verdi, 2023. “Inside GitHub: Working with the LLMs behind GitHub
Copilot,” https://github.blog/2023-05-17-inside-github-
working-with-the-llms-behind-github-copilot
OceanofPDF.com
Part II
GitHub Copilot Features in
Action
In This Part
Chapter 3: Exploring Code Completions
Chapter 4: Chatting with GitHub Copilot
OceanofPDF.com
CHAPTER 3
Exploring Code Completions
In this chapter, we will do a deep dive into the code completion capabilities
of GitHub Copilot. We will cover all the details you need to get the most
out of Copilot code completions. While code completions are incredibly
intuitive, we will explore various features that will enable you to create
more refined solutions that meet the needs of your development plan.
Prerequisites
To follow along with this example, you will need the following
prerequisites installed:
Node.js:
https://nodejs.org/en/download
Top-Level Comment
Building on the filename and type, you can add a filename comment to your
code file to add more context to Copilot's decision engine.
Within the roman-to-integer.js file, type the following comment:
/**
* create a node.js app that gets a roman numeral via user
input
* and outputs the correct integer value
*/
After typing this comment, hit the Enter key and wait for Copilot to respond
with a code completion suggestion. If you don't see one, you can initiate a
response with the keyboard shortcut (Option+\ or Alt+\), as shown in Figure
3.1.
Now you should be able to run the js file via Node. Open your terminal via
the keyboard shortcut (Ctrl+`) or with the command menu (see Figure 3.3).
Now, within the terminal window, type the following:
node roman-to-integer.js
Hit the Enter key, and you should see the prompt from the Node.js app,
allowing you to provide a Roman numeral.
This should have provided you with a working example of an application
that can convert Roman numerals to integers. In the next section, we will
explore how you can expand upon this example using other methods of the
code completion feature set.
You should now be able to see your validation method in action, with
output shown to the user if they were to input an incorrect Roman numeral
(see Figure 3.6).
Figure 3.6: Validation method output test
Hit the Enter key after this comment and wait for Copilot to respond with a
suggestion. If Copilot does not initiate a code completion suggestion, you
can manually trigger this by using the keyboard shortcut (Option+\ or
Start+\). You should get something like Figure 3.7.
After entering the top-level comment, hit the Enter key and begin to review
and accept the code completions that Copilot is providing. You will see
Copilot adapting the code to meet the need of this new file while following
the coding design of the open roman-to-integer.js tab.
inlineSuggestCount
Update this value if you would like to control the maximum number of
inline suggestions that are produced.
length
The length setting allows you to specify a maximum length for code
suggestion responses.
listCount
The listCount setting (Ctrl+Enter) controls the limit of code suggestions
that you will be shown.
Leveraging Keyboard Shortcuts
Keyboard shortcuts help keep us in the flow of coding by allowing us to
keep our hands on the keyboard while typing commands and code. Let's
look at ways we can leverage Copilot's keyboard shortcuts to help us work
even faster while interacting with our pair programming assistant.
You can access the Copilot keyboard shortcuts from the Copilot Status
menu viewable after clicking the Copilot extension icon on the bottom
toolbar. You can also quickly access them via a keyboard shortcut (Cmd+K
Cmd+S/Ctrl+K Ctrl+S). After opening the Keyboard Shortcuts panel, you
can filter down to the Copilot shortcuts to view all that are available (see
Figure 3.13).
There are bindable keyboard shortcut commands for nearly all of the
Copilot actions that you can take. There is also a subset that have
predefined keybindings. As you use Copilot more, make sure to take note of
repetitive tasks that you are performing and consider making a keybinding
for that action. The following are my suggestions.
Figure 3.13: Keyboard shortcut settings
Mac: Shift+Cmd+C
Windows: Shift+Alt+C
Doing this enables you to quickly view the menu view for Copilot Chat.
This can speed up your workflow for ongoing conversations you are having
with Copilot about your code.
Suggest Terminal Command
The Suggest Terminal Command action will open the Inline Chat dialog
when you are within the editor window. This command will also open the
quick chat view with the @terminal command when you are in the
integrated terminal window.
Mac: Cmd+I
Windows: Control+I
Mac: Option+\
Windows: Alt+\
Mac: Option+]
Windows: Alt+]
Mac: Ctrl+Enter
Windows: Ctrl+Enter
Conclusion
In this chapter, we have covered in detail GitHub Copilot's code completion
capabilities, which are crucial for enhancing your coding efficiency and
creativity. By introducing code completions, demonstrating how to work
with Copilot, discovering its toolbar and panel, reviewing settings, and
leveraging keyboard shortcuts; this chapter empowers you with the
knowledge to harness Copilot's potential. As we've seen, Copilot is more
than just a tool for generating code; it's a partner in your development
process, enabling the creation of refined solutions that align with your
unique development goals.
OceanofPDF.com
CHAPTER 4
Chatting with GitHub Copilot
While code completions allow for tightly integrated responses to keep you
in the flow of coding, Copilot Chat enables you to have robust
conversations about your code in an intuitive way. Copilot Chat can help
you understand code, learn new topics of interest, refine code files, write
tests, create documentation, and learn the features of Copilot.
Let's dive in to the things that you need to know to get working with
Copilot Chat!
Editor Context
In VS Code, to give Copilot context to the file you are currently editing, use
the #editor tag in your prompt (see Figure 4.11). This will give Copilot the
code you are currently viewing in your editor as context.
Figure 4.11: Copilot prompt with the #editor tag
In other IDEs, the #editor tag may not be available, even though the
Copilot team attempts to align features and user experiences whenever
possible.
In this example, we used the following prompt:
@workspace /explain #editor
This allows us to get a full definition of the code within the editor window.
File Context
If you don't have the file open that you know you want an answer about,
you can use the #file tag to specify the file you would like to have
considered. You can also use the #file tag for multiple files within a single
prompt if necessary (see Figure 4.12).
In the previous example, when we enter #file, we will see a menu appear.
Select that option, and you will then see a search box to find the appropriate
file. After selecting your file, you will see the #file tag with the associated
file in your prompt.
Adding context via the #file tag may differ from one IDE to the next. The
Copilot team attempts to align features whenever possible.
Selection Context
When interacting with Copilot via a chat window, if you have text selected
in your editor, Copilot will automatically use that code as context for the
prompt that you send.
You can also specify declaratively to Copilot that you would like it to
consider the selected text by using the #selection tag.
Currently, this tag is implemented only in VS Code. In the future, this may
change.
If you are working in an editor, you can use the Copilot menu to initiate
quick commands. In this case, let's use the Explain This menu item (see
Figure 4.13).
Figure 4.13: Copilot's Explain This command
Now within the file editor, you can activate inline chat (Cmd+I/Alt+I) and
type / to get a list of the available commands within the inline chat dialog.
You can now select the /explain command. If you have a question about
code you are working on, make sure to select the code in question before
sending your question to Copilot (see Figure 4.14).
Figure 4.14: Inline chat /explain command
If you prefer, you can also Copilot questions about your code from the
sidebar chat window. Just make sure to highlight the code you would like to
have explained (see Figure 4.15).
Copilot is also able to give you a full explanation about the current file you
are reviewing. To do this, simply use the #editor tag in your prompt to
indicate to Copilot that you would like to have it consider the visible section
of your working document.
Working within the terminal is deeply engrained in the workflows of
developers all over the world. But when something goes wrong within your
terminal, or you don't understand an error that has occurred, lean on Copilot
to assist you in getting an answer quickly and bespoke to your pressing
needs. When an error occurs, you can use the sparkle icon as your quick
path to an explanation by Copilot (see Figure 4.16).
Figure 4.15: Chat window /explain command
Figure 4.16: Sparkle menu's Explain using Copilot command
If you don't have the quick fix menu available, you can highlight the
terminal lines in question and use the Copilot menu to initialize a quick chat
with Copilot to get an answer in a snap (see Figure 4.17).
Figure 4.17: Terminal window's Copilot: Explain This command
NOTE You can guide Copilot into creating better unit tests by
having an example file open with existing unit tests that match the
structure you would like. Also, you can include prompt details like
the type of tests you would like or the testing libraries that should
be used.
Within the chat window with Copilot, you can use the /tests command as
well. You still need to provide Copilot with the context of your preferred
test method by selecting it, or you can reference the visible section of the
editor via the #editor tag (see Figure 4.20).
After you have executed the /tests command with one of the methods
shown previously, you should end up with output that allows you to start
testing your method to ensure it is functioning properly (see Figure 4.21).
Figure 4.19: Inline chat /tests command
Figure 4.20: Window chat /tests command
Figure 4.21: Copilot-generated test file
With this test file, you can see that Copilot has created a good list of
assertions that will ensure you have a well-functioning method. From this
starting point, you can add assertions for floating-point numbers, strings,
and nonarray input values. You can use code completions or chat to
brainstorm additional test cases that you would like to add.
With this request submitted, you will see a response from Copilot with a
suggested workspace structure (see Figure 4.24). This structure will align
with your initial request and combine it with the project standards for the
language and any additional details you provided in the request.
Conclusion
In this chapter, we have meticulously explored the diverse interaction
mechanisms available with Copilot via Chat, offering a comprehensive
guide to harnessing this powerful tool within the development workflow.
By navigating through sidebar conversations, editor views, inline queries,
and the strategic use of context-specific tags, we have uncovered the depth
of Copilot Chat's capabilities in understanding and assisting with coding
tasks. This detailed examination not only sheds light on the versatility and
adaptability of Copilot Chat but also underscores its significance as an
intelligent assistant that can enhance coding efficiency, facilitate problem-
solving, and foster a more intuitive coding environment.
Leveraging the insights from this chapter, you can capitalize on the full
spectrum of functionalities offered by Copilot Chat. Whether it's refining
code, debugging, writing tests, or generating documentation, Copilot Chat
stands ready as a collaborative partner, equipped to navigate the
complexities of software development alongside you.
OceanofPDF.com
Part III
Practical Applications of GitHub
Copilot
In This Part
Chapter 5: Learning a New Programming Language
Chapter 6: Writing Tests with Copilot
Chapter 7: Diagnosing and Resolving Bugs
Chapter 8: Code Refactoring with Copilot
Chapter 9: Enhancing Code Security
Chapter 10: Writing Tests
Chapter 11: Enhancing Development Environments with Copilot
Chapter 12: Universal Conversion with GitHub Copilot
OceanofPDF.com
CHAPTER 5
Learning a New Programming Language
In this chapter, we will explore how you can interact with Copilot to learn a
new programming language. With Copilot, you can quickly get answers to
questions about languages, gain bespoke insights based on your previous
knowledge, get examples, run tests, and ask questions as you learn, all
within the integrated development environment (IDE)!
The chapter will be using VS Code to showcase how to learn with GitHub
Copilot and will be using Copilot Chat extensively. It is important to note
that Copilot Chat is not available in all IDEs. In addition, the Chat
experience is slightly different from one IDE to another. Although there are
differences, most of the information shared will be transferrable to other
IDEs.
Prerequisites
To follow along with this example, you will need the following
prerequisites installed:
Setup Guide
The first thing you need to do when learning a new language is ensure that
your development environment is configured properly. In the example you
will see in this chapter, you will be learning the C# programming language.
Let's leverage Copilot Chat to help set up the environment. The following
will get Copilot to guide us to the necessary resources and steps to get
started (see Figure 5.1):
help me setup my computer to run c#
Figure 5.1: Copilot chat instructions
The prerequisites that Copilot correctly identified before we can run a C#
application is the .NET Core SDK. It is also useful to have an IDE, so
Copilot has suggested Visual Studio Code. Head to the following URL to
download the .NET Core SDK:
https://aka.ms/dotnet-core-download
After you have installed the .NET Core SDK to enhance your developer
experience within VS Code, it is helpful to have the C# extension as Copilot
has indicated in the setup instructions. If you are not in VS Code, you will
still be able to run the C# application using the dotnet command-line
interface (CLI).
Let's navigate to the Extensions panel on the Action Bar. You will find the
Extensions panel identified by the “squares” icon (see Figure 5.2).
Microsoft encourages you to install the C# Dev Kit, which contains the C#
extension. For the purposes of this demo, you will just need the C#
extension. But if you are interested, exploring the features of a rich
developer experience via the C# Dev Kit might interest you.
GitHub account:
https://github.com/signup
Prerequisites
To follow along with this example, you will need the following
prerequisites installed:
When giving instructions to Copilot, context and clarity are critical for you
to receive the output you would like. In this case, specifying the dotnet
version, language, project name, and test framework gave Copilot the
context needed to give you a great result.
Now let's explore how you can converse with Copilot to discover how to
create a C# console application and run it manually. Remember, you can
create a prompt specific to your topic of choice so that Copilot gives you
instructions that are targeted to you. Try prompting Copilot with something
like the following:
How do I create a c# console app and run it?
With this prompt to Copilot Chat, you should get a result indicating the
steps required to run a C# program in VS Code. This will include things
like the following (see Figure 5.4):
7. Open your project in VS Code with the code . command within the
terminal window.
Figure 5.4: Copilot response for how to create C# console app
After following these steps, you should have a VS Code window with the
pirate example project created (see Figure 5.5).
Figure 5.5: C# console application project in VS Code
With the example C# application, you can now continue to add code to
explore the language features of C#. Let's open Copilot Chat to get a
Pirate class started so that you can learn more.
After opening Copilot Chat, you can enter a prompt like the following:
Create a C# Pirate class with name, age, and ship properties
This prompt adds enough context about your technology and language of
choice to produce a consistent result. The less context you provide Copilot,
the more freedom it will have in giving you responses. In this case, you
should see something like Figure 5.6). With this response code, you should
be able to create a Pirate.cs class from the code generated by Copilot.
Figure 5.6: Copilot chat response to request to create a Pirate class
Figure 5.7: Copilot /explain chat command for Pirate class file
This will result in Copilot providing you with a new method Insert of code
suggestion that enables you to quickly extend the functionality of the
Pirate.cs class.
Copilot will respond with several valid reasons to this common practice,
including separation of concerns, avoiding deployment of test code,
dependency management, build performance, and organization
considerations.
Copilot Chat within VS Code allows you to copy code snippets to your
clipboard, insert code into your current file, create a new file, or insert code
into the terminal. Here you can leverage the insert into terminal
functionality (see Figure 5.10).
Figure 5.10: Copilot chat insert into terminal
After you run the command dotnet new nunit -n
PiratesExample.Tests, the PiratesExample.Tests project should be
created.
You can then follow Copilot's next suggestion to add a reference to the
PiratesExample project. Enter the following command into the terminal:
Copilot should have suggested how to run our unit tests project. If it hasn't,
you can ask for a dotnet CLI command to run unit tests, and you should be
able to see the command for this is dotnet test. After running this, you
will see an error indicating the working directory does not contain a project
or solution due to us moving out of the PiratesExample project. You can
use the quick-fix menu and have Copilot give you a justification and
potential fix for the terminal issue we have encountered (see Figure 5.11).
Figure 5.11: Copilot explaining the last terminal command via a quick-fix
menu
Now that you know how to properly run the dotnet test command, you
can run it and get a successful build and run of the test project (see Figure
5.12).
With the unit test project now running, you can have Copilot create a
starting point for exploring how to test the Pirate.cs class. Let's begin by
opening the Pirate.cs file. To create a test for the Greeting() method, it is
important to give Copilot the context it needs in order to create a quality
starting point for the test file. You can do this in a couple of different ways.
After typing the #file tag, you should see a menu to select the file that you
want to reference. With this prompt, you should get a similar result to the
previous example using the selected text for the entire file.
Running Tests
Now that you have generated a baseline test for the Pirate.cs Greeting()
method, you can add this generated code to the test project. After adding
this file, you can run the dotnet test terminal command to initiate a new
test (see Figure 5.14).
In my case, I needed to add namespace to the Pirate.cs class on the first
line of the file for the generated unit tests to run.
namespace PiratesExample;
// greeting method
public string Greeting()
{
return $"Ahoy! My name is {Name}, I am {Age} years
old. I sail on the {Ship}.";
}
Conclusion
This chapter provided a comprehensive guide on how to utilize GitHub
Copilot to learn a new programming language. Copilot's ability to provide
bespoke insights and examples tailored to your interests and needs makes
the process of learning a new programming language less daunting and
more engaging.
This chapter highlighted the flexibility and power of using Copilot in an
IDE like VS Code. Whether you're exploring basic concepts, adding new
code, or learning through testing, Copilot serves as a valuable companion
that accelerates the learning curve and enriches the educational experience.
This practical application has shown you how Copilot can act as a mentor
that guides you through the intricacies of a new programming language,
leveraging your previous knowledge and adapting to your learning style. As
you've seen with the C# example, Copilot can provide personalized
assistance every step of the way, regardless of the programming language
you choose to learn, from setup to sophisticated coding practices.
Reference
[1] TIOBE, “TIOBE Index for February 2024,” 2024. [Online]. Available:
https://www.tiobe.com/tiobe-index
OceanofPDF.com
CHAPTER 6
Writing Tests with Copilot
Testing is a cornerstone of software development, ensuring that code not
only works as intended but also is robust and reliable. In this context,
GitHub Copilot emerges as a transformative tool, offering developers an
AI-powered assistant capable of streamlining the testing process. Through
its ability to suggest, generate, and refine test cases, GitHub Copilot
enhances both the efficiency and coverage of software tests.
This chapter aims to explore the practical benefits of leveraging GitHub
Copilot for writing tests. From unit and integration tests to more specific
scenarios like testing regular expressions and form input validators, we'll
demonstrate how GitHub Copilot can accelerate the creation of
comprehensive test suites.
The project example you will be using is a simple to-do application. In this
first section, you will be setting up the application programming interface
(API) for the project so that you can see how GitHub Copilot can facilitate
creating several different types of tests for a back-end API.
The API project used in this chapter is a NestJS API. This framework
provides a robust testing suite and will enable us to cover several topics
from unit tests to integration tests and show how to leverage Copilot to
assist write tests along the way.
Prerequisites
To follow along with this example, you will need to install the following
prerequisites:
Node.js:
https://nodejs.org/en/download
NestJS:
https://docs.nestjs.com/first-steps
Jest extension:
https://marketplace.visualstudio.com/items?
itemName=Orta.vscode-jest
With the start script running, open a second terminal and run the following
command:
npm run test:watchAll
You will now have unit tests triggered on each change that will output
coverage results.
Lastly, if you would like to see inline test coverage results, run the
coverage gutters: watch process via the command palette or with the
right-click menu from any open editor.
After adding a new line under this comment, you will see a code
completion suggestion from Copilot (see Figure 6.1).
Given the context that you have provided Copilot, you should get a quality
starting point for the unit test that will cover the create() method in the
todo.controller.ts tab that is open adjacent to the test file. After running
this test, you will see that this does not match the expected result of the
service layer (see Figure 6.2).
If you had opened the todo.service.ts file before typing the inline
comment for the new test, Copilot would have created a test that aligns with
the existing code in the service. This service code currently returns a
placeholder string instead of an object type.
Figure 6.1: Test code completion from an inline comment
Figure 6.2: Test failure from the new test
Later you will find that it will be necessary to modify this code to mock the
results from the service layer to remove the dependency on an external
database call.
Let's add an isCompleted property to the service result object that you are
expecting in the unit test to round out what you would like to have returned
from the service function when creating a new to-do item (see Figure 6.3).
Figure 6.3: Is Completed Property added to the test object result
Let's update the create-todo.dto.ts DTO and todo.entity.ts entity
files with the following properties:
export class CreateTodoDto {
title: string;
description: string;
}
export class Todo {
id: number;
title: string;
description: string;
isCompleted: boolean;
}
Now that you have a test case and object types that represent the desired
result from the service layer, let's refactor the todo.service.ts file to align
with this unit test and get a passing test.
With the new properties added to the DTO and entity classes, let's update
the create method to align with the expected result from the unit test. For
this update, you can utilize Copilot code completions to help guide you in
typing out the return object.
create(createTodoDto: CreateTodoDto): Todo {
return {
id: 1,
…createTodoDto,
isCompleted: false,
};
}
After you update the create() service function to align with the object type
properties specified earlier, you can then run the tests and you should see a
passing result (see Figure 6.4).
Setup
To begin, let's first use the NestJS command-line interface (CLI) to add a
new resource to the codebase for your users. In a terminal window at the
project root, execute the following command:
nest g resource user
After choosing the REST API and clicking Yes to the CRUD entry points,
you should have a new resource added to the todo-api codebase (see
Figure 6.7).
Conclusion
As you have seen in this chapter, GitHub Copilot can greatly enhance your
ability to write quality tests in a variety of situations. Whether you are
writing unit tests for existing code, integration testing a new system
component, or doing end-to-end testing on a vertical slice of your system
functionality, Copilot is there to help you create test suites that are more
robust while allowing you to stay in the flow of coding new features.
OceanofPDF.com
CHAPTER 7
Diagnosing and Resolving Bugs
In this chapter, you will take a closer look at how Copilot can help you
diagnose and resolve bugs. In these chapter examples, you will see a variety
of circumstances that Copilot enables you to resolve coding issues without
leaving your development flow.
Prerequisites
To follow along with this example, you will need to install the following
prerequisites:
Node.js:
https://nodejs.org/en/download
NestJS:
https://docs.nestjs.com/first-steps
Jest extension:
https://marketplace.visualstudio.com/items?
itemName=Orta.vscode-jest
ESLint:
https://marketplace.visualstudio.com/items?
itemName=dbaeumer.vscode-eslint
Open the integrated terminal in VS Code. At the project root, run the
following command:
npm install
After installing packages for the project, start the compilation mode
watching for changes and compiling when updates occur:
npm run start:dev
With the start script running, open a second terminal and run the following
command:
npm run test:watchAll
You will now have unit tests triggered on each change that will output
coverage results.
Lastly, if you would like to see the inline test coverage results, run the
coverage gutters: watch process via the command palette or with the
right-click menu from any open editor.
Setup
First let's add username and password properties to the create-
user.dto.ts DTO class.
With those properties in place, you can add some basic functionality to the
user.service.ts class.
// Import Statements
@Injectable()
export class UserService {
users: User[] = [];
create(createUserDto: CreateUserDto) {
const { username, password } = createUserDto;
this.users.push(newUser);
return 'Account created';
}
// Remainder of Code
}
With this code established, let's continue to add a unit test of this method
with a null DTO object. Open the user.service.spec.ts file and add a
comment to drive a test that will validate that the null reference scenario is
handled properly (see Figure 7.4).
// create null parameter throw BadRequestException
You can now open the user.service.ts file and add the necessary code to
throw BadRequestException when you receive a null parameter in the user
service function.
When you add a new line after the create method signature, you will likely
get a code suggestion from Copilot to add a guard statement against the null
parameter (see Figure 7.6). This is due to the context that Copilot has with
the adjacent test file tab open.
Figure 7.6: User service create method guard statement code suggestion
If you don't get a good suggestion from Copilot when adding a new line,
you can try typing out the first part of the if statement or adding an import
for the BadRequestException at the top of the file first.
After you accept this code from Copilot, you can save the file. With the
guard statement in place, the null reference test should pass (see Figure
7.7).
Figure 7.7: User service create method passing test for null reference
exception
Conclusion
In this chapter, you saw how GitHub Copilot can assist you with the
complexities of resolving syntax errors, smoothing over runtime exceptions,
and overcoming terminal errors. Interacting with Copilot has enabled you to
transform the debugging process from an isolated solo endeavor to a
collaborative pair-programming debugging session.
As you move forward with the knowledge from this chapter, look for ways,
unique to your codebase, that Copilot can assist you in having more bug-
free days and clean builds!
OceanofPDF.com
CHAPTER 8
Code Refactoring with Copilot
In this chapter, you will learn how to use Copilot as a refactoring pair-
programming assistant. While code refactoring tools such as VS Code
language services and JetBrains ReSharper help you make safe refactors for
your code, you can use Copilot as a pair programmer in your refactoring
efforts. Copilot can assist you in exploring better ways to write your code
and even assist you when making changes. You can download a copy of the
starter project todo-api-ch08-starter in the Chapter 8 folder.
www.wiley.com/go/programminggithubcopilot
Node.js:
https://nodejs.org/en/download
NestJS:
https://docs.nestjs.com/first-steps
Open the integrated terminal. At the project root, run the following
command:
npm install
After installing the packages for the project, start the compilation mode
watching for changes and compiling when the updates occur.
npm run start:dev
After this, you can open a second integrated terminal and run the following
command:
npm run test:watchAll
You will now have unit tests triggered on each change that will output
coverage results. You will continue using the VS Code extension Coverage
Gutters. This extension uses the coverage output to show you which lines of
code have been covered by the unit tests.
You can activate the “coverage gutters: watch” process via the command
palette or via the right-click menu from any open editor.
When running the npm run test:watchAll command in the terminal, you
may notice the NestJS error logs. Those are from the unit tests that are
covering the logger.error() statements within the user.controller.ts
class.
Refactoring Validators
Validation logic starts simple in a lot of projects but can quickly outgrow its
container functions, causing increased complexity and reduced
maintainability of the code.
The next focus area will be in the user.service.ts file. Here you have a
create() method that has validation code for the username and password
fields. While it is good to add guard clauses and validation for the user-
provided input, placing large quantities of code with varied responsibilities
in a single function will cause decreased maintainability. Let's explore how
you can add tests and refactor this code with Copilot.
NOTE When using the #file variable within the Copilot chat,
you must use the drop-down menu to select the file.
Figure 8.13: User service create method extended code refactoring result
Figure 8.14: Copilot chat response to additional refactoring that could be
done for validation code
Use Middleware for Validation: You can use middleware to validate
the request data before it reaches your service methods. This way, your
service methods will only run if the request data is valid.
Use Decorators for Validation: In NestJS, you can use decorators like
@IsString(), @IsNotEmpty(), @Length(), etc., from the class-validator
package in your DTOs. This will automatically validate the incoming
request data based on the decorators you've used.
Separate Validation to a Different Method or Class: If you don't want
to use middleware or decorators, you can at least separate the
validation code to a different method or even a different class. This
will make your service methods cleaner and easier to read.
Use a Validation Library: There are many validation libraries
available for TypeScript/JavaScript like Joi, Yup, etc. These libraries
provide a declarative way to define validation rules and can make
your validation code cleaner and easier to manage.
Interacting with Copilot to plan your refactoring techniques and get
actionable results is a powerful tool. In this example, you can explore a
variety of code refactoring options and choose the right solution for your
needs.
After submitting this request to Copilot, you will receive an inline refactor
with an explanation of the suggested refactor (see Figure 8.16).
Figure 8.15: Copilot inline chat refactor bad variable names prompt
Figure 8.16: Copilot inline chat refactor bad variable names refactor result
There are many ways to accomplish renaming refactors in your code. When
renaming variables, Copilot works best when targeting single-file updates.
When you start to modify code that might have external dependencies,
using our IDE-based tooling can ensure the reactor is accounting for the
external file references and adjusting those files as well.
Figure 8.17: Copilot inline chat add documentation to user service class
After submitting this request to Copilot, you should get a response with the
method descriptions for all the methods in the UserService class. You will
see that you have seven changes you can cycle through and choose to
accept or discard those suggested documentation blocks (see Figure 8.18).
Figure 8.18: Copilot inline chat add documentation to user service class
result
This initial response from Copilot was great. Always review each of the
modifications that Copilot provides and ensure they match the functionality.
You can now benefit from these documented methods and better understand
the inputs, outputs, and expected behavior (see Figure 8.19).
Project Documentation
With all the hard work you have put into your project, you need to make
sure you document the overall project and allow other contributors to
understand your project structure and features.
You will use Copilot chat to create a baseline readme.md file for the todo-
api project. Opening the Copilot chat window, you can add the following
command to get Copilot to generate documentation for you:
@workspace Please write a readme for my todo-api project.
After you submit this request to Copilot, you should get a result with
bespoke details for your project (see Figure 8.20).
Figure 8.19: Function documentation refactor completed
Figure 8.20: Copilot chat response to generate the project README.md file
Here you can see that Copilot used six files from the codebase and created a
great starting point for you to have a useful and detailed descriptive
README.md file.
From my testing, it seems the best way to get the generated markdown for
the Copilot response is to right-click the response area and click Copy. This
will allow you to paste the markdown in your project README.md file.
Conclusion
This chapter touched on the history of refactoring code, the tools and
techniques used today, and how you should best incorporate Copilot into
your code refactoring workflow.
You looked at examples from a project that showcased Copilot's ability to
assist you in creating a test suite to enable confident refactoring of code.
After establishing some tests, you explored how Copilot was able to assist
in a variety of refactoring tasks, from duplicate code reduction to
documentation. Through these examples, I hope you have seen how Copilot
can be an asset to you as you refactor your codebases.
OceanofPDF.com
CHAPTER 9
Enhancing Code Security
In this chapter, you will be equipped with the ability to fully utilize GitHub
Copilot to assist you in enhancing your code security. This chapter will
outline the importance of security, how Copilot can assist you in learning
about security vulnerabilities and best practices, and ways to apply that
knowledge to your codebase to make corrective measures before releasing
insecure code to your users.
The OWASP top 10 list is a great start for teams to understand the most
prominent security threats facing the software industry. While this
information empowers developers to make changes to their code, it is
important to implement a multifaceted security suite to protect against
security threats.
With the increasing complexity of modern web applications and the steady
rise in security threats, application security has become a critical part in the
software development life cycle (SDLC). The need for enhanced
application security gave rise to the term application security development
operations (DevSecOps). Traditional security practices often struggle to
keep up, leading to vulnerabilities being discovered late in the process or
even after deployment, when they are costly and disruptive to fix.
DevSecOps addresses this by integrating security practices directly into the
SDLC. This “shift left” approach ensures that security is considered at
every stage of development, from initial design through deployment and
maintenance. Automated testing, continuous monitoring, and proactive
threat modeling become integral parts of the process, enabling teams to
catch and fix issues early when they are easier to manage.
In this chapter, you will learn how GitHub Copilot can be used to assist in
producing secure code. This chapter will also detail how Copilot can be
used to help you learn about security best practices and vulnerabilities
specific to your codebase.
Prerequisites
To follow along with this example, you will need the following
prerequisites installed:
Node.js
https://nodejs.org/en/download
NestJS
https://docs.nestjs.com/first-steps
Jest extension
https://marketplace.visualstudio.com/items?
itemName=Orta.vscode-jest
ESLint
https://marketplace.visualstudio.com/items?
itemName=dbaeumer.vscode-eslint
Open the integrated terminal. At the project root, run the following
command:
npm install
After installing packages for the project, start the compilation mode
watching for changes and compiling when updates occur:
npm run start:dev
After this, you can open a second integrated terminal and run the following
command:
npm run test:watch
Let's examine how you can take the conversation further to get actionable
suggestions for some of these security controls.
Using HTTPS
Continuing the conversation, ask Copilot the following:
How do I use HTTPS in a NestJS API?
With this request, Copilot will return detailed, step-by-step instructions for
you to produce a certificate for testing purposes and make the appropriate
modifications to the main.ts file of your application (see Figure 9.2).
Figure 9.2: Copilot Chat response for how to use HTTPS in a NestJS API
Implementing Validation
Up next, let's see what Copilot suggests for validation. Ask Copilot the
following:
How to do input validation in a NestJS API?
With this request, Copilot will return another detailed response with
specific instructions to implement this security control (see Figure 9.3).
Figure 9.3: Copilot Chat response for how to do input validation in a
NestJS API
In this case, you can see that Copilot gives necessary package installations,
DTO object modifications, controller class update requirements, and
instructions for implementing a global pipeline validator.
Conclusion
As you can see from this example, with some basic questions about
security, you can navigate the complexities of securing a modern API. Make
sure to always verify the suggestions with Copilot if you are unsure of the
suggested result.
This request should give you a result indicating that the code has weak
password hashing, potential SQL injection, error handling leaking sensitive
data, lack of rate limiting, no salting of password, and password validation
enhancements that are needed (see Figure 9.4).
Figure 9.4: Copilot Chat response for user service security issues
Now that you have these insights into security issues that may need to be
addressed, Copilot can continue to help as you navigate the modifications
required to fix the security issues found.
Now, instead of navigating around the file to adjust imports, you can utilize
Copilot inline chat to make the necessary adjustments to code. With the
hashPassword() function selected, activate the Copilot inline chat.
You can then provide a request to Copilot using the /fix command to
resolve the hashing refactor (see Figure 9.6).
/fix the hash password function to use bcrypt
Figure 9.6: Copilot Chat response for how to fix weak password hashing
After Copilot processes the request, you should see a preview of the
suggested refactors and an explanation for the adjustments that have been
applied. In this case, two changes are provided. One change is for the
function doing the password hashing, and the other change is to add the
import for the bcrypt library.
NOTE When adjusting existing code with the Copilot inline chat,
using the /fix command will be better suited to make multiple
adjustments in the current file.
Conclusion
In this chapter, Copilot proved to be a powerful asset in the software
development lifecycle when confronting security issues. Through practical
application within the example project, you saw how Copilot not only
identifies vulnerabilities but also guides the implementation of robust
security measures. As you move forward, let the insights gained here inspire
a deeper integration of Copilot into your security practices.
OceanofPDF.com
CHAPTER 10
Accelerating DevSecOps Practices
In this chapter, you will learn how Copilot can assist in several DevSecOps
tasks. DevSecOps tasks can be complicated to learn and implement. With
Copilot by your side, you will be empowered to create the necessary
resources and actions that will get your application from concept to center
stage.
Detailing DevSecOps
Simplifying Containers
Automating Infrastructure as Code
Streamlining CI/CD Pipelines
Detailing DevSecOps
DevSecOps, short for development, security, and operations, is a software
engineering culture and practice that aims to unify software development
(Dev), security (Sec), and operations (Ops).
To practice DevSecOps, security needs to be considered at every phase of
the software development life cycle (SDLC) (see Figure 10.1).
As you can see from Figure 10.1, in addition to the development tasks, the
release, deployment, operation, and monitoring tasks all play a vital role in
successful software delivery with security embedded at every task.
Figure 10.1: DevSecOps diagram detailing security considered at each
stage of the DevOps cycle
Here are some key points:
In all these areas of DevSecOps, Copilot can be leveraged. Whether you are
considering a CI/CD pipeline, security vulnerability scanning, or production
monitoring, Copilot is there to gain insights, ask questions, and help create
resources that will allow your application to take flight.
Simplifying Containers
A container is a lightweight, stand-alone, and executable software package
that includes everything needed to run a piece of software. This includes the
code, a runtime, libraries, environment variables, and config files.
In this section, you will see how Copilot can assist in writing container
configuration files and support running the application within a container.
Creating a Container
Let's explore how Copilot can assist in creating a container to run a NestJS
API. To showcase this capability, open a Copilot Chat window. After you
have that open, you can enter a prompt to request help to create a container.
Request to Copilot (see Figure 10.2):
Help me create a production container for my NestJS API
project.
Figure 10.2: Copilot Chat response for how to create a container for a
NestJS API
You will see Copilot respond with a Dockerfile and instructions on how to
build and run the image.
Within this resulting Dockerfile, Copilot suggests the use of Node.js version
14. GitHub Copilot is trained on a large dataset of publicly available code,
but it doesn't know specifics about which libraries or versions it was trained
on. The base functionality of Copilot doesn't have the ability to access or
retrieve information beyond its training data. With this functionality in
mind, it is always important to ensure the version numbers and syntax
match the current versions and syntax is matched to the needs you have.
You can add context to Copilot with example files of current standards or
library versions to get a generated output that aligns better with your needs.
Here is the Docker file that Copilot returned:
# Define the base image
FROM node:14
# Install dependencies
RUN npm install
In addition, Copilot gave instructions on how to build and run the Docker
image.
docker build -t my-nestjs-app .
docker run -p 3000:3000 my-nestjs-app
Deploying a Container
Copilot has provided a great follow-up prompt given the initial question
about a container for an API project. If you did not receive this prompt, you
can submit the following to see how you could deploy a container to a
cloud platform (see Figure 10.3).
Insert your cloud platform of choice to receive detailed instructions targeted
to your specific needs.
Here is the request to Copilot:
How can I deploy my Dockerized NestJS API to a cloud
platform?
Figure 10.3: Copilot Chat response for how to deploy a Dockerized NestJS
API to a cloud platform
Figure 10.5: Copilot Chat response for what security controls can be
applied to a Dockerized NestJS API
You will see Copilot respond with a detailed step-by-step plan to create
your IaC using Terraform. Copilot should also suggest a basic example of a
main.tf file that will provision the resources required for a NestJS API (see
Figure 10.6).
Here is the Terraform file:
provider "aws" {
region = "us-west-2"
}
tags = {
Name = "nestjs_api"
}
}
ingress {
from_port = 3000
to_port = 3000
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}
container_definitions = <<DEFINITION
[
{
"name": "nestjs-container",
"image": "<your-dockerhub-username>/nestjs-api",
"essential": true,
"portMappings": [
{
"containerPort": 3000,
"hostPort": 3000
}
]
}
]
DEFINITION
}
Creating CI Pipeline
Starting with continuous integration to the source code repository, you will
see how Copilot can support the creation of automated tasks that allow for
quality contributions to your application codebase (see Figure 10.8).
Here is the request to Copilot:
Help me create a continuous integration pipeline for my
NestJS API project dev branch and pull request.
Figure 10.8: Copilot Chat response for help creating a continuous
integration pipeline
This result from Copilot provides a good starting point for a GitHub
Actions–based CI pipeline that will support listening for changes to your
repository branch of choice, building the application, and running any tests
that the application has.
Here is the GitHub workflow .yml file:
name: CI
on:
push:
branches: [ dev ]
pull_request:
branches: [ dev ]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [12.x]
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- run: npm ci
- run: npm run build --if-present
- run: npm test
Like previous responses from Copilot, the Node.js version is not reflective
of what would work for a modern NestJS API project today. So, as always,
remember to review the output provided by Copilot for accuracy to the
needs of your project.
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [12.x]
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- run: npm ci
- run: npm run build --if-present
- run: npm test
codeql:
name: Run CodeQL
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
Creating CD Pipeline
Now that you have a CI GitHub Action established, the next thing needed is
to release changes to environments for functional testing, pen testing,
staging validation, and production delivery.
Create a new conversation with Copilot in a chat window and ask the
following (see Figure 10.10):
Help me create a continuous deployment GitHub Action for my
NestJS API project dev branch merges. Create a Docker image,
store the image, tag it, and release to a development AWS EC2
environment.
on:
push:
branches:
- dev
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
deploy:
needs: build
runs-on: ubuntu-latest
steps:
- name: executing remote ssh commands to deploy
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.SSH_KEY }}
script: |
docker pull your-dockerhub-username/your-repo-
name:latest
docker stop api-container || true
docker rm api-container || true
docker run -d --name api-container -p 80:3000 your-
dockerhub-username/your-repo-name:latest
This continuous delivery workflow file is a great start for you finalizing the
CI/CD process for a dev branch. Always remember to review and test code
and scripts provided by Copilot.
Conclusion
In this chapter, you saw how Copilot can be a great asset in the DevSecOps
process, enabling you to do more and stay in the flow. Even with
complicated tasks like infrastructure as code and security scanning in a
DevOps pipeline, Copilot has your back and will always be ready to support
you in your DevSecOps activities.
OceanofPDF.com
CHAPTER 11
Enhancing Development Environments with
Copilot
In this chapter, you will discover how Copilot can assist you in a multitude
of development environments. Whether you are running a command in the
terminal or creating an enterprise application in Visual Studio, Copilot has
you covered. Let's explore how you can get the most out of your IDE and
enhance your development workflow with Copilot.
Prerequisites
GitHub Copilot license
https://github.com/features/copilot
Window OS
https://www.microsoft.com/software-download/windows11
Visual Studio
https://visualstudio.microsoft.com/downloads
With those comments now in place, enter two new lines to get another
suggestion from Copilot. Within Visual Studio, you can also trigger a code
completion via the keyboard shortcut. For more information on keyboard
shortcuts and configuration of your Visuals Studio environment, check out
the official documentation at the following URL:
https://docs.github.com/copilot/configuring-github-
copilot/configuring-github-copilot-in-your-environment?
tool=visualstudio
Copilot will most likely suggest the statement using System;. After
accepting that line, add another two lines to the file and wait for another
code completion suggestion from Copilot. You should see Copilot
attempting to complete a console program that has user input and checks if
the input is a palindrome (see Figure 11.5).
Prerequisites
GitHub Copilot license
https://github.com/features/copilot
Azure Data Studio
https://azure.microsoft.com/products/data-studio
After successfully installing the Copilot extension, you should see a pop-up
in the lower-right corner of VS Code prompting you to sign in to GitHub.
Please use this option to sign in. If that does not appear, you can check your
login status via the account menu in the bottom-left corner of Azure Data
Studio.
After following the login instructions with GitHub, you need to ensure that
you have enabled GitHub Copilot globally via the bottom-right Copilot icon
(see Figure 11.10).
After adding this line, add a new comment. In my case, Copilot quickly
suggested a line indicating the database would store information about
customers. Continue the new line comment creation until you have a few
tables like this top-level comment:
-- SQL Server Database Schema
-- Create a database schema for a SQL Server database that
will store the following data:
-- 1. A table to store information about customers. Each
customer has a unique ID, a name, and an email address.
-- 2. A table to store information about products. Each
product has a unique ID, a name, and a price.
-- 3. A table to store information about orders. Each order
has a unique ID, a customer ID (from the customers table), a
product ID (from the products table), and a quantity.
With this comment in place, you can now proceed down two new lines and
lead Copilot to initiate the database schema creation if it doesn't already
start.
-- Create the customers table
With this comment, add a new line and then wait for a CREATE statement to
be created. Repeat this new line process to the bottom of the file until you
have three tables created for customers, products, and orders (see Figure
11.11).
Copilot will assist in writing the test data but will make you provide emails
to ensure that it is not injecting any predicted emails that would be realistic.
After finishing two records of customer data, finishing that statement, and
moving to another line, Copilot will assist with insert new test data. Add
sample data for the remaining products and orders table (see Figure 11.12).
Figure 11.11: SQL Server database schema
Figure 11.12: Copilot-assisted test data creation
After completing this comment, Copilot will again jump in to help you
complete the SQL query you are wanting to write (see Figure 11.13).
Figure 11.13: Copilot-assisted query creation
This example of GitHub Copilot within Azure Data Studio highlights the
impressive skillset and how Copilot can assist in creating database schemas,
constructing test data, and formulating complex queries.
Giving Copilot quality context is essential to the success of receiving
quality responses. You can accomplish similar tasks in other IDEs. And by
using skills like file tagging to reference database schema files, you can
create queries in separate files and allow Copilot to access your database
schema via a file reference.
Android Studio
AppCode
Aqua
CLion
Code With Me Guest
DataGrip
DataSpell
GoLand
JetBrains Client
MPS
PhpStorm
PyCharm
Rider
RubyMine
RustRover
WebStorm
To showcase GitHub Copilot in the JetBrains IDEs, in this section you will
learn how GitHub Copilot can be leveraged to help you do more within
IntelliJ IDEA.
Prerequisites
GitHub Copilot license
https://github.com/features/copilot
Figure 11.14: IntelliJ IDEA plugins search result screen with GitHub
Copilot
After installing GitHub Copilot, you will be prompted to restart the IDE.
Restart the IDE; after doing this, click New Project from the welcome page.
To see how Copilot can work within IntelliJ IDEA, let's create a
PalindromeChecker Java project (see Figure 11.15).
After creating the project, you should see a prompt to sign in to GitHub at
the bottom right. If you don't see this pop-up, you can also sign in via the
welcome screen to the GitHub Copilot window accessible in the left menu
(see Figure 11.16).
From this window or the Copilot icon on the bottom-right menu, sign in to
your GitHub account using the steps outlined by the authentication prompt.
After completing the top-level comment, add a second line to indicate valid
examples to help Copilot provide the best result possible.
// valid examples: racecar, taco cat
With those comments now in place, enter two new lines to get another
suggestion from Copilot. Copilot will most likely suggest an import
statement: import java.util.Scanner;. After accepting that line, add
another two lines and wait for another code completion suggestion from
Copilot. You should see Copilot attempting to complete a console program
that has user input and checks if the input is a palindrome (see Figure
11.17).
With this comment in place, add a new line and wait for Copilot to provide
a code suggestion. After you accept the next line, you can run the
application and test that the valid examples are returning the correct value
(see Figure 11.18).
Figure 11.18: Programing the test result with new code
Prerequisites
GitHub Copilot license
https://github.com/features/copilot
Neovim
https://neovim.io
Node.js
https://nodejs.org/en/download
After logging in to your GitHub account, you are now ready to enable
Copilot. Run the following command to enable Copilot:
:Copilot enable
Open the dad-jokes.js file with Neovim with the following command:
nvim dad-jokes.js
After opening the file, Copilot should be enabled from the installation steps,
so you can proceed to adding a top-level comment to the file. To start
editing the file, press the i key to activate “insert” mode. Start by typing the
following:
// Node.js script that fetches a random dad joke from the
icanhazdadjoke API
You will notice that Copilot, using the context of the filename, already
completes the ending of the comment (see Figure 11.20). You can accept
the request by hitting the Tab key.
Figure 11.20: Copilot completing a comment in Neovim
Add another comment to inform Copilot to use the https module:
// Use the https module to make a request to the API
After you have added the second comment, add two blank lines to the file.
You should then be prompted with a code suggestion with the https
variable declaration. Accept that line, and then add two more blank lines.
Copilot should suggest a comment or function for fetching the dad joke (see
Figure 11.21).
Figure 11.21: Copilot completing the fetchDadJoke()function
After accepting the fetchDadJoke()function, add two more blank lines and
make a call to the fetchDadJoke() function. After you are done, your file
should look like Figure 11.22.
With the export in place, hit the Esc key to stop editing. Now, save and quit
the file via the :wq command.
After you are back in the terminal, run the following command to test the
function (see Figure 11.23):
node dad-jokes.js
Now you can enjoy all the dad jokes you can handle thanks to Copilot! I
hope this example shed light on just how useful Copilot can be in the
context of Neovim/Vim.
For more extensive documentation, visit the DOC file for the Copilot Vim
plugin.
https://github.com/github/copilot.vim/blob/release/doc/copilot.
txt
Figure 11.22: Copilot completing the fetchDadJoke()function
Figure 11.23: Node.js call for dad jokes
Prerequisites
GitHub Copilot license
https://github.com/features/copilot
GitHub CLI
https://cli.github.com
If you want to upgrade your Copilot extension, you can run the upgrade
command:
gh extension upgrade gh-copilot
NOTE
The first time you run the gh copilot suggest function, you may
be asked to allow GitHub to collect usage data to help improve the
product. The data collected does not include your queries.
Figure 11.24: Copilot in the GitHub CLI
This will provide you with multiple options. You can get generic shell
command, gh command, or Git command assistance (see Figure 11.25).
Figure 11.25: Copilot suggest command result
In this case, you will see how Copilot can help you find how to search for a
file that contains a specific string (see Figure 11.26).
Figure 11.26: Copilot suggest generic shell command result
With this result, you can do many actions. You can copy, explain, execute,
revise, rate, or exit from the result.
Figure 11.27 shows the result if you explain the command and then execute
it.
In this result, you can see that Copilot provided a great explanation of the
command. Also, when attempting to directly run the command from
Copilot's CLI, there was an issue because of not having the ghcs alias set
up. You will see how this is configured at the end of this section.
You can also provide the Copilot suggest feature with the command you
want help with from the first step like this:
gh copilot suggest "Task that you want to run"
Explaining Commands with Copilot
To get insights about a particular command that you would like to know
more about, you can use the explain feature.
gh copilot explain
Figure 11.27: Copilot explains and executes the generic shell command.
This will initiate a similar experience as the suggest feature but is focused
only on providing you with an explanation of the command instead of the
ability to run it directly from the result (see Figure 11.28).
Figure 11.28: Copilot explain command result
Bash
echo 'eval "$(gh copilot alias -- bash)"' >> ~/.bashrc
PowerShell
$GH_COPILOT_PROFILE = Join-Path -Path $(Split-Path -Path
$PROFILE -Parent) -ChildPath "gh-copilot.ps1"
gh copilot alias -- pwsh | Out-File ( New-Item -Path
$GH_COPILOT_PROFILE -Force )
echo ". $GH_COPILOT_PROFILE" >> $PROFILE
Zsh
echo 'eval "$(gh copilot alias -- zsh)"' >> ~/.zshrc
After you have updated your configuration file, close your shell and re-open
it. You will then have access to use the ghcs and ghce aliases.
References
[1] GitHub, “GitHub Copilot for Vim and Neovim” 2024. [Online].
Available: https://github.com/github/copilot.vim
[2] GitHub, “Using GitHub Copilot in the CLI” 2024. [Online]. Available:
https://docs.github.com/en/copilot/github-copilot-in-the-
cli/using-github-copilot-in-the-cli
Conclusion
In review, I hope this chapter has given you insights into just how helpful
GitHub Copilot is in development environments. The team at GitHub is
continuing to innovate, taking Copilot to more places to assist engineers
where they work best.
OceanofPDF.com
CHAPTER 12
Universal Conversion with GitHub Copilot
In this chapter, you will discover the compelling use of GitHub Copilot for
universal conversion in software development. Copilot can assist in
translating languages, frameworks, libraries, databases, or CI/CD pipelines.
With Copilot by your side, you are empowered to transition between
technologies with incredible speed. This opportunity to use the technologies
that you require with speed and accuracy is a game-changing capability.
Let's jump to the examples of how Copilot can supercharge your
development workflow when translation is required.
Here you can see that Copilot created an Angular button component that has
the appropriate naming convention of the file noted and file structure that is
best practice for Angular and applies indention correctly. Figure 12.4 shows
the resulting Angular button component.
Figure 12.4: React to Angular
This could be extended to any other component type that you might need to
convert. Also, this concept can apply to any of the popular front-end
frameworks like Vue.js, Svelte, Ember.js, and more.
This screen consists of a name, email, password, and Create Profile button.
The form input is in a form tag that is aligned center with a header above it.
All of this is currently done with inline CSS (see Figure 12.6).
JavaScript to TypeScript
Python to Cython
Ruby to Crystal
PHP to Hack
Clojure to ClojureScript
Erlang to Alpaca
Lua to Typed Lua
R to Slang
Perl to Raku
Groovy to Java
In this section, you will see some of these translations and how you can
easily enhance your nontyped language with Copilot.
JavaScript to Typescript
Let's look at how Copilot can help convert JavaScript to TypeScript. In this
example, there is a calculateTotal function that has an input of items and
discount properties and should return the calculated total.
function calculateTotal(items, discount) {
let total = 0;
for (let i = 0; i < items.length; i++) {
total += items[i].price;
}
total -= total * (discount / 100);
return total;
}
There are several potential issues that could arise when not using
TypeScript in this function. First, type safety when using the input
parameters items and discount is not present. So, if a developer accidentally
passes a single item into the method instead of an array, there would be a
runtime error. Also, for the discount parameter, if a developer later passes a
non-numeric value, there would be a runtime error. While these things can
be checked with unit tests, adding another layer of safety on your code can
help identify issues quickly and keep the maintainability of your code
higher.
To convert this function to typescript, let's use inline chat. You can also use
chat within the window, but for this purpose I will be demonstrating an
inline refactor.
Start by selecting the function. After making the selection, activate inline
chat. Send a request to Copilot to convert the file to TypeScript with the fix
command (see Figure 12.11):
/fix convert the file to TypeScript
After making this conversion, you would need to update your project to use
TypeScript. As stated earlier, nontyped languages offer an ease of use
because of their simplicity and an ease of execution. With the addition of
types, it is now a requirement to do a few additional steps to get your code
to compile and execute.
For assistance in these remaining steps, you can turn to Copilot. Start a new
window chat and ask Copilot the following:
How can I update my JavaScript project to use TypeScript?
After sending this request, you should get a detailed step-by-step guide to
implementing TypeScript for your project (see Figure 12.12).
Figure 12.11: Calculate total function converted to TypeScript
Figure 12.12: Copilot response on how to update a JavaScript project to
Typescript
From this starting point, select the application code and use the chat
window to ask Copilot to convert the application to use Polars (see Figure
12.13).
Here is the request to Copilot:
Convert application to use Polars #editor
With this conversion now completed, you can proceed to installing the
appropriate library as Copilot indicated in the chat response and enjoy the
speed improvements when dealing with your large dataset.
Express.js to Koa.js
Express.js has long been the go-to framework for developing web
applications in Node.js. It is simple, is unopinionated, and has a large
community with a rich ecosystem of middleware. However, as JavaScript
and Node.js have evolved, new frameworks have emerged that take
advantage of newer features to offer a more modern and streamlined
development experience.
One such framework is Koa.js. Developed by the same team behind
Express, Koa.js leverages async functions to eliminate callbacks and
significantly improve error handling. Koa is also modular, enabling for a
leaner more dynamic offering.
In this section, you will discover how in the process of modernizing your
framework-dependent applications, Copilot can assist in updating your code
to ensure the functionality is preserved while giving you the benefits of
modern advancements made by new frameworks.
If you would like to follow along with this coding example, you can
download a copy of the starter express-to-koa.js file in the Chapter 12
folder.
https://www.wiley.com/go/programminggithubcopilot
app.listen(port, () => {
console.log(`Example app listening at
http://localhost:${port}`);
});
Using Copilot Chat, let's see how you can translate this application to
Koa.js. Start by opening a window chat and request Copilot to convert the
application to use Koa.js (see Figure 12.14).
Here is the request to Copilot:
Convert application to use Koa.js #editor
Figure 12.14: Copilot response on how to convert application to use Koa.js
From here, you can take this application code using Koa.js and apply it to
your editor. There are several differences here from the use of a Koa router
library to async functions. With Copilot, you can remove the burden of
making each individual edit to your application code when migrating
frameworks as you have seen here.
Here is the completed Node.js application using Koa.js:
const Koa = require('koa');
const Router = require('@koa/router');
app
.use(router.routes())
.use(router.allowedMethods());
app.listen(port, () => {
console.log(`Example app listening at
http://localhost:${port}`);
});
Objective-C to Swift
For years, the preferred language to create macOS and iOS applications was
Objective-C. While this language allowed for a great ecosystem of
applications to be developed and tooling to be created, modernization
efforts for the Apple ecosystem resulted in the creation of the Swift
programming language. As a result, the developer community began to
have more and more reasons to migrate to Swift because of its continued
feature enhancements and first-class support.
Let's look at an example of an Objective-C class that Copilot can assist in
translating to Swift.
If you would like to follow along with this coding example, you can
download a copy of the starter Person.m file in the Chapter 12 folder.
https://www.wiley.com/go/programminggithubcopilot
Here is the starting class file written in Objective-C:
#import <Foundation/Foundation.h>
- (instancetype)initWithFirstName:(NSString *)firstName
lastName:(NSString *)lastName;
- (void)printFullName;
@end
@implementation Person
- (instancetype)initWithFirstName:(NSString *)firstName
lastName:(NSString *)lastName {
self = [super init];
if (self) {
_firstName = firstName;
_lastName = lastName;
}
return self;
}
- (void)printFullName {
NSLog(@"%@ %@", self.firstName, self.lastName);
}
@end
In this example, you will see how Copilot can translate code using inline
comments to drive code completion for the translation task. This may not be
the ideal method for translating a class file, but I wanted to showcase
another option if you are in an IDE without chat support but would still like
to translate a class file.
In an editor window, add the following two blank lines after the Objective-
C Person object and input a comment like the following:
// Convert the above code to Swift
After inputting that comment, you can proceed to the next line; in my case
Copilot suggests a name for the Person.swift file we want to create. After
adding a new line after that, you should get an import for the Foundation
library. Add that line, and add two more blank lines after the import. This
should trigger Copilot to suggest a completion for the Person class (see
Figure 12.15).
Migrating Databases
Migrating databases can be a huge effort. Although there are great tools to
assist in large portions of migrations, there are still some manual tasks that
Copilot can assist with. Whether you are moving from MySQL,
PostgreSQL, SQL Server, or Oracle Database, you can lean on your pair-
programming assistant GitHub Copilot to help you along the way.
In this section, you will learn how Copilot can assist with general database
conversion tasks.
SQL Server to PostgreSQL
When migrating to a new database, there are many conversion options. In
the case of migrating to PostgreSQL, the pgloader CLI tool assists in many
of the migration tasks required like table schemas, data imports, and basic
indexing. In this basic example, you will see how Copilot can translate the
schema, insert statements, and stored procedures from SQL Server to
PostgreSQL.
If you would like to follow along with this coding example, you can
download a copy of the starter sql-server.sql file in the Chapter 12
folder.
https://www.wiley.com/go/programminggithubcopilot
EXEC GetFullName 1;
Using Copilot Chat, you can make quick work of a small, targeted
conversion. With the SQL Server database file open, request that Copilot
convert to PostgreSQL.
Convert from SQL Server to PostgreSQL
After sending this request to Copilot, you should get a resulting PostgreSQL
file that you can use as a baseline to your migration efforts (see Figure
12.16).
As mentioned, there are great tools that can support large migration efforts,
but sometimes the ease of use with Copilot for targeted migrations can be a
much better option. Also, a tool like pgloader does not migrate SQL Server
stored procedures to PostgreSQL functions. This is a great area to get
Copilot to assist and quickly migrate those files to your new database.
Here is the chat request to Copilot to convert an Azure DevOps pipeline file
to GitHub Actions:
Convert this Azure DevOps pipeline file to GitHub Actions:
trigger:
- master
pool:
vmImage: 'windows-latest'
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
steps:
- task: NuGetToolInstaller@1
- task: NuGetCommand@2
inputs:
restoreSolution: '$(solution)'
- task: VSBuild@1
inputs:
solution: '$(solution)'
msbuildArgs: '/p:DeployOnBuild=true
/p:WebPublishMethod=Package /p:PackageAsSingleFile=true
/p:SkipInvalidConfigurations=true
/p:DesktopBuildPackageLocation="$(build.artifactStagingDirect
ory)\WebApp.zip" /p:DeployIisAppPath="Default Web Site"'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: VSTest@2
inputs:
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: PublishBuildArtifacts@1
- task: AzureRmWebAppDeployment@4
inputs:
ConnectionType: 'AzureRM'
azureSubscription: 'Your Azure Subscription'
appType: 'webApp'
WebAppName: 'Your Web App Name'
packageForLinux:
'$(build.artifactStagingDirectory)/**/*.zip'
After sending this request to Copilot, you should get a result that details the
resulting GitHub Actions workflow file and indicates any manual updates
that might be needed due to different build dependencies (see Figure 12.17).
As you can see from this example, both platforms allow .yaml file formats,
but the structure and keywords are different. Azure DevOps Pipelines use a
more linear structure, while GitHub Actions use a more nested structure.
GitHub Actions also make extensive use of “actions,” which are reusable
pieces of code.
Figure 12.17: Copilot response for Azure DevOps pipeline file to GitHub
Actions
Modernizing Legacy Systems
Legacy systems can be a liability for businesses due to increased
vulnerability to security threats, maintenance challenges, and the inability to
adapt to evolving business needs. Transitioning from these outdated
systems to newer technologies can significantly decrease risk exposure,
enhance business agility, and maintain competitiveness. This modernization
enables organizations to innovate more effectively and meet changing
customer demands.
In this section, you will learn how Copilot can assist in modernizing legacy
systems using languages such as COBAL or Fortran. Using Copilot to
modernize legacy applications can significantly reduce the effort it would
take to do a legacy system modernization with traditional tooling.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-ID PIC 9(5).
01 WS-NAME PIC X(20).
01 WS-BALANCE PIC 9(5)V99.
01 WS-EOF PIC X VALUE 'N'.
EXEC SQL INCLUDE SQLCA END-EXEC.
PROCEDURE DIVISION.
Begin.
EXEC SQL
CONNECT TO DB2
END-EXEC.
EXEC SQL
DECLARE C1 CURSOR FOR
SELECT ID, NAME, BALANCE
FROM CUSTOMERS
END-EXEC.
EXEC SQL
OPEN C1
END-EXEC.
EXEC SQL
CLOSE C1
END-EXEC.
EXEC SQL
DISCONNECT DB2
END-EXEC.
STOP RUN.
Let's see how Copilot can convert this legacy program to a C# equivalent.
Start by opening VS Code with the CustomerBalanceDisplay.cob file
opened. After having that file open, start a new chat with Copilot and send a
request like the following:
Convert this COBAL program to C#.
#file:CustomerBalanceDisplay.cob
After sending this request, you should get a result from Copilot that
matches something like the following program file:
using System;
using System.Data;
using IBM.Data.DB2;
namespace DB2Example
{
class Program
{
static void Main(string[] args)
{
string connectionString =
"your_connection_string_here"; // replace with your DB2
connection string
Console.WriteLine($"{id} {name}
{balance}");
}
}
}
connection.Close();
}
}
}
}
In this program, you can see that Copilot did a great job preserving the
functionality of the legacy COBAL application while modernizing the
codebase to C#. Because no additional instructions were given, Copilot
determined we most likely wanted to preserve the DB2 database
connection. In some cases, you might want to migrate to a new database
technology as well. In this next example, you will see how Copilot can also
implement a new database technology and migrate the code functionality all
at the same time.
Start this by sending a new request to Copilot like the following:
Convert this COBAL program to C#. Use SQL Server and Entity
Framework. #file:CustomerBalanceDisplay.cob
With this request, you are specifying the original request to convert the
program to C#. In addition, you can layer on additional instructions to use
SQL Server and the Entity Framework. It is important not to try to get
Copilot to do conflicting tasks or overload your requests. In this example, it
works out well to convert the database connection code and program code
simultaneously. Using this request, you should get a result that describes the
Entity Framework class and context files and an updated
CustomerBalanceDisplay program file (see Figure 12.18).
Figure 12.18: Copilot response for converting COBAL program and DB2
to SQL Server
With the help of Copilot, this program becomes more maintainable and
easier to read. Using the Entity Framework has reduced the program code
significantly. Using this framework also gives type safety when working
with database objects enhancing the stability of the program.
Conclusion
In this chapter, you explored the transformative capabilities of Copilot in
facilitating seamless transitions across a multitude of technical landscapes.
When converting languages, frameworks, libraries, databases, or CI/CD
pipelines, Copilot not only accelerates the adoption of new technologies but
also enhances the development workflow with unparalleled speed and
accuracy. Through various examples, you saw how Copilot can be
leveraged to do the following:
OceanofPDF.com
Part IV
Key Insights and Advanced Use
Cases for GitHub Copilot
In This Part
Chapter 13: Considering Responsible AI with GitHub Copilot
Chapter 14: Augmenting the Software Development Lifecycle with
GitHub Copilot
Chapter 15: Exploring Copilot Business and Enterprise
OceanofPDF.com
CHAPTER 13
Considering Responsible AI with GitHub
Copilot
In this chapter, you will learn about responsible AI, what AI regulations are
being established by governments, how GitHub Copilot implements
responsible AI principles, and what you should consider when adopting AI-
powered tools like GitHub Copilot.
Introducing Responsible AI
Examining How GitHub Copilot Implements Responsible AI
Programming with AI Responsibly
Introducing Responsible AI
Responsible artificial intelligence (responsible AI) refers to the practice of
creating, evaluating, and implementing AI technologies in a manner that is
safe, reliable, and aligned with ethical principles.
In recent years, a plethora of AI tools have emerged. With this surge in AI-
powered tools and mass adoption of AI tooling at a global scale, responsible
AI has never been more important.
The concept of AI has been around since the 1950s, but only recently has
the convergence of hardware, software, and data combined to produce the
rapid advancements seen today with tools like GitHub Copilot. This
convergence of technological advancements to produce such powerful tools
has amplified the need for responsible AI standards.
The following sections, which examine how GitHub Copilot implements
responsible AI, will detail these responsible AI standards—which consist of
fairness, reliability and safety, privacy and security, inclusiveness,
transparency, and accountability.
Responsible AI Regulation
The European Union AI Act is setting the stage globally for the adoption of
responsible AI practices [1]. Once in force, the act will impact companies
building, selling, and marketing AI in the EU. Due to the Brussels effect, a
term that is used to describe an incentive for companies to adhere to
regulatory standards in a particular market, I predict that other countries
will essentially copy and paste the act for their own use. The act focuses on
establishing an AI risk threat level that declares banned applications and
sets requirements for high-risk systems, as well as establishing transparency
requirements and implementing measures to support innovation while
protecting citizens of the EU. Fines for violations of the EU AI Act can be
as high as 7% of a company's global revenue, making this not only the first
but the most serious regulation on AI.
In the United States, the White House has established a blueprint for an AI
Bill of Rights, a nonbinding set of responsible AI considerations meant to
generate conversation around establishing protections for U.S. citizens and
residents in the same way the Constitutional Bill of Rights establishes
protections [2]. President Biden also signed an AI Executive Order, which
establishes requirements for the safe implementation and monitoring of AI
systems in the U.S. federal government. This Executive Order was the first
government-wide establishment of responsible AI requirements by a major
global power.
Together, these major pieces of regulation, while incomplete and
noncomprehensive, highlight that global leaders are seeing the importance
of clear guidance and regulations that ensure their citizens are protected and
benefit positively from the advancements in AI.
Fairness
The idea behind the fairness principle is that “AI systems should treat all
people fairly” [6]. One example of fairness considered by the GitHub
Copilot team is ensuring that the tool operates in languages other than
English. In developing the tool, the GitHub team ensured that natural
language support was established for a large set of languages. The default
language can be adjusted in the extension settings for Copilot (see Figure
13.1).
Figure 13.1: Copilot extension settings for language
In Figure 13.2, you can see how, when setting a default response language
for Copilot, you will receive responses specific to the locale.
Figure 13.2: Copilot responding in multiple languages
In addition to language support, GitHub Copilot prioritizes support for
accessibility. By intentionally supporting keyboard-only and screen reader
users, GitHub Copilot empowers people with disabilities to contribute
effectively to their projects.
Data Protection
GitHub Copilot is compliant with the General Data Protection Regulation
(GDPR). GDPR is Europe's data privacy and security law. This regulation
works to protect consumer data and enforce fines on companies that do not
have their data privacy and security standards in place.
For business and enterprise users, data used for GitHub Copilot code
suggestions and chat responses are not stored in persisted storage. Instead,
this data is kept in memory only for the duration of the API request. Once
that is completed, the request data is cleared. Also, to further ensure your
session data is protected, GitHub does not log user request data.
For individual plan users, prompts and suggestions are retained by default
unless you disable code snippet collection in your settings.
Inclusiveness
The principle of inclusiveness establishes the idea that “AI systems should
empower everyone and engage people” [6]. One way that GitHub fosters
inclusiveness is by providing several options to obtain a license to GitHub
Copilot, which works to make the product available for everyone. For
students and maintainers of popular open-source projects, Copilot can be
completely free. For individuals, the current price is $10 per month or $100
per year. And there are also multiple options for organizations to purchase
the plan that fits their needs.
Another example of inclusiveness is that GitHub Copilot does not operate
on its own in the background while the programmer works. The tool was
never intended to replace programmers or make them obsolete. It partners
with the programmer, which keeps them included in the work being done.
This is great for the labor market, but it also lends to the principle of
accountability, which I'll dive into in a moment.
Transparency
The idea of the principle of transparency is that “AI systems should be
understandable.” To illustrate this principle, you can ask GitHub Copilot
Chat to explain the code that it has written for you (see Figure 13.5). This is
an example of transparency in that it allows the user to understand what's
being offered in terms of a code suggestion.
Another way you can see this principle show up in practice is in the
documentation and explanation of how the product works. GitHub did not
create GitHub Copilot to operate in a black box. It was created in a way that
lends to transparency and allows users to understand how the product is
working, how it is trained, the data it leverages, and the code it produces.
Accountability
The accountability principle posits that “People should be accountable for
AI systems.” While every principle is important, this is perhaps the most
critical. Because of the pace of AI development and the very real impact AI
can have—positively and negatively—on human lives, it could be easy to
get into a loop of blaming AI for being unsafe, providing unfair responses,
or sharing biased views and perspectives.
Figure 13.5: Copilot explain command results
GitHub imbues this principle at multiple points in the process, from
development to use and output.
In the development process, GitHub product teams partner with the
Microsoft Office to Responsible AI to move the product through the
established responsible AI processes. This keeps humans from multiple
organizations and perspectives engaged in the process. Should there be a
responsible AI challenge with the product, there is accountability at the
GitHub and Microsoft levels.
For product use and output, the user is kept in the loop throughout the
duration of the process.
An important concept to highlight here is that you are responsible for
accepting and reviewing the code and information provided by GitHub
Copilot. GitHub Copilot will never “accept” code of its own volition. The
concept of “human-in-the-loop” is a core implementation detail in
numerous Copilot features. It provides a level of accountability at the user
level and drives accountability at varying levels of AI use by requiring
active human engagement. As shown in Figure 13.6, when accepting inline
code changes, you need to accept or discard the result. This human-in-the-
loop activity is vital to ensure safety and adherence to the principles of your
software development practice.
Further Research
For full details on these responsible AI principles, please visit the Microsoft
Responsible AI website.
https://www.microsoft.com/ai/responsible-ai
For more details on how GitHub Copilot works and information about
responsible AI related to the product, visit the GitHub Copilot Trust Center.
https://resources.github.com/copilot-trust-center
Conclusion
This chapter provided a high-level exploration of responsible AI, detailing
the regulations set forth by governments, the application of responsible AI
principles in GitHub Copilot, and considerations for adopting AI-powered
tools like GitHub Copilot. You should now have a good starting point to
understand and engage with AI technologies ethically and effectively.
References
[1] EU Artificial Intelligence Act, 2024. “The EU Artificial Intelligence
Act,” https://artificialintelligenceact.eu
[2] The White House, 2023. “Blueprint for an AI Bill of Rights,”
https://www.whitehouse.gov/ostp/ai-bill-of-rights
[5] GitHub, 2023. “Nine years of the GitHub Security Bug Bounty
program,” https://github.blog/2023-08-14-nine-years-of-the-
github-security-bug-bounty-program
[6] Microsoft AI, 2024. “Empowering responsible AI practices,”
https://www.microsoft.com/ai/responsible-ai
OceanofPDF.com
CHAPTER 14
Augmenting the Software Development Life
Cycle with GitHub Copilot
In this chapter, we will explore the details of the software development life
cycle (SDLC) and how GitHub Copilot can help you each step of the way.
We will assess the current adoption statistics of AI tooling in the SDLC and
future predictions. Additionally, we will define the levels of AI integration
in the SDLC. Finally, this chapter will address potential concerns with ever-
increasing AI adoption in software development workflows and what
impacts adoption might have on job stability and work dynamics.
Design
During the Design phase, activities such as creating architectural diagrams,
designing user interfaces, and planning system interactions are crucial.
GitHub Copilot assists here by generating boilerplate code for design
patterns, offering coding alternatives, and suggesting improvements or best
practices based on current design trends.
Coding
The Coding phase is where GitHub Copilot truly excels, helping you write
code, review code, and integrate modules. It provides real-time code
suggestions, completes lines or blocks of code, and helps you write more
efficient, error-free code quickly.
Testing
In the Testing phase, writing test cases, conducting various types of tests,
including unit, integration, and system tests, debugging, and validating are
key activities. GitHub Copilot aids by suggesting and generating test cases,
helping identify potential edge cases, and providing code for automated
testing frameworks to enhance the robustness and coverage of tests.
Deployment
The Deployment phase involves configuring servers, deploying code to
production, and monitoring the deployment process. GitHub Copilot offers
guidance on deployment scripts, suggests best practices for CI/CD
pipelines, and helps troubleshoot deployment issues by providing relevant
code snippets and configurations.
Maintenance
During the Maintenance phase, activities such as bug fixing, upgrading
systems, and optimizing performance are prevalent. GitHub Copilot helps
by quickly identifying bugs with suggested potential fixes, offering
performance optimization techniques, and assisting in updating
documentation or comments within the code to maintain its relevance and
readability over time.
Level 0: Nonexistent
At level 0, AI integration in the SDLC is virtually absent. This stage is
characterized by a complete lack of AI tools and processes within the
development framework. Organizations at this level rely solely on
traditional software development practices, without the augmentation of AI
capabilities.
At this level, there is high potential for misuse of AI tools by engineering
teams due to lack of clarity from the organization on proper use and best
practices. This lack of clarity and misuse can lead to organizational risk.
As discussed in the previous section, developers surveyed directly are
adopting AI tooling at a high rate while organizations are not yet identifying
their adoption rates at as high a rate [2, 3]. This indicates that there is most
likely a large number of organizations with no guidance on AI integration in
the SDLC while their engineering teams are seeking out AI tooling on their
own.
Capabilities Demonstrated
These are the capabilities:
Level 1: Initial
At level 1, organizations begin their journey toward AI integration within
the SDLC by exploring and tentatively adopting AI tools and
methodologies. This level is characterized by initial efforts to understand
and implement AI capabilities in a limited, experimental fashion, often
focused on specific projects or parts of the SDLC.
Capabilities Demonstrated
These are the capabilities:
Level 2: Managed
At level 2, organizations have moved beyond the initial exploration of AI in
the SDLC to a phase of managed integration, where AI tools and practices
are implemented with specific management oversight and integration into
selected development processes. This level is marked by a deliberate
approach to AI adoption, driven by targeted objectives and monitored
through structured management practices.
Capabilities Demonstrated
These are the capabilities:
Level 3: Defined
At level 3, organizations achieve a phase of defined integration in the
adoption of AI within the SDLC. This level signifies a mature approach
where AI tools and methodologies are not just managed but are fully
integrated into standardized processes across the organization. AI practices
are documented, and their integration is characterized by consistency,
repeatability, and alignment with the organization's strategic goals.
Capabilities Demonstrated
These are the capabilities:
Standardized AI Processes The organization has developed and
implemented standardized processes for integrating AI tools across
various stages of the SDLC. These processes are documented and
shared across teams, ensuring consistency in how AI is leveraged for
software development.
Organization-wide AI Integration AI integration extends beyond
specific projects or teams and is now a standard part of the
development process across the organization. This widespread
adoption ensures that all projects benefit from AI's efficiency and
innovation potential.
Comprehensive AI Strategy There exists a comprehensive strategy
for AI adoption that aligns with the organization's overall business and
technology objectives. This strategy guides the selection,
implementation, and management of AI tools and processes.
Advanced AI Use Cases The organization is implementing advanced
AI use cases, such as deep learning for complex problem-solving, AI-
driven user experience personalization, and predictive analytics for
strategic planning and decision-making.
Capabilities Demonstrated
These are the capabilities:
Level 5: Optimizing
At level 5, organizations have achieved the pinnacle of AI integration
within the SDLC, where AI-driven processes are not only quantitatively
managed but are also continuously optimized for peak performance and
innovation. This stage is characterized by the organization's proactive and
strategic use of AI to drive ongoing improvements and achieve competitive
advantages in software development and product innovation.
Capabilities Demonstrated
These are the capabilities:
Summary
This section described the various levels of AI integration within the SDLC,
modeled after CMMI. It outlines a progression from level 0 to 5.
This structured approach of evaluation should help you and your
organization assess your current AI maturity level and strategize
advancements to enhance development effectiveness and competitive
positioning.
Requirements Gathering
The product owner, Sofia, uses GitHub Copilot to efficiently draft detailed
functional requirements and user stories for the FreshFridge's inventory
tracking, recipe suggestion, and grocery replenishment features, ensuring a
comprehensive approach to sustainable living.
In this instance, you will see Copilot used within the VS Code IDE. With
GitHub Copilot Enterprise, the product owner could use GitHub Copilot
Chat within GitHub.com.
Starting with the first requirement that the team has outlined, Sofia opens
VS Code and starts a window chat with Copilot. Here she can request that
Copilot give a list of potential user stories supporting the inventory tracking
requirement (see Figure 14.4).
Figure 14.4: Copilot responding with user story titles for a feature
Here's the request to Copilot:
Create user stories that would be required to complete this
feature:
From here, Sofia can upload these stories and acceptance criteria to the
product backlog for her team to review in their product backlog refinement
meeting. Or, if there are changes that she would like to make, she can
simply ask Copilot to make the adjustment to the acceptance criteria,
allowing her and her team to rapidly iterate on the details of the user story.
As you can see from the request made in the example, the prompt simply
indicated “ac” instead of fully spelling out “acceptance criteria.” Because
Copilot is trained on such a large dataset, it can predict the intent of the
prompt and still produce a response that meets our needs.
In the result options, OpenCV stands out as a good option for the team to
try. They determine that they feel confident in their ability to complete the
user story based on their research.
Figure 14.6: Copilot responding with details on AI vision system libraries
This is just one example of ideation and a question that you can leverage
with Copilot. There are endless options to leverage Copilot in the context of
user story discovery and ideation.
With this new information, Tom can make an edit to the scenario by
leveraging the Copilot inline chat (see Figure 14.7).
Here's the request to Copilot:
Update this scenario to indicate the use of the OpenCV
library.
The results from Copilot are great. They provide a very logical starting
point, which the team can build from. See the complete list generated by
Copilot here:
Now, Alexi can continue to install the required library. With this completed,
they can continue to the next task for this sprint item:
Develop a function/method that uses the trained AI model and OpenCV
to identify and categorize new food items.
Figure 14.9: Copilot inline chat assisting in installing and importing a
library
At this point, Alexi can use a variety of Copilot features to complete the
work. A top-level comment, window chat, or inline chat would work great
here. Let's see how the team can use inline chat to create a great starting
point for a function that matches the requirements from the task selected
(see Figure 14.10).
Here's the request to Copilot:
Develop a function/method that uses the trained AI model and
OpenCV to identify and categorize new food items.
As you can see from this example, the team generated an identify_food
function from the task text. This completion was assisted by the file, file
type, import statement, and request text.
From here, the developer can continue to interact with Copilot to implement
the missing imports and methods that will finalize the implementation.
class TestImageProcessing(unittest.TestCase):
def test_identify_food(self):
# Test case 1: Image with a single food item
image_path =
'path_to_image_with_single_food_item.jpg'
expected_categories = ['apple']
self.assertEqual(identify_food(image_path),
expected_categories)
if __name__ == '__main__':
unittest.main()
As you can see, this test is a great example of the power and speed that you
have at your fingertips with GitHub Copilot. From here, the development
team can iterate on the design of the underlying code until it has
successfully passed the unit tests.
on:
push:
branches: [ dev ]
pull_request:
branches: [ dev ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
As you can see, Copilot’s chat response gives a step-by-step instruction set
with a complete workflow file to kick-start the integration of the new
feature work from the team. Also, Copilot uses the Python version from the
request in the generated result.
These examples showcase how GitHub Copilot can be utilized at every
phase of the SDLC. This was just a glimpse at the numerous ways a
development team can leverage Copilot while working on sprints.
Conclusion
In this chapter, you learned about the SDLC and how AI can be integrated
into a Scrum team's workflow. Copilot can be helpful in every phase of the
SDLC.
We explored the current adoption statistics and future predictions detailing
what today’s development landscape looks like and where we are headed.
These statistics and predictions emphasize the upward trajectory of GitHub
Copilot in the software industry.
Additionally, you learned about the levels of AI integration in the SDLC.
From level 0 to level 5, you should be empowered to address where you are
in your organization's adoption of AI in the SDLC and be able to navigate a
way forward.
Finally, this chapter addressed potential concerns with ever-increasing AI
adoption in software development workflows and the impact that might
have on job stability and work dynamics.
References
[1] GitHub, 2024. “Understanding the SDLC: Software Development
Lifecycle Explained,” https://resources.github.com/software-
development/what-is-sdlc
[2] Gartner, 2023. “Gartner Hype Cycle Shows AI Practices and Platform
Engineering Will Reach Mainstream Adoption in Software Engineering
in Two to Five Years,”
https://www.gartner.com/en/newsroom/press-releases/2023-11-
28-gartner-hype-cycle-shows-ai-practices-and-platform-
engineering-will-reach-mainstream-adoption-in-software-
engineering-in-two-to-five-years
OceanofPDF.com
CHAPTER 15
Exploring Copilot Business and Enterprise
This chapter will cover the features within Copilot Business and Copilot
Enterprise. Building on the robust offerings of the Copilot experience,
Copilot Business enables organizations to leverage Copilot while giving
leaders the control they need and ensuring the security of their intellectual
property.
In addition to the controls and security that Copilot Business offers, you
will learn the advanced capabilities of Copilot Enterprise. These robust
features enable your entire organization to get more done. You will learn
about chat within GitHub.com, indexing repositories, knowledge bases, pull
request features, and more.
Repository-specific questions
General software questions
File- or symbol-specific inquiries
Questions about specific lines within a file
Knowledge base–related questions
Pull request diff inquiries
Throughout the remainder of this chapter, you will see examples of all these
features in action.
NOTE
Figure 15.9 shows the main page of the client application with the
navigation, header, filters, products, login, and cart (see Figure 15.9).
After submitting this question to Copilot, you should get a response like the
one in Figure 15.11.
Figure 15.11: Copilot Chat response for how to run the API locally
This result is infused with the details from the indexed repository. There are
specifics on the type of database connections required, project-specific
command-line statements, and alternative dev containers using Docker.
Where Question
Next, let's see how Copilot can give bespoke results for a specific part of
the repository. When you need to know where code is for a specific feature
in a larger repository, a simple symbolic or keyword search can leave you
with limited understanding. Let's see how Copilot can supercharge your
search experience and give you the insights you need to be productive.
With a Copilot Chat window open and the repository selected as context for
the conversation, send a request to Copilot to understand where
authentication is handled (see Figure 15.12).
Here's the Copilot request:
Where is authentication handled in our API?
Figure 15.12: Copilot Chat response for where authentication is handled in
our API
Here Copilot surfaced important files related to our question. Unlike a
traditional search, Copilot was able to provide additional context about
what the files do and specific attributes that pertain to the authentication
question.
As you can see, Copilot excels with the index that was created, enabling
you to get insights about your codebase with the power of Copilot to
compile logical responses and assets to help you do more.
Front-end development
UI/UX design
Front-end frameworks (React.js, Angular)
Web technologies (HTML, CSS, JavaScript)
Performance optimization
Accessibility standards
Cross-browser compatibility
Backend development
Programming languages (Python, Java, Node.js)
Server and API development
Security practices
Scalability and performance
Integration with third-party services
Database administration
Database management systems (MySQL, MongoDB)
Data modeling and normalization
Performance tuning
Backup and recovery strategies
Database security
Quality assurance
Testing techniques (unit, integration, system testing)
Test automation
Bug tracking and management
Performance and load testing
CI/CD integration
Information assurance
Risk management
Compliance with security standards (ISO/IEC 27001, GDPR)
Encryption and data protection
Incident response
Security policies and procedures
Operations
Monitoring and logging
System administration
Incident management
Deployment and scaling
Disaster recovery and business continuity
Requirements management
Requirements elicitation and documentation
Change management
Traceability of requirements
Tools and software for managing requirements
These examples are intended to get you started. Make sure you consider
your organizational needs and team dynamics when implementing your
knowledge bases.
Let's look at an example and focus on front-end development. Start by
adding a name and optional description. Then add relevant repositories to
the content area like dotnet/razor, twbs/bootstrap, and dotnet-
architecture/eShopOnWeb (see Figure 15.15).
Figure 15.15: Organization Copilot knowledge front-end development
After you have selected the repositories, you want for your knowledge base,
click Create at the bottom of the page.
You can now use the knowledge base from Copilot Chat in GitHub.com.
Open a new chat window and click the book icon at the bottom left of the
chat window (see Figure 15.16).
Figure 15.16: Copilot Chat knowledge base menu
From here, click Frontend Development. As you can see, I created a second
knowledge base for backend development to showcase the menu structure.
Within the Copilot conversation, you will now see a “chatting with frontend
development” alert. This will direct Copilot to reference the repository
Markdown files when answering questions in this conversation.
Since the front-end development knowledge base is referencing bootstrap,
ask Copilot what the latest version of that library is (see Figure 15.17).
What is the latest version of bootstrap?
You can see Copilot referenced six files to determine the best answer given
the question. Copilot responded with the correct, most current version of
bootstrap, which is 5.3.3 at the time of writing.
Let's see what other information we can gather regarding version changes
for bootstrap. Ask Copilot what you have to change when migrating from
version 4 to version 5 (see Figure 15.18).
Figure 15.17: Copilot Chat bootstrap version question
Figure 15.18: Copilot Chat bootstrap version migration question result
What updates are required to my classes when moving from
bootstrap 4 to bootstrap 5?
Here you can see Copilot gathered great information on a migration from
version 4 to version 5 of bootstrap with references to the documentation
from the official repository.
Also, you might notice in Figure 15.18 that I have navigated to the
bootstrap repository and continued my conversation with Copilot. This
ability to follow your reference files linked in the chat responses while
maintaining your conversation with Copilot offers a great fluid experience.
You can always minimize the Copilot Chat window if you would like quick
access while navigating around different pages.
Summary
As you can see from this short example, this is applied across your entire
organization to assist in productive conversations with up-to-date
authoritative data sources, which is a game-changer. These conversations
can quickly uncover company-specific information about internal libraries,
tools, or best practices.
With knowledge bases, you and your team can quickly jump into
conversations that give you the targeted and best information possible to
keep you moving.
With the specific question about files and a targeted feature within the
repository, Copilot has done a great job of identifying the files used in this
process. With this result, open the Basket.cs class file.
Here you can see that Copilot understands the context of your question and
can give you an insightful response with limited work on your behalf.
In addition to a single file attachment, you can click the paperclip icon to
select as many files as you need to support your conversation with Copilot
(see Figure 15.26).
Figure 15.25: Copilot Chat window with attachment response
Figure 15.26: Copilot Chat window attachment search for files and
symbols
Searching and adding files or symbols to your conversation is a simple task
with the intuitive search feature. With the BasketService.cs added as
additional conversation context, you can ask questions targeted at the
interaction of these files.
Figure 15.28: Copilot Chat response for how to add a remove item feature
to the basket page
Copilot has responded with reference to the repository. At the top of the
response, you can see that Copilot uses a search term “remove item from
basket” against the indexed repository information to gather all of the
necessary resources to give a holistic response to our request.
In summary, here are the steps Copilot has outlined for our change:
To make these changes in VS Code, you will need to follow the README.md
instructions from the eShopOnWeb repository. Specifically, review the
guide under the heading “Running the sample locally.” In addition to the
steps outlined, for me to get the application to run, I needed to set the
default value of useOnlyInMemoryDatabase = true within the
Dependencies.ConfigureServices() method.
After following the steps for running locally and installing all the required
dependencies, you can run the following dotnet CLI commands.
From the project root, open a terminal and execute the following to run the
API:
cd src/PublicApi
dotnet watch
Open a second terminal at the project root and execute the following to run
the client application:
cd src/Web
dotnet watch
With the API and web projects running in watch mode, you can now make
the edits outlined in the previous section.
Update the Basket Domain Model
In my case, Copilot responded with a RemoveItem() function within the
initial chat response for adding the remove functionality to the basket page.
You can work with Copilot in several ways to create this method. Whether
you prompt Copilot for a code completion via an inline comment, start a
new chat within VS Code, or use Copilot Chat in GitHub.com, you should
end up with a function like this added to your Basket.cs file:
public void RemoveItem(int catalogItemId)
{
_items.RemoveAll(i => i.CatalogItemId == catalogItemId);
}
After adding this code to your Basket.cs file, you can then add a test using
Copilot Chat to ensure the functionality. Do this by selecting the
RemoveItem() function in the editor. Open a new chat with Copilot in the
side menu. From this chat, send a request to Copilot like this (see Figure
15.29):
@workspace /tests #selection #file:BasketAddItem.cs XUnit
Figure 15.29: Copilot Chat response for creating tests for the new method
The test result from Copilot needed additional guidance to generate an
XUnit test. Additionally, the using statements, namespace, and class name
all needed to be adjusted. The unit tests themselves were in good standing,
but it is important to always review the output critically from Copilot and
refine as needed.
Figure 15.30: Copilot function creation for remove item from basket
function
Here you can see Copilot creating the function with the necessary
interactions with the basket specification class, basket repository, and
basket class with the assistance of the interface file context. Here is the
complete method for reference:
public async Task<Result<Basket>>
RemoveItemFromBasket(int basketId, string username, int
catalogItemId)
{
var basketSpec = new
BasketWithItemsSpecification(basketId);
var basket = await
_basketRepository.FirstOrDefaultAsync(basketSpec);
if (basket == null) return Result<Basket>.NotFound();
basket.RemoveItem(catalogItemId);
await _basketRepository.UpdateAsync(basket);
return basket;
}
With this function in place, which can use the new basket service
RemoveItemFromBasket function, you will also need to adjust the
Index.cshtml page. For my edit, I added a btn btn-link button to the
right of the other basket item table row fields. Additionally, I adjusted some
alignment of the grid rows to be aligned with the new remove button. Here
is a snippet of the button that was added to the cshtml file:
<section class="esh-basket-item esh-basket-item--middle col-
xs-1">
<button class="btn btn-link" name="removebutton" asp-
route-id="@item.CatalogItemId" type="submit" asp-page-
handler="Remove">
Remove
</button>
</section>
With all these changes in place, the remove button is now functioning. The
output you should have after making the edits for layout and adding the
button as described earlier should look like Figure 15.31.
Figure 15.31: Basket page with new remove button for each item
With the remove button in place and functioning, you are ready to commit
to the local branch and submit the pull request.
NOTE
Managing Policies
The next option you can manage is the policies for GitHub Copilot,
encompassing the following:
Suggestions matching public code
Copilot in GitHub.com
Copilot Chat in the IDE
Copilot in the CLI
Figure 15.36 shows a view of this page as an organization member with the
settings and their indicators of enabled and disabled status.
For more information on the allowable syntax and more examples, head to
the official documentation at the following URL:
https://docs.github.com/copilot/managing-github-copilot-in-
your-organization/configuring-content-exclusions-for-github-
copilot
Looking Ahead
Today, Copilot Enterprise provides the tools you need to be much more
productive and empowered in the SDLC. GitHub is moving at a rapid pace
to enhance the developer experience across a wide spectrum of developer
tooling and services. The following sections are development areas that are
of interest for the 2024 calendar year.
These product features might change or might not be released after their
alpha and beta testing rounds. Regardless, there are some very compelling
features on the horizon, and I'd like to share them with you.
Augmenting Results with Web Search Powered by Bing
Like the embeddings you have seen in the examples where repository files
are referenced by Copilot in a response, GitHub Copilot is rolling out web
search powered by Bing. This feature is currently in Beta at the time of
writing.
The Copilot Enterprise administrator will need to enable this under the
Policies area for Copilot.
References
[1] GitHub, 2024. “GitHub Copilot Business,”
https://docs.github.com/enterprise-
cloud@latest/copilot/copilot-business
[4] Choi N., 2024. “What is retrieval-augmented generation, and what does
it do for generative AI?,” https://github.blog/2024-04-04-what-is-
retrieval-augmented-generation-and-what-does-it-do-for-
generative-ai
[5] GitHub, 2024. “Copilot Workspace,”
https://githubnext.com/projects/copilot-workspace
OceanofPDF.com
Conclusion
As this exploration of GitHub Copilot concludes, it's clear that the
landscape of software development is undergoing a significant
transformation. GitHub Copilot has introduced a new paradigm of
programming, one where artificial intelligence acts not just as a tool but as
a collaborator, enhancing software development capabilities and workflows
far beyond traditional developer tooling.
Throughout this book, you have encountered many aspects of GitHub
Copilot, from basic code completions to its role in learning new
programming languages, writing robust tests, refactoring code, and even
navigating the complexities of CI/CD processes. You've seen how Copilot
can act as a universal converter, diagnose and resolve bugs, and help ensure
code security.
As technology evolves, so will GitHub Copilot, and with it, its applications
in the software development life cycle (SDLC) will continue to expand.
Future advancements will drive deeper integration of AI tools in the SDLC,
potentially reshaping job roles and industry standards. Embracing these
tools can lead to unprecedented productivity and innovation.
Encouraging responsible use of AI and understanding its implications on
privacy, security, and employment are essential as you move forward. As
you integrate GitHub Copilot into your development practices, please
continue to engage with the community, share insights, and contribute to the
progression of this transformative tool.
Thank you for joining me on this educational journey through the features,
capabilities, and applications of GitHub Copilot. The knowledge and
strategies shared here will help you harness the full potential of GitHub
Copilot in your development workflow.
OceanofPDF.com
APPENDIX A
Resources for Further Learning
This appendix is a curated list of resources designed to help you understand
and navigate the various aspects of GitHub Copilot. This guide includes
everything from getting started with the tool to detailed information about
subscription plans, community support, and legal guidelines. Whether you
are a new user looking to integrate GitHub Copilot into your workflow or
seeking deeper insights into its impact and ethical considerations, these
resources provide valuable information to enhance your knowledge and use
of this innovative tool.
OpenAI Codex
Get an introduction to Codex, the AI model behind GitHub Copilot, which
is capable of interpreting and executing commands in several programming
languages.
https://openai.com/blog/openai-codex
OceanofPDF.com
Glossary
AI (artificial intelligence)
The simulation of human intelligence processes by machines, especially
computer systems.
AI Bill of Rights
A nonbinding document proposed by the White House outlining the
rights citizens should have in the AI-enhanced world, emphasizing
privacy, transparency, and fairness.
AI Executive Order
A directive by the U.S. President mandating federal agencies to
incorporate and monitor responsible AI practices in their operations.
Angular
A platform and framework for building client-side, single-page web
applications using HTML and TypeScript.
@terminal agent
An agent in Copilot Chat focused on assisting with terminal-related
tasks and queries, optimizing the use of the terminal within the
development workflow.
@vscode agent
A keyword used in Copilot Chat to inquire about or interact with
features specific to the Visual Studio Code environment.
@workspace agent
A keyword in Copilot Chat allowing users to interact with their entire
workspace, enabling the AI to fetch context from all files in the project
for generating responses.
Azure Data Studio
A cross-platform database tool by Microsoft designed for data
professionals to manage SQL Server, Azure SQL Database, and Azure
SQL Data Warehouse from Windows, macOS, and Linux.
Behavior-Driven Development (BDD)
A software development approach that involves specifications written in
plain language, forming a common understanding among development,
QA, and nontechnical stakeholders. BDD focuses on the behavioral
specification of software units.
Bootstrap
A free and open-source CSS framework directed at responsive, mobile-
first, front-end web development.
C#
A modern, object-oriented, and type-safe programming language
developed by Microsoft, designed to enable developers to build a
variety of secure and robust applications that run on the .NET
ecosystem.
capability maturity model integration (CMMI)
A process-level improvement training and appraisal program
administered by the CMMI Institute, which provides organizations with
the essential elements of effective processes that ultimately improve
their performance.
code refactoring
The process of restructuring existing computer code—changing the
factoring—without changing its external behavior. It is aimed at
improving code readability and reducing complexity to enhance the
maintainability and extensibility of the code base.
code security
The practices and processes put in place to protect code from
vulnerabilities, unauthorized access, and other threats, ensuring that
software behaves as intended without any unintended or malicious
activities.
CodeQL
A tool for code analysis, used within platforms like GitHub Actions and
Azure DevOps pipelines to automatically identify vulnerabilities in
code before it is merged and deployed.
contextual prompting
Techniques used in Copilot Chat to enhance the AI's understanding of
the user's coding environment and intentions, such as the use of tags like
#editor and #file.
continuous deployment (CD)
A strategy for software release where code changes are automatically
prepared and deployed to a production environment without explicit
approval from developers, ensuring a fast and automated way to release.
continuous integration (CI)
A software development practice where developers frequently merge
code changes into a central repository. After this, automated builds and
tests are run.
CSRF protection
Measures to protect against Cross-Site Request Forgery, a type of
malicious website exploitation where unauthorized commands are
transmitted from a user that the web application trusts.
data encryption
The method of converting plaintext data into a coded form to prevent
unauthorized access.
DevSecOps
Short for Development, Security, and Operations, it integrates security
practices into the DevOps process. It emphasizes security at every phase
of the software development lifecycle to minimize vulnerabilities and
ensure continuous delivery of high-quality software.
Dockerfile
A text document that contains all the commands a user could call on the
command line to assemble an image. Docker can build images
automatically by reading the instructions from a Dockerfile.
dotnet CLI
The command-line interface for .NET used to create, run, and manage
.NET applications from the command line or terminal.
#editor context variable
A tag used in prompts to give GitHub Copilot context about the visible
code in the editor window, aiding in relevant and accurate code
suggestions.
end-to-end tests
Comprehensive testing that validates every process along with the flow
of an application from start to finish. It ensures the system's components
function together as expected from the user's perspective.
Entity Framework
An open-source object-relational mapping framework that is part of the
.NET Framework.
ESLint
A pluggable and configurable linter tool for identifying and reporting on
patterns in JavaScript, helping to make code more consistent and
avoiding bugs.
EU AI Act
European Union legislation aimed at regulating AI applications by
setting standards for ethical practices, risk assessment, and compliance
for AI systems used within the EU.
/explain command
A command used in Copilot Chat to request detailed explanations or
discussions about specific pieces of code or concepts.
#file context variable
A tag that allows users to specify which file(s) should be considered by
GitHub Copilot during the conversation, even if the file is not currently
open.
FIPS (Federal Information Processing Standards)
Publicly announced standards developed by the United States federal
government for use in computer systems.
/fix command
A command in Copilot Chat where GitHub Copilot provides
suggestions to correct errors in code based on the context of the error.
Gartner Hype Cycle
A methodology used by Gartner, an IT research and advisory firm, to
represent the maturity, adoption, and social application of specific
technologies.
generative AI models
Artificial intelligence models that can generate new content based on
their training data.
Gherkin syntax
A business readable, domain-specific language that lets you describe
software's behavior without detailing how that behavior is implemented.
Gherkin is primarily used to write structured tests for BDD.
GitHub
A platform for version control and collaboration, allowing developers to
work together on projects from anywhere.
GitHub Actions
GitHub's CI/CD platform that enables automation of all software
workflows, now with world-class CI/CD. Build, test, and deploy code
right from GitHub.
GitHub Advanced Security
A feature set for GitHub that provides tools for secure code
development, such as code scanning for vulnerabilities.
GitHub Classroom
A tool provided by GitHub to automate the use of GitHub for
educational purposes, which can be used to distribute and collect
assignments.
GitHub CLI
Command-line tools provided by GitHub that facilitate GitHub
operations like cloning repositories, managing issues, and handling pull
requests directly from the command line.
GitHub Copilot
An AI-powered tool designed to assist developers by suggesting code
snippets and entire functions while programming. It acts as an artificial
pair programming partner.
GitHub Copilot Business
A subscription plan that builds upon the functionalities available in
Copilot Individual by providing additional control and security features.
This plan allows organizations to manage how GitHub Copilot is used
within their teams, ensuring that the integration of this tool aligns with
their security policies and operational needs.
GitHub Copilot Chat within GitHub.com
A feature in Copilot Enterprise that allows users to interact with GitHub
Copilot directly through the GitHub.com interface, facilitating code-
related discussions and queries.
GitHub Copilot Enterprise
The most advanced subscription plan, designed for large organizations
using GitHub Enterprise Cloud. This plan includes all the features of
Copilot Business and adds exclusive capabilities such as direct
interaction with GitHub Copilot in the browser, access to advanced AI
features on GitHub.com, and more extensive control over how Copilot
interacts with the organization's codebases and data. Copilot Enterprise
is tailored to enhance productivity across the entire organization by
integrating deeply with GitHub's ecosystem.
GitHub Copilot knowledge base
A feature in GitHub Copilot Enterprise that allows organizations to
create and maintain a centralized repository of knowledge,
documentation, and FAQs to enhance the contextual understanding and
response accuracy of GitHub Copilot.
GitHub Copilot Vulnerability Prevention System
A feature of GitHub Copilot designed to enhance security by
proactively identifying and blocking insecure coding patterns in real-
time. This mechanism ensures that the code suggestions provided by
GitHub Copilot adhere to best security practices, thereby helping
developers avoid common security pitfalls while coding.
GPT-3 (Generative Pre-trained Transformer 3)
The third iteration of OpenAI's generative pre-trained transformer series
of large language models released in 2020.
GPT-4 (Generative Pre-trained Transformer 4)
The fourth iteration of OpenAI's generative pre-trained transformer
series of large language models released in 2023.
HTTPS (Hypertext Transfer Protocol Secure)
An extension of the hypertext transfer protocol (HTTP) used for secure
communication over a computer network.
integration testing
A level of software testing where individual units are combined and
tested as a group. The purpose is to expose faults in the interaction
between integrated units.
JavaScript
A high-level, interpreted programming language that conforms to the
ECMAScript specification. JavaScript is one of the core technologies of
the Web, alongside HTML and CSS, and enables interactive web pages.
JetBrains IntelliJ IDEA
An IDE by JetBrains primarily focused on Java development but also
supports a wide range of other programming languages and
technologies through plugins.
legacy system
An old method, technology, computer system, or application program
that continues to be used despite its age.
modernization
The process of refactoring, re-architecting, or replacing legacy software
systems to align them more closely with current business needs.
Neovim
An extended version of Vim, an open-source text editor designed to
improve Vim's functionality and ease of use for more complex editing
and development tasks.
NestJS
A progressive Node.js framework for building efficient, reliable, and
scalable server-side applications.
.NET
A free, cross-platform, open-source developer platform for building
many different types of applications, known for its robustness and wide
range of capabilities.
.NET Core SDK
A software development kit (SDK) used to develop applications with
.NET, which includes the runtime and command-line tools for creating
.NET applications.
/new command
A command used to initiate the scaffolding of a new project or codebase
in a specific programming context, guided by the user's specifications.
/newNotebook command
A command that triggers the creation of a structured Jupyter Notebook
for tasks such as exploratory data analysis, leveraging Copilot's ability
to scaffold code.
NIST (National Institute of Standards and Technology)
An agency of the U.S. Department of Commerce, responsible for
developing standards, including those for data encryption.
Node.js
An open-source, cross-platform, JavaScript runtime environment that
executes JavaScript code outside a web browser.
OpenAI Codex
A descendant of the GPT-3 model, trained specifically to understand
and generate code across various programming languages.
OWASP (Open Web Application Security Project)
An online community that produces freely available articles,
methodologies, documentation, tools, and technologies in the field of
web application security.
OWASP Top 10
A standard awareness document for developers and web application
security. It represents a broad consensus about web applications’ most
critical security risks.
pair programming
A software development technique where two programmers work
together. One, the driver, writes code while the other, the observer or
navigator, reviews each line of code as it is typed in. The roles are
frequently switched.
Pandas
Pandas is an open-source Python library used for data analysis and
machine learning, built on Numpy, which supports multi-dimensional
arrays.
Polars
A high-performance data manipulation library, providing a DataFrame
object similar to Pandas but with better performance.
prompt engineering
The practice of crafting precise and effective prompts to improve the
quality of responses from AI systems, crucial in working with tools like
GitHub Copilot.
React.js
A JavaScript library for building user interfaces, particularly for single-
page applications where you need to interact quickly with the user.
red teaming
A strategy where teams actively try to find and exploit new
vulnerabilities in a system, helping to identify and mitigate potential
security issues.
responsible AI
Practices that ensure artificial intelligence technologies are developed
and implemented in a safe, ethical, and reliable manner, adhering to
principles like fairness, transparency, and accountability.
retrieval-augmented generation (RAG)
A process used to enhance the output of large language models by
incorporating real-time data retrieval from an external knowledge base,
ensuring the generated content is accurate, relevant, and informed by
the latest information.
Scrum
An agile process framework for managing complex knowledge work,
with an initial emphasis on software development, although it has been
used in other fields and is slowly starting to be explored for other
complex projects, too.
security scanning
The process of scanning software for security vulnerabilities, typically
integrated into the CI/CD pipeline to ensure that vulnerabilities are
caught and remedied before deployment.
#selection context variable
A tag indicating to GitHub Copilot that the selected text in the editor
should be considered as context for the conversation.
shift left on security
A practice in DevSecOps of integrating security measures early in the
software development lifecycle rather than at the end to catch
vulnerabilities earlier when they are typically less costly to fix.
software development life cycle (SDLC)
A systematic process used by development teams to create high-quality
software efficiently. It includes phases such as requirements gathering,
system design, implementation, testing, deployment, and maintenance.
Swift
A powerful and intuitive programming language created by Apple for
building apps for iOS, Mac, Apple TV, and Apple Watch, designed to
work with Apple's Cocoa and Cocoa Touch frameworks.
Tailwind CSS
A utility-first CSS framework for rapidly building custom designs.
Terraform
An open-source infrastructure as code (IaC) software tool that provides
a consistent CLI workflow to manage hundreds of cloud services.
Terraform codifies cloud APIs into declarative configuration files.
/tests command
A command that instructs GitHub Copilot to generate unit tests for a
specified method or function, helping to streamline test development.
TLS (Transport Layer Security)
A cryptographic protocol designed to provide communications security
over a computer network.
TypeORM
An ORM (object-relational mapper) for TypeScript and JavaScript that
facilitates interactions with databases by abstracting database
interactions into easily manageable objects.
TypeScript
A superset of JavaScript that compiles to plain JavaScript, known for its
optional static typing features.
unit tests
Tests that validate the functionality of a specific section of code, usually
at the function level, allowing developers to verify that each part of the
system operates as expected independently.
Visual Studio
An IDE developed by Microsoft that supports a multitude of
programming languages and tools for developing and managing
complex software projects.
VS Code (Visual Studio Code)
A free source-code editor made by Microsoft for Windows, Linux, and
macOS. Features include support for debugging, syntax highlighting,
intelligent code completion, snippets, and code refactoring.
OceanofPDF.com
Index
A
access, managing, 288–289
accountability principle, 223–225
Ad Hoc AI Integration in Projects, in level 1, AI integration in SDLC, 234
adding
code, 78–79
context with attach to current thread, 277–279
security scanning, 154–156
unit tests, 117–120, 122–123
unit tests to existing code, 89–94
user accounts, 95–99
AddItem() function, 275
Advanced AI Use Cases, in level 3, AI integration in SDLC, 236
Advanced Metrics and KPIs, in level 4, AI integration in SDLC, 236
AI (artificial intelligence). See also responsible AI
adoption concerns, 250–251
assessing adoption of in SDLC, 231–232
behind GitHub Copilot, 17–18
defined, 303
impact on developer experience, 301
levels of integration in SDLC, 232–238
AI Bill of Rights, 303
AI Executive Order, 218, 303
AI-augmented software engineering (AIASE), 232
aliases, setting up for Copilot, 185
angular, 303
/api command, 64
application security development operations (DevSecOps), 134
applying security controls, 147–148, 151–152
artificial intelligence (AI). See also responsible AI
adoption concerns, 250–251
assessing adoption of in SDLC, 231–232
behind GitHub Copilot, 17–18
defined, 303
impact on developer experience, 301
levels of integration in SDLC, 232–238
assessing adoption of AI in SDLC, 231–232
audit logs, reviewing, 291
augmenting results with Web Search Powered by Bing, 292
automating infrastructure as code (IaC), 148–152
Automation, in DevSecOps, 144
Awareness Building Among Teams, in level 1, AI integration in SDLC, 235
Azure Data Studio, 166–170, 303
B
backend development, 269
backlog, refining, 242–243
BadRequestException, 106
base features, in Copilot Business and Enterprise, 254–256
Bash, setting up aliases for Copilot, 185
Basic AI Tool Experimentation, in level 1, AI integration in SDLC, 234
Basket Domain Model, updating, 281–282
basket page, updating, 284–285
BasketService, updating, 283–284
behavior-driven development (BDD), 94–99, 303
Biden, Joe, 218
bootstrap, 192, 304
Brussels effect, 218
bugs
about, 101
establishing example projects, 101–103
fixing syntax errors, 103–105
resolving runtime exceptions, 105–109
resolving terminal errors, 109–111
C
C# Dev Kit, 71
C# language, 70, 304
Copilot, 73–74
calculateTotal function, 197
capability maturity model integration (CMMI), 233, 304
Cascading Style Sheets (CSS), simplifying styles, 191–196
CCC (Customer Copyright Commitment), 21
changing code, 281–285
Chat (Copilot)
about, 41
commanding conversations with, 52–65
defining prompt engineering with, 48–52
enhancing IntelliJ IDEA, 175–176
enhancing Visual Studio Code, 163–165
expanding conversations to new windows, 43–45
leveraging in code repository files, 273–279
maximizing conversations with Editor view, 42–43
Quick Chat, 47–48
shifting conversations to the right, 45
sidebar window, 42
using inline chat, 45–46
chatting
with GitHub.com, 257–262
in integrated development environment (IDE), 254–255
CI/CD (continuous integration/continuous delivery), streamlining, 152–158
CI/CD platforms, transitioning, 206–209
CLI (command-line interface), 109
in, 256
CMMI (capability maturity model integration), 233, 304
COBAL programs, modernizing, 209–213
code
adding, 78–79
adding unit tests to existing, 89–94
changing, 281–285
deploying using Terraform, 150–151
explaining with Copilot, 77–78
prompting for, 49
refactoring duplicate, 116–122
code completions
about, 25–26
exploring, 162–163, 172–175, 177–180
leveraging keyboard shortcuts, 38–40
Panel, 34, 35
Toolbar, 34–35
updating CoPilot settings, 36–37
working with, 26–33
code refactoring
about, 113–114
bad variable names, 127–129
defined, 304
documenting and commenting, 129–132
for duplicate code, 116–122
establishing example projects, 114–115
validators for, 122–127
code repositories
getting insights about, 258–260
indexing, 262–267
leveraging chat in, 273–279
code security
about, 133–134
defined, 304
establishing example projects, 134–135
exploring, 135–138
finding and fixing issues with, 139–142
CodeQL, 304
coding, with Copilot, 245–246
Coding phase, in SDLC, 231
Collaboration, in DevSecOps, 144
command-line interface (CLI), 109
in, 256
commands
in conversations, 52–65
explaining with Copilot, 183–184
comments
driving unit test creation with, 89–92
writing, 31–32
committing to feature branch, 285–286
community engagement and support, 299
Comprehensive AI Strategy, in level 3, AI integration in SDLC, 236
configuring IDE settings for GitHub Copilot, 7–9
console applications, creating, 74–77
Constitutional Bill of Rights, 218
consulting GitHub Copilot in GitHub CLI, 181–185
containers
creating, 145–146
deploying, 146–147
simplifying, 144–148
content exclusion, 290–291
context
adding with attach to current thread, 277–279
creating with selection, 82–84
creating with tags, 84
gaining in Chat, 50–52
contextual prompting, 304
continuous integration/continuous delivery (CI/CD), streamlining, 152–158
Continuous Process Optimization, in level 5, AI integration in SDLC, 237
Continuous security, in DevSecOps, 144
conversations
commands in, 52–65
expanding with new windows in Chat, 43–45
maximizing in Chat with Editor view, 42–43
shifting to the right in chat, 45
converting
between CSS frameworks, 192–196
JavaScript components, 190–191
object-oriented languages, 203–205
Copilot Business and Enterprise
about, 253–254
base features, 254–256
chatting with in GitHub.com, 257–262
Copilot Business, 256–257
Copilot Enterprise, 257
defined, 306
enhancing pull requests, 279–287
indexing code repositories, 262–267
knowledge base, 267–273
leveraging chat in code repository files, 273–279
looking ahead, 292
managing, 288–291
Copilot Chat. See Chat (Copilot)
copyright protections, 20–21
Coverage Gutters extension, 88, 102
create() method, 89, 92, 103, 105, 122, 125
creating
CD pipelines, 156–158
CI pipeline, 153–154
console applications, 74–77
containers, 145–146
context with selection, 82–84
context with tags, 84
database schemas, 166–168
GitHub accounts, 4
infrastructure as code (IaC), 148–150
knowledge base, 267–273
tests, 56–59
tests using inline chat, 93–94
cross-site scripting attack, 221
CSRF protection, 304
CSS (Cascading Style Sheets), simplifying styles, 191–196
Customer Copyright Commitment (CCC), 21
customizing Copilot with fine-tuned models, 292
D
data encryption, 304
data handling, 18–20
data protection, 221–222
data storage, 19
data transfer objects (DTOs), 104
database development, 269
database schemas, creating, 166–168
databases, migrating, 205–206
Data-Driven Process Improvement, in level 4, AI integration in SDLC, 236
decoding GitHub Copilot, 17–21
defining prompt engineering with Copilot Chat, 48–52
deploying
code using Terraform, 150–151
containers, 146–147
with Copilot, 248–250
Deployment phase, in SDLC, 231
describe() function, 120
Design phase, in SDLC, 230
development environments
about, 159
consulting Copilot in GitHub CLI, 181–185
enhancing, 159–185
enhancing Azure Data Studio, 166–170
enhancing JetBrains IntelliJ IDEA, 171–176
enhancing Neovim, 176–180
enhancing Visual Studio, 159–165
setting up, 70–72
DevSecOps
about, 143–144
automating infrastructure as code (IaC), 148–152
defined, 304
simplifying containers, 144–148
streamlining CI/CD pipelines, 152–158
/doc command, 129
Dockerfile, 305
dotnet CLI, 305
downloading Visual Studio Code (VS Code), 5–6
DTOs (data transfer objects), 104
E
EDA (exploratory data analysis), 62–63
Editor context, 50–51
#editor context variable, 305
Editor view, maximizing chat conversations with, 42–43
end-to-end (E2E) tests, 96–99, 305
enhancing
Azure Data Studio, 166–170
development environments, 159–185
JetBrains IntelliJ IDEA, 171–176
Neovim, 176–180
nontyped languages with types, 196–198
pull requests, 279–287
Visual Studio, 159–165
Enterprise-wide AI Culture, in level 5, AI integration in SDLC, 237
Entity Framework, 305
error handling code, refactoring duplicate, 120–122
ESLint, 102, 135, 305
ethical considerations, 299–300
EU Artificial Intelligence Act, 300, 305
European Union AI Act, 218
expanding chat conversations with new windows, 43–45
/explain command, 53–56, 77, 109, 189, 305
exploratory data analysis (EDA), 62–63
Express.js, 201–203
extracting validation code to functions, 124–127
F
fairness principle, 219–220
feature branch, committing to, 285–286
Federal Information Processing Standard (FIPS), 19, 305
fetchDadJoke() function, 179–180
File context, 51–52
#file context variable, 125, 164, 195, 305
files, naming, 26
finding
fixes, 59–61
security issues, 139–142
findOne() function, 116–117, 141–142
FIPS (Federal Information Processing Standard), 19, 305
/fix command, 59–61, 141, 305
fixes, finding, 59–61
fixing
security issues, 139–142
syntax errors, 103–105
Focus on GitHub Copilot View action, 39
Foundation, 192
frameworks, transitioning between libraries and, 199–203
front-end development, 269
functions, extracting validation code to, 124–127
future of work, 250–251
G
Gartner, 231–232
Gartner Hype Cycle, 305
General Data Protection Regulation (GDPR), 221–222
generative AI models, 305
gh copilot suggest function, 181
Gherkin syntax, 95, 188, 305
git checkout command, 110
GitHub
creating accounts, 4
defined, 305
GitHub Actions, 306
GitHub Advanced Security, 20, 306
GitHub Classroom, 306
GitHub CLI
about, 181
consulting Copilot in, 181–185
defined, 306
GitHub Copilot
about, xvii, 3
artificial intelligence (AI) behind, 17–18
benefits of, 4
Chat, 41–65, 306
configuring IDE settings for, 7–9
consulting in GitHub CLI, 181–185
creating console applications with, 74–77
decoding, 17–21
defined, 306
installing extension, 6–7, 160–162, 166, 171–172, 177, 181
learning C# with, 73–74
managing, 288–291
nondeterministic nature of, 13
obtaining a license for, 4–5
overview, 297–299
subscription plans, 297–299
testing, 10–15
Trust Center, 21, 299
updating settings, 36–37
writing tests with, 87–99
GitHub Copilot Enterprise, 306
GitHub Copilot knowledge base, 267–273, 306
GitHub Copilot Vulnerability Prevention System, 306
GitHub.com, chatting with, 257–262
GPT-3 (Generative Pre-trained Transformer 3), 18, 307
GPT-4 (Generative Pre-trained Transformer 4), 307
Greeting() method, 78, 82
H
hashPassword() function, 140
--help commands, 109
Hypertext Transfer Protocol Secure (HTTPS), 19, 137, 307
I
IDE (integrated development environment)
chatting in, 254–255
programming with Copilot in, 254
IDE extension, installing, 5–9
implementing
responsible AI, 218–225
validation, 138
inclusiveness principle, 223
indexing code repositories, 262–267
information assurance, 269
infrastructure as code (IaC)
automating, 148–152
creating, 148–150
Initial Data Analysis Efforts, in level 1, AI integration in SDLC, 234
inline chat
about, 45–46
generating tests using, 93–94
inlineSuggestCount setting, 37
Innovative AI Application, in level 5, AI integration in SDLC, 237
inserting test data, 168–169
installing
GitHub Copilot extension, 6–7, 160–162, 166, 171–172, 177, 181
IDE extension, 5–9
Node.js, 9
integrated development environment (IDE)
chatting in, 254–255
programming with Copilot in, 254
integration testing, 307
IsPalindrome function, 14, 164, 174–176
isRomanNumeral() method, 29
J
JavaScript
converting components, 190–191
defined, 307
to TypeScript, 197–198
JetBrains IDE, 5
JetBrains IntelliJ IDEA
defined, 307
enhancing, 171–176
K
keyboard shortcuts
about, 10
leveraging, 38–40
knowledge base, 267–273, 306
Koa.js, 201–203
L
learning
C# language with Copilot, 73–74
resources for further, 297–301
to test, 79–85
legacy systems
defined, 307
modernizing, 209–213
legal considerations, 299–300
length, of prompts, 50
length setting, 37
level 0, AI integration in SDLC, 233–234
level 1, AI integration in SDLC, 234–235
level 2, AI integration in SDLC, 235
level 3, AI integration in SDLC, 235–236
level 4, AI integration in SDLC, 236–237
level 5, AI integration in SDLC, 237
leveraging
Copilot in CLI, 256
keyboard shortcuts, 38–40
libraries, transitioning between frameworks and, 199–203
license, obtaining for GitHub Copilot, 4–5
Limited Awareness or Understanding, in level 0, AI integration in SDLC,
234
Linux
Neovim on, 177
Vim on, 177
listCount setting, 37
LLM, 20–21
M
macOS
Neovim on, 177
Vim on, 177
Maintenance phase, in SDLC, 231
Management of AI Tools and Processes, in level 2, AI integration in SDLC,
235
managing
access, 288–289
GitHub Copilot, 288–291
policies, 289–290
Material UI, 192
maximizing conversations with Editor view, 42–43
message transmission, 19
method documentation, 129–130
Microsoft, 21
Microsoft Copilot Copyright Commitment, 299
migrating databases, 205–206
models, customizing Copilot with fine-tuned, 292
modernization
defined, 307
of legacy systems, 209–213
N
names, importance of using meaningful, 29–31
naming files, 26
National Institute of Standards and Technology (NIST), 19, 308
natural language, translating to programming languages, 188–189
Navigate to the Next Panel Suggestion action, 39
Navigate to the Previous Panel Suggestion action, 40
Neovim
defined, 307
enhancing, 176–180
NestJS, 88, 95, 101, 102, 115, 135, 307
.NET, 307
.NET Core SDK, 71, 307
/new command, 61–62, 74, 307
/newNotebook command, 62–63, 308
NIST (National Institute of Standards and Technology), 19, 308
No AI-Driven Optimization, in level 0, AI integration in SDLC, 234
Node.js, 9, 102, 115, 135, 177, 308
nondeterministic nature, of GitHub Copilot, 13
nontyped languages, enhancing with types, 196–198
nvim command, 177
O
Objective-C, 203–205
object-oriented languages, converting, 203–205
obtaining license for GitHub Copilot, 4–5
Open Completions Panel action, 40
Open Tabs context, 50
Open Web Application Security Project (OWASP), 133–134, 308
OpenAI, 18
OpenAI Codex, 18, 301, 308
operations, 270
Organization-wide AI Integration, in level 3, AI integration in SDLC, 236
OWASP Top 10, 308
P
pair programming, 308
Pandas, 199–201, 308
Panel (GitHub Copilot), 34, 35
password hashing, 140–141
PBR (product backlog refinement) meeting, 242
Performance Benchmarking, in level 4, AI integration in SDLC, 237
Performance Measurement, in level 2, AI integration in SDLC, 235
planning, with Copilot, 243–245
Polars, 199–201, 308
policies, managing, 289–290
Postgre SQL, 205–206
PowerShell
Neovim on Windows via, 177
setting up aliases for Copilot, 185
Vim on Windows via, 177
Predictive Analytics for Process Optimization, in level 4, AI integration in
SDLC, 237
prerequisites, for testing Copilot, 10
privacy
about, 18–20, 221
data protection, 221–222
vulnerability prevention system, 222–223
Process-Specific AI Integration, in level 2, AI integration in SDLC, 235
product backlog, 242
product backlog refinement (PBR) meeting, 242
programming
with Copilot in IDE, 254
questions about, 260–262
with responsible AI, 226
programming languages
about, 69–70
adding code, 78–79
basics of, 72–74
creating console applications, 74–77
explaining code with Copilot, 77–78
learning to test, 79–85
setting up development environment, 70–72
translating natural language to, 188–189
project documentation, 130–132
prompt engineering
defined, 308
defining with Copilot Chat, 48–52
prompts, 19
pull requests
enhancing, 279–287
summarizing, 286–287
Q
:q command, 177
quality assurance, 269
querying, 170
questions, repository-specific, 265–267
Quick chat, 47–48
R
RAG (retrieval-augmented generation), 263–264, 300, 308
Reactive Problem-Solving, in level 0, AI integration in SDLC, 234
React.js, 308
red teaming, 220–221, 308
referencing open tabs, 32–33
refining backlog, 242–243
reliability, 220–221
remove() function, 118
RemoveItem() function, 281–282
requirements gathering, 239–241
requirements management, 270
Requirements phase, in SDLC, 230
research and insights, 300–301
researching responsible AI principles, 226
resolving
runtime exceptions, 105–109
terminal errors, 109–111
resources, for further learning, 297–301
Responsibility, in DevSecOps, 144
responsible AI
about, 217–218
defined, 308
empowering practices, 300
implementing, 218–225
programming with, 226
REST API, 95
retrieval-augmented generation (RAG), 263–264, 300, 308
reviewing audit logs, 291
running tests, 84–85
runtime exceptions, resolving, 105–109
S
safety, 220–221
SAST (static application security testing), 134
Scrum, 242, 309
SDLC (software development life cycle)
about, 229–231
addressing concerns, 250–251
assessing adoption of AI in, 231–232
defined, 309
detailing levels of AI integration in, 232–238
showcasing GitHub Copilot in, 238–250
security
about, 18–20
applying controls for, 147–148, 151–152
data protection, 221–222
vulnerability prevention system, 222–223
security scanning
adding, 154–156
defined, 309
SELECT statement, 209–210
selection, creating context with, 82–84
Selection context, 52
#selection context variable, 309
Sematic UI, 192
settings, updating for GitHub Copilot, 36–37
setup
aliases for Copilot, 185
development environment, 70–72
shift left on security, 309
Shift left on security, in DevSecOps, 144
shifting chat conversations to the right, 45
sidebar chat window, 42
simplifying
containers, 144–148
CSS styles, 191–196
software development life cycle (SDLC)
about, 229–231
addressing concerns, 250–251
assessing adoption of AI in, 231–232
defined, 309
detailing levels of AI integration in, 232–238
showcasing GitHub Copilot in, 238–250
solutions, prompting for, 49
SQL injection, 141–142
SQL Server, 205–206
Standardized AI Processes, in level 3, AI integration in SDLC, 236
static application security testing (SAST), 134
Strategic AI Evolution, in level 5, AI integration in SDLC, 237
streamlining CI/CD pipelines, 152–158
subscription plans, 297–299
Suggest Terminal Command action, 39
suggestions, 19, 181–183
Suggestions Matching Public Code setting, 21
summarizing pull requests, 286–287
supercharging Copilot with Workspace, 292
Swift, 203–205, 309
syntax errors, fixing, 103–105
T
Tab key, 12
tabs, referencing open, 32–33
tags, creating context with, 84
Tailwind CSS, 192, 309
Targeted AI Implementation, in level 2, AI integration in SDLC, 235
tasks, pull request, 280–281
@terminal agent, 64–65, 303
terminal errors, resolving, 109–111
Terraform
defined, 309
deploying code using, 150–151
test data, inserting, 168–169
test-driven development (TDD), 94
testing
with Copilot, 246–248
GitHub Copilot, 10–15
Testing phase, in SDLC, 231
tests
about, 87
adding unit tests to existing code, 89–94
behavior-driven development, 94–99
end-to-end (E2E), 96–99
establishing example projects, 87–89
generating, 56–59
learning to, 79–85
running, 84–85
writing with Copilot, 87–99
/tests command, 56–59, 93, 247–248, 309
TIOBE Index, 70
TLS (Transport Layer Security), 19, 309
Toolbar (GitHub Copilot), 34–35
top-level commitment, 26–29
toThrowError function, 106
Traditional Development Approaches, in level 0, AI integration in SDLC,
234
transitioning
CI/CD platforms, 206–209
between frameworks and libraries, 199–203
translating natural language to programming languages, 188–189
transparency principle, 223
Transport Layer Security (TLS), 19, 309
Triggering Inline Suggestion action, 39
Trust Center (GitHub Copilot), 21
Type ORM, 309
TypeError, 106
types, enhancing nontyped languages with, 196–198
TypeScript, 197–198, 309
U
unit tests
adding, 117–120, 122–123
adding to existing code, 89–94
defined, 309
universal conversion
about, 187
converting JavaScript components, 190–191
converting object-oriented languages, 203–205
enhancing nontyped languages with types, 196–198
migrating databases, 205–206
modernizing legacy systems, 209–213
simplifying CSS styles, 191–196
transitioning between frameworks and libraries, 199–203
transitioning CI/CD platforms, 206–209
translating natural language to programming languages, 188–189
update() function, 116
updating
Basket Domain Model, 281–282
basket page, 284–285
BasketService, 283–284
Copilot settings, 36–37
user accounts, adding, 95–99
user engagement data, 19
UserController class, 116, 120
UserService class, 130
V
validation, implementing, 138
validators, refactoring, 122–127
variables, refactoring bad names for, 127–129
Visual Studio, 310
Visual Studio Code (VS Code)
defined, 310
downloading, 5–6
enhancing, 159–165
IDE, 5
@vscode agent, 63–64, 303
vulnerability prevention system, 20, 222–223
W
Wakefield Research, 232
weak password hashing, 140–141
Web Search Powered by Bing, augmenting results with, 292
websites
Azure Data Studio, 166
Coverage Gutters extension, 88, 102
ESLint, 102, 135
EU Artificial Intelligence Act, 300
GitHub CLI, 181
GitHub Copilot extension, 26, 72
GitHub Copilot Trust Center, 21, 299
GitHub.com, 257–262
JetBrains IntelliJ IDEA, 171
Microsoft Copilot Copyright Commitment, 299
Neovim, 177
NestJS, 88, 102, 115, 135
Node.js, 9, 26, 88, 102, 115, 135, 177
Open Worldwide Application Security Project (OWASP), 134
OpenAI Codex, 301
research and insights, 300–301
Visual Studio Code (VS Code), 5, 26, 72, 88, 102, 115, 135, 160
windows, expanding chat conversations with new, 43–45
Windows via PowerShell
Neovim on, 177
Vim on, 177
work, future of, 250–251
Workspace, supercharging Copilot with, 292
@workspace agent, 42, 53–63, 77, 80, 164, 303
:wq command, 179
writing
comments, 31–32
tests with Copilot, 87–99
Z
Zsh, setting up aliases for Copilot, 185
OceanofPDF.com
Copyright © 2024 by John Wiley & Sons, Inc. All rights, including for text and data mining, AI
training, and similar technologies, are reserved.
Published by John Wiley & Sons, Inc., Hoboken, New Jersey.
Published simultaneously in Canada and the United Kingdom.
ISBNs: 9781394263370 (paperback), 9781394263394 (ePDF), 9781394263387 (ePub)
No part of this publication may be reproduced, stored in a retrieval system, or transmitted in any
form or by any means, electronic, mechanical, photocopying, recording, scanning, or otherwise,
except as permitted under Section 107 or 108 of the 1976 United States Copyright Act, without either
the prior written permission of the Publisher, or authorization through payment of the appropriate
per-copy fee to the Copyright Clearance Center, Inc., 222 Rosewood Drive, Danvers, MA 01923,
(978) 750-8400, fax (978) 750-4470, or on the web at www.copyright.com. Requests to the Publisher
for permission should be addressed to the Permissions Department, John Wiley & Sons, Inc., 111
River Street, Hoboken, NJ 07030, (201) 748-6011, fax (201) 748-6008, or online at
www.wiley.com/go/permission.
Trademarks: Wiley and the Wiley logo, are trademarks or registered trademarks of John Wiley &
Sons, Inc. and/or its affiliates in the United States and other countries and may not be used without
written permission. GitHub Copilot is a trademark of GitHub, Inc. All other trademarks are the
property of their respective owners. John Wiley & Sons, Inc. is not associated with any product or
vendor mentioned in this book.
Limit of Liability/Disclaimer of Warranty: While the publisher and author have used their best
efforts in preparing this book, they make no representations or warranties with respect to the
accuracy or completeness of the contents of this book and specifically disclaim any implied
warranties of merchantability or fitness for a particular purpose. No warranty may be created or
extended by sales representatives or written sales materials. The advice and strategies contained
herein may not be suitable for your situation. You should consult with a professional where
appropriate. Further, readers should be aware that websites listed in this work may have changed or
disappeared between when this work was written and when it is read. Neither the publisher nor
author shall be liable for any loss of profit or any other commercial damages, including but not
limited to special, incidental, consequential, or other damages.
For general information on our other products and services, please contact our Customer Care
Department within the United States at (800) 762-2974, outside the United States at (317) 572-3993.
For product technical support, you can find answers to frequently asked questions or reach us via live
chat at https://support.wiley.com.
Wiley also publishes its books in a variety of electronic formats. Some content that appears in print
may not be available in electronic formats. For more information about Wiley products, visit our web
site at www.wiley.com.
Library of Congress Cataloging in Publication data available on request.
Cover image: © CSA-Printstock/Getty Images
Cover design: Wiley
OceanofPDF.com
Acknowledgments
Creating this book has been a collaborative effort that would not have been
possible without the guidance, support, and encouragement of many people.
First, I want to express my gratitude to Kenyon Brown for believing in my
vision and providing me with the opportunity to bring this book to life.
A heartfelt thanks to Satish Gowrishankar for keeping everything on track
with meticulous planning, organization, and dedication to deadlines. Your
oversight ensured the process remained smooth and effective.
I am deeply grateful to Janet Wehner for coordinating the content and
guiding the production through each step with keen attention to detail and
precision.
Special appreciation goes to T.J. Corrigan for offering invaluable expertise
and meticulously reviewing the technical aspects. Your assistance helped
shape this book into what it is today.
To my wife, Paige Lord-Dowswell, thank you for your encouragement,
insights, and acumen. You were instrumental in helping me get this book
across the finish line.
—Kurt Dowswell
OceanofPDF.com
About the Author
Kurt Dowswell is a seasoned software architect with more than 13 years of
industry experience. Kurt has spent the larger part of his career leading
teams of developers in building, deploying, and maintaining large-scale
enterprise software solutions for the U.S. government. He graduated with a
BS in computer science from James Madison University.
OceanofPDF.com
WILEY END USER LICENSE AGREEMENT
Go to www.wiley.com/go/eula to access Wiley’s ebook EULA.
OceanofPDF.com