GitLab Duo use cases | GitLab Docs
/ GitLab Duo use cases The following use cases provide practical examples, exercises, and workflows with GitLab Duo. Learn how to: Refactor existing source code. Use GitLab Duo Root Cause Analysis to troubleshoot failed jobs. Solve security vulnerabilities. If you have GitLab Self-Managed: GitLab Duo requires GitLab 17.2 and later for the best user experience and results. Earlier versions might continue to work. However, the experience may be degraded.
Use GitLab Duo to solve development challenges Start with a C# application In these examples, open your C# IDE, ensure that GitLab Duo is enabled , and explore how to use GitLab Duo AI-native features for more efficiency. CLI tool for querying the GitLab REST API Watch the GitLab Duo Coffee Chat: Get started with C# The challenge is to create a CLI tool for querying the GitLab REST API. Ask GitLab Duo Chat how to start a new C# project and learn how to use the dotNET CLI: markdown How can I get started creating an empty C# console application in VS Code?
Use Code Suggestions to generate a REST API client with a new code comment: c# // Connect to a REST API and print the response The generated source code might need an explanation. Use the code task /explain to get insight into how the REST API calls work. After the source code is generated from a Code Suggestions comment, you need to configure CI/CD. Chat can help with best practices for a .gitignore file for C#: markdown Show a .gitignore and .gitlab-ci.yml configuration for a C# project.
If your CI/CD job fails, use Root Cause Analysis to troubleshoot failed CI/CD jobs . Alternatively, you can copy the error message into GitLab Duo Chat, and ask for help: markdown Explain the CI/CD error: The current .NET SDK does not support targeting .NET 8.0 To create tests later, ask GitLab Duo to use the code task /refactor to refactor the selected code into a function. Chat can also explain programming language specific keywords and functions, or C# compiler errors. markdown Can you explain async and await in C# with practical examples? explain error CS0122: 'Program' is inaccessible due to its protection level Generate tests by using the /tests code task.
The next question is where to put the generated tests in C# solutions. As a beginner, you might not know that the application and test projects must exist on the same solutions level to avoid import problems. GitLab Duo Chat can help by asking and refining the prompt questions: markdown In C# and VS Code, how can I add a reference to a project from a test project? Provide the XML configuration which I can add to a C# .csproj file to add a reference to another project in the existing solution?
Sometimes, you must refine the prompt to get better results. The prompt /refactor into the public class creates a proposal for code that can be accessed from the test project later. markdown /refactor into the public class You can also use the /refactor code task to ask Chat how to execute tests in the .gitlab-ci.yml file. markdown /refactor add a job to run tests (the test project) Resources: Project with source code Improve a C++ application Refactor a C++ application with SQLite In this example, existing source code with a single main function exists.
It repeats code, and cannot be tested. Watch the GitLab Duo Coffee Chat: C++, SQLite and CMake To refactor the source code into reusable and testable functions: Open VS Code or the Web IDE with GitLab Duo enabled. Select the source code, and use a refined prompt to ask GitLab Duo Chat to refactor it into functions: markdown /refactor into functions This refactoring step might not work for the entire selected source code.
Split the refactoring strategy into functional blocks. For example, iterate on all insert, update, and delete operations in the database. To generate tests for the newly created functions, select the source code again and use the code task /tests . Include a specific prompt of instructions for the test framework: markdown /tests using the CTest test framework If your application uses the Boost.Test framework instead, refine the prompt: markdown /tests using the Boost.Test framework Resources: Project with source code Refactor C++ functions into object-oriented code In this example, existing source code has been wrapped into functions.
To support more database types in the future, the code must be refactored into classes and object inheritance. Watch the walkthrough of these steps in GitLab Duo Coffee Chat: Refactor C++ functions into OOP classes Start working on the class Ask GitLab Duo Chat how to implement an object-oriented pattern for a base database class and inherit it in a SQLite class: markdown Explain a generic database implementation using a base class, and SQLite specific class using C++.
Provide source examples and steps to follow. The learning curve includes asking GitLab Duo Chat about pure virtual functions and virtual function overrides in the implementation class. markdown What is a pure virtual function, and what is required for the developer inheriting from that class? Code tasks can help refactoring the code. Select the functions in the C++ header file, and use a refined prompt: markdown /refactor into class with public functions, and private path/db attributes.
Inherit from the base class DB /refactor into a base class with pure virtual functions called DB. Remove the SQLite specific parts. GitLab Duo Chat also guides with constructor overloading, object initialization, and optimized memory management with shared pointers. markdown How to add a function implementation to a class in a cpp file? How to pass values to class attributes through the class constructor call? Find better answers The following question did not provide enough context. markdown Should I use virtual override instead of just override?
Instead, try to add more context to get better answers. markdown When implementing a pure virtual function in an inherited class, should I use virtual function override, or just function override? Context is C++. A relatively complex question involves how to instantiate an object from the newly created class, and call specific functions. markdown How to instantiate an object from a class in C++, call the constructor with the SQLite DB path and call the functions.
Prefer pointers. The result can be helpful, but needed refinements for shared pointers and required source code headers. markdown How to instantiate an object from a class in C++, call the constructor with the SQLite DB path and call the functions. Prefer shared pointers. Explain which header includes are necessary. Code Suggestions helps generate the correct syntax for std::shared_ptr pointer arithmetic and help improve the code quality. c++ // Define the SQLite path in a variable, default value database.db // Create a shared pointer for the SQLite class // Open a database connection using OpenConnection Refactor your code After refactoring the source code, compiler errors may occur.
Ask Chat to explain them. markdown Explain the error: `db` is a private member of `SQLiteDB` A specific SQL query string should be refactored into a multi-line string for more efficient editing. c++ std :: string sql = "CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL, email TEXT NOT NULL)" ; Select the source code, and use the /refactor code task: markdown /refactor into a stringstream with multiple lines You can also refactor utility functions into a class with static functions in C++ and then ask Chat how to call them. markdown /refactor into a class providing static functions How to call the static functions in the class?
After refactoring the source code, the foundation for more database types is built, and overall code quality improved. Resources: Project with source code Explain, test, and refactor a Kotlin application In this example, the adventure application from the Kotlin code generation prompts must be analyzed, and improved with refactor
The rest of this page is on the live site.