Skip to content

Issue Reviewer

This guide shows how to automate reviewing issues with a GenAIScript that provides feedback and code analysis in GitHub Actions.

Resolving the issue

The script starts by getting the current issue information from the GitHub API.

issue-reviewer.genai.mjs
const { title, body } = await github.getIssue()

The github.getIssue assumes that GenAIScript is running in a GitHub Action, it will have access to the github token (GITHUB_TOKEN) and the GITHUB_ISSUE issue id.

The GITHUB_ISSUE needs to be configured in the GitHub Action from the github.event.issue object.

github-action.yml
jobs:
review:
- run: ...
env:
GITHUB_ISSUE: ${{ github.event.issue.number }}

The task

The prompt sets the task and how to perform the review in a system message.

issue-reviewer.genai.mts
$`## Tasks
You are an expert developer and have been asked to review an issue.
Review the TITLE and BODY and report your feedback that will be added as a comment to the issue.
`.role("system")

The context

Then it adds the issue title and body to the prompt.

issue-reviewer.genai.mts
def("TITLE", title)
def("BODY", body)

Automation in Github Actions

Add this step to your Github Actions workflow to automate the issue review process. The -prc flag stands for —pull-request-comment and takes care of upserting a comment in the pull request/issue conversation.

permissions:
content: read # permission to read the repository
issues: write # permission to write a comment
...
- run: npx --yes genaiscript run issue-reviewer -prc --out-trace $GITHUB_STEP_SUMMARY
env:
GITHUB_ISSUE: ${{ github.event.issue.number }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
... # LLM secrets

Full source

issue-reviewer.genai.mjs
script({
title: "Issue Reviewer",
description: "Review issues and provide feedback",
})
const { title, body } = await github.getIssue()
$`## Tasks
You are an expert developer and have been asked to review an issue.
Review the TITLE and BODY and report your feedback that will be added as a comment to the issue.
`.role("system")
def("TITLE", title)
def("BODY", body)