DevSecOps with GitLab Duo - Hands-On Lab: Working with Issues and Merge Requests
Estimated time to complete: 30 minutes
Objectives
GitLab Duo extends beyond just code generation. GitLab Duo can support you through any stage of the DevSecOps lifecycle! In this lab, you will see how GitLab Duo can work with issues and merge requests inside of a project.
Task A. Creating an Issue with GitLab Duo
-
Navigate to your GitLab Duo Principles Project.
-
In your project, from the left sidebar, select Plan > Issues.
-
Select New issue.
-
For the Title, input
Update hello world visuals
. -
If your editor is in rich text editing mode, Select
Switch to plain text editing
at the bottom of the issue description.The AI generation feature for issue descriptions will only display in plain text editing mode. If you do not see the Tanuki button, you are likely in rich text editing mode.
-
In the Description box, select the Tanuki button, then select Generate issue description.
-
In the issue description generation box, type the prompt:
We want to make our "hello world" application more visually appealing for the end user. We want to incorporate the Go Figure module into our application to print out more exciting text.
The response will look similar to the following:
Issue: The "hello world" application lacks visual appeal The current "hello world" application prints basic text without any formatting or visual elements. We want to enhance the user experience and make the application output more interesting to look at. The Go Figure module allows printing text in different styles and formats. Integrating this module into our "hello world" code will let us customize how the message is displayed, such as changing fonts, colors, effects and more. This will make our application stand out more and be more enjoyable for end users to interact with. *** _Description was generated using AI_
-
Assign the issue to yourself and select Create issue.
Task B. Creating a Merge Request
-
From the issue you just created, select Create merge request.
-
Select the Tanuki icon, then select Fill in merge request template.
-
Select Apply AI-generated description.
GitLab Duo can also provide a summary of code changes in an MR. We will return to this feature later in the course.
-
Leave all other options as default and select Create merge request.
Task C. Add Code to Your MR
-
In your MR, select Code > Open in Web IDE.
-
Select the Tanuki icon from the left sidebar.
-
In the chat, write the prompt:
How could I use the go-figure module of go-to print hello world in a different font?
You will get a response similar to this:
package main import ( "github.com/common-nighthawk/go-figure" ) func main() { myFigure := figure.NewFigure("hello world", "", true) myFigure.Print() }
-
Select the repository icon from the left sidebar.
-
Select
main.go
. -
Replace the contents of
main.go
with the AI generated code. -
Select Source Control from the left sidebar.
-
Select the Commit button to commit the code changes.
-
Select Go to MR to return back to your merge request.
Task D. Summarizing your Code Changes
-
On your merge request, select Edit.
-
Just above the Description input, select Summarize code changes.
-
Select Save changes.
-
Note that at the bottom of the MR description, there is now an outline of the changes included in the MR.
Task E. Root Cause Analysis
Uh-oh! You may have noticed that our pipeline failed.
-
From the MR, click on the most recent pipeline run that failed.
-
Click on the job that failed.
-
At the top of the output of the job click the button that says Root cause analysis.
-
Select Generate root cause analysis.
-
This will generate an explanation on why the job failed an example fix. It will say something along the lines of a missing module. Try to implement the suggested fix in your
.gitlab-ci.yml
file by adding an additionalgo
command in thebuild app
job. -
Return to your merge request.
-
Select Code > Open in Web IDE.
-
Open your
.gitlab-ci.yml
file. -
In the
script
section of yourbuild app
job, add the script to pull thego-figure
dependency.Your configuration file should look like the file below:
stages: - build default: image: golang:latest build app: stage: build script: - go get github.com/common-nighthawk/go-figure - go run main.go
This will fix the pipeline and in the output you should see a fun version of hello world printed in the job log!
-
Select Source Control from the left sidebar.
-
Select the Commit button to commit the code changes.
-
Select Go to MR to return back to your merge request.
-
Select Merge to merge your code updates into the main branch.
Lab Guide Complete
You have completed this lab exercise. You can view the other lab guides for this course.
Suggestions?
If you’d like to suggest changes to the lab, please submit them via merge request.
46417d02
)