Ask GitHub Copilot for code review in your .NET project

Knowledge session of DevOps

Overview

In this blog post, I’ll share my experience building a .NET 8 Azure Function App that retrieves a user profile via the Microsoft Graph API. The function app is designed to run in Azure and return the user profile of the logged-in user via Microsoft Entra-ID. While the technical implementation was exciting, the interesting part of this journey was using GitHub Copilot as a code reviewer through Pull Requests in GitHub. It became generally available on April 4th. I’ll walk you through the process, share my thoughts on Copilot’s feedback, and highlight areas where it shines and where it could improve.

The project

👀 Link to my GitHub project pull request

The goal was to create a dotnet-isolated Azure Function App with the following features:

  • A GET endpoint to fetch the user profile from the Microsoft Graph API.
  • Support for both local development and Azure deployment using appropriate credentials (e.g., Azure CLI for local and Managed Identity for Azure).
  • Logging for observability and error handling.

The function app was implemented using .NET 8 and deployed to Azure. You can find the full implementation in the repository.

Using GitHub Copilot for code reviews

After completing the initial implementation, I decided to use GitHub Copilot’s code review feature to improve the quality of my code. GitHub Copilot can be configured to provide feedback on Pull Requests, as described in this guide.

Setting Up Copilot for Code Reviews

  1. Enable Copilot for Pull Requests: I followed the steps in the GitHub documentation to configure Copilot for automatic code reviews.
  2. Create a Pull Request: Once my function app was ready, I created a Pull Request to merge the changes into the main branch.
  3. Add Copilot as reviewer: Copilot was added as a reviewer to the Pull Request.

Copilot as reviewer

The process

While I have played around much more with GitHub Copilot as a reviewer here I have described some steps in the process to get an idea how my journey was with requesting a review from Copilot:

  1. Initial review: In my initial implementation I have used an Azure function called HttpExample. This is where Copilot made a suggestion in the first round on my Pull Request to use another name. As shown in the images the Copilot couldn't review everything, because some files are not supported. However, it was able to give feedback on my C# code.

Request a review from Copilot

First review from Copilot

Code suggestion from Copilot

  1. Revised feedback: I addressed the initial comments from Copilot and renamed the function and decided to change a timer trigger to an http trigger function. Then I made a new commit. When I re-requested a review (since it won't trigger a new review automatically) it was able to detect that a logger function still contained a word trigger. Also, I noticed that the time to review was very short which is very nice.

Re-request a review from Copilot

Re-request a review from Copilot

Re-request a review from Copilot

  1. Inconsistent feedback: In this step I re-requested a review from Copilot again without making any code changes to see if I will get more feedback. I was surprised that the new feedback was more useful than the previous one and I was expecting to receive both suggestions without re-requesting a review.

The code suggestion was that I could make the error handling more consistent with a better error message and http status code when something goes wrong.

Re-request a review from Copilot

The process part 2

In a second pull request I introduced an interface and service to organize my project a little bit more. The fun part was that when I requested a review from Copilot there were no comments added, however it provided me with a brief summary of my changes and also explained each changed file in a table format for which Copilot executed a review.

Link to latest pull request

My experience with GitHub Copilot as a reviewer

Pro

  • Quick and contextual feedback: Copilot provided feedback almost instantly after I created the Pull Request and requested a review. It suggested improvements, and even recommended better practices for Azure Functions and .NET.
  • Helpful suggestions: For example, Copilot pointed out areas where I could improve error handling and logging. It also made suggestions about naming, like preventing the word example in the function name.

Con

  • Inconsistent feedback: When I asked Copilot for feedback multiple times without making any code changes, I received different recommendations each time. While this was interesting, I expected Copilot to consolidate its thoughts and provide more comprehensive feedback in one go.
  • Limited depth: Some feedback was surface-level, and I had hoped for deeper insights into architectural decisions or potential scalability issues. In my experience this could help me or my team to write better code.

Lessons learned

  • Copilot is a good assistant to start with: GitHub Copilot as a reviewer is a nice addition to the GitHub Copilot in the editor (e.g. Visual Studio Code) for catching common issues and suggesting improvements.
  • Room for improvement: Copilot as a reviewer could be more powerful when providing more comprehensive feedback in a single pass and being more consistent across multiple review requests.

Conclusion

Using Github Copilot as a reviewer is an interesting feature and it is a nice addition to the GitHub Copilot in the editor. It can save you time to discover issues in the code and improve them. However, GitHub Copilot as a reviewer in its current form still has a lot of room for improvement. The biggest gain can be achieved when Copilot also gives more explanation why it thinks the improvement is necessary. This is also more valuable for other colleagues if they understand why Copilot gives certain feedback. However, I am curious how this will develop over time and look forward to seeing if these kinds of features can improve code quality.