# Issue Reviewer

> Learn how to automate reviewing issues with a script.

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

## Resolving the issue

[Section titled “Resolving the issue”](#resolving-the-issue)

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

issue-reviewer.genai.mjs

```js
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

```yaml
jobs:
  review:
    - run: ...
      env:
        GITHUB_ISSUE: ${{ github.event.issue.number }}
```

## The task

[Section titled “The task”](#the-task)

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

issue-reviewer.genai.mts

```js
$`## 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

[Section titled “The context”](#the-context)

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

issue-reviewer.genai.mts

```js
def("TITLE", title)
def("BODY", body)
```

## Automation in Github Actions

[Section titled “Automation in Github Actions”](#automation-in-github-actions)

Add this step to your Github Actions workflow to automate the issue review process. The `--pull-request-comment` flag stands for [—pull-request-comment](/genaiscript/reference/cli/run#pull-requests) and takes care of up-serting a comment in the pull request/issue conversation.

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

## Full source

[Section titled “Full source”](#full-source)

issue-reviewer.genai.mjs

```js
script({
  title: "Issue Reviewer",
  description: "Review issues and provide feedback",
  responseType: "markdown",
  systemSafety: true,
  parameters: {
    issue: {
      type: "integer",
      description: "The issue number to answer.",
      required: false,
    },
  },
});


const { title, body } = await github.getIssue(env.vars.issue);


def("TITLE", title);
def("BODY", body);


$`## Role
You are an expert developer at TypeScript and GenAIScript (https://github.com/microsoft/genaiscript) and have been asked to review an issue.


## Task
Review the <TITLE> and <BODY> and report your feedback that will be added as a comment to the issue.
- Check that has enough details to help the developer. Ask clarifying questions if needed.
- do not suggest code changes or guidance. Only provide feedback on the issue itself.
`;
```