...
To achieve this, create custom prompts with the Title or Description usage, and be sure to set them as the default for PR title and description suggestions in the repo repository admin settings panel (e.g. here we created custom prompt templates generate-title
and generate-description
):
...
Expand | ||
---|---|---|
| ||
|
Guide for a reviewer
While PR title and description suggestion is useful for the contributor opening the PR, we can create a useful tool for reviewers to familiarise themselves with potential problems. In this example, we created a prompt template generate-review
with the Chat usage, which can be invoked in a conversation with AIRA from the pull request overview.
...
Expand | ||
---|---|---|
| ||
|
Using Custom Chat Prompt Templates
...
If you create a custom prompt template for Chat. You can use it talk to AIRA by starting the comment with /aira <template-slug>
, this can be automatically inserted by choosing a prompt template from the list when you click on the AI Prompt
button in the comment editor.
Guide for a reviewer
While PR title and description suggestion is useful for the contributor opening the PR, we can create a useful tool for reviewers to familiarise themselves with potential problems. In this example, we created a prompt template generate-review
with the Chat usage, which can be invoked in a conversation with AIRA from the pull request overview.
...
Expand | ||
---|---|---|
| ||
|
In the above prompt we use a few prompt template variables. As the output focuses on code quality, we selected to use <diff>
and <commits>
to be able to ask relevant questions. We avoid using <title>
and <description>
to eliminate potential interference with false claims from the contributor about their PR.
Identify potential problems
In the following example we ask AIRA from the pull request overview to identify issues in the code, before a reviewer begins to take a look. Thanks to the identify-problems
custom prompt template, we get precise output, pinpointing the location in the code to look at.
...
In the above snippet, we followed the same # ROLE
section as for generating a reviewer guide, only adjusting the # WORKFLOW
. Here is the diff of the PR for comparison:
...
Generate test cases
If a reviewers identifies suspicious or untested code in the pull request, they could use another Chat prompt template to generate test cases for a given snippet in the diff, for example here is displayed a user instructing AIRA to use the generate-tests
custom prompt template:
...
In the above snippet from the prompt template, we use a few more prompt template variables. Importantly, as we are expecting the prompt to be applied directly to the diff, we use the anchor variables <anchor-line-number>
, <anchor-line>
, <anchor-path>
, and <anchor-file>
. These specifically pinpoint the code that user has commented on to provide useful context.
Suggest code improvements
At a glance a reviewer may spot code that needs improving. Here the repo admin created a suggest-improvements
custom Chat prompt template, with a workflow that rewrites the code that the comment is attached to:
...
The above snippet reuses the same # ROLE
section as for generating test cases, only the # WORKFLOW
changes.
Generate code documentation
You can create a custom prompt template with the Chat usage with a workflow to add documentation comments to a given unit of code. For example here using the generate-documentation
custom prompt:
...
Expand | ||
---|---|---|
| ||
|
...
|
The above snippet reuses the same # ROLE
section as for generating test cases, only the # WORKFLOW
changes.
Ask general questions with the default chat prompt template
...
Reviewers can also chat without selecting any prompt-template, in which case the default one configured for the repository is used. In this case you can still set a custom prompt template as the default in the repository admin settings panel. In this case the prompt should really only provide the expected role and knowledge of the AI Review assistant, and let the chat drive the workflow.
...
1. Ask about facts
AI Review Assistant will be good at scanning your pull requests for particular facts that a human can easily double-check. The following questions can be applied automatically to any pull request.
/aira Make a list of all files and line numbers where there is a password in plain-text in this Pull Request
/aira Make a list of all files and line numbers where PII information might leak from the code in this Pull Request
/aira Make a list of any inconsistencies between inline comments in the code, and the implementation, or the description of this Pull Request?
2. Ask about help understanding the pull request
AI Review Assistant can also help the reviewers to understand a particular piece of code that was changed. The following questions can be applied by a human directly on the source code file
/aira Please write the steps of the algorithm implementing this function <name of the function>
/aira Please list the places where this new class <name of the class> is used in this pull request
3. Ask about generating new content
AI Review Assistant can also generate code related to the pull request, which can then be added to it.
/aira Please write another test case that is relevant to the implementation of this function <name of the function>
/aira Please write a docstring (Java style) explaining the purpose of this function <name of the function>
Extra assistance
Prompt template variables
...