Skip to content

Analysis Features

Analyzing a New Repo/Application with GitHub Copilot

Objective

In this section, we will explore how to use prompt engineering with GitHub Copilot to analyze a new repository or application. We will walk through potential prompts to help understand our workshop application and its various components. Screenshots will be provided to illustrate the process.

Understanding the DKS Application Structure

Before we dive into adding new features and testing, let's first understand the structure of the DKS (DevOps Knowledge Share) application.

The DKS application is a Spring Boot application. It is centered around maintaining blog posts, so when we refer to "post" objects later, we are referring to the blog posts in this application. It has a typical MVC (Model-View-Controller) structure. Here are the key components:

  • Model: This is the data and the rules around the data in your application. It represents the information (the data) of the application and the rules to manipulate that data. For example, the Post class in src/main/java/com/liatrio/dojo/devopsknowledgeshareapi/Post.java represents the data structure of a post in the application.

  • View: The dks-api is a RESTful API, so it doesn't have a traditional view like a web application would. Instead, it returns data in a machine-readable format (usually JSON) which can be used by other applications or services. The user interface for this application is handled by the DevOps Knowledge Share UI (dks-ui), a separate React application that interacts with this API.

  • Controller: This is the link between the Model and the View. It takes user input from the view, manipulates the model based on that input, and updates the view to reflect changes in the model. For example, the PostController class in src/main/java/com/liatrio/dojo/devopsknowledgeshareapi/PostController.java handles HTTP requests and responses.

  • Repository: The PostRepository interface in src/main/java/com/liatrio/dojo/devopsknowledgeshareapi/PostRepository.java provides methods for interacting with the database.

  • Clone each repository: Start by cloning each repository. Use the git clone command followed by the repository URL to create a local copy of the repository on your machine.

    Note: We recommend cloning the repositories into a single directory to allow both repositories to be open in the same workspace.

Clone the repositories

git clone https://github.com/liatrio/liatrio-copilot-catalyst-api
git clone https://github.com/liatrio/liatrio-copilot-catalyst-ui
  1. Create a new branch with git: Once you have cloned the repositories, navigate to each repository's directory and use the git checkout -b command followed by the branch name to create a new branch for analysis. This will allow you to make changes and experiment without affecting the main branch.

  2. Open the repository in your IDE: Start by opening each repository we want to analyze in your preferred Integrated Development Environment (IDE). Make sure you have the GitHub Copilot extension installed and enabled.

  3. Start a new conversation with GitHub Copilot: In your IDE, open the GitHub Copilot chat interface. You can do this by clicking on the GitHub Copilot icon in the toolbar or by using the keyboard shortcut.

  4. Ask GitHub Copilot about the repository: Use the chat interface to ask GitHub Copilot questions about the repository. For example, you might ask "What does this repository do?" or "What is the main function of this application?". We will be utilizing these questions to their maximum by opening a new workspace with both the UI and API within the same workspace. Then by using @workspace before the prompt, we can ask questions about the entire environment.

Ask GitHub Copilot about the repository

@workspace What do these repositories do and how are they related to each other?

GitHub Copilot will analyze the code in the repository and provide a response based on its understanding of the code.

Image: Response 1

  1. Ask follow-up questions: You can ask follow-up questions to get more detailed information about specific parts of the code. For example, while in the file of a function you are curious about, you might ask "What does ______ function do?" or "How is the ______ class used?".

Ask a follow-up question

@workspace What does the setLink function in #file:Post.java do?

You can also navigate directly to the file at dks-api/src/main/java/com/liatrio/dojo/devopsknowledgeshareapi/Post.java and ask your question in line.

Ask a follow-up question in line

What does this "setLink" function do?

Again, GitHub Copilot will provide a response based on its analysis of the code. It has direct access to the current file that is open in the IDE, so it can provide more detailed and relevant responses as shown below.

Response 2

  1. Continue the conversation: You can continue asking questions and exploring the code with GitHub Copilot until you have a good understanding of what the repository or application does.

Conclusion

Prompt engineering with GitHub Copilot is a powerful tool for understanding new code bases. By asking the right questions, you can quickly get a high-level overview of a repository or dive deep into specific parts of the code. Remember, the more specific your questions, the more detailed and helpful GitHub Copilot's responses will be.