AI-Powered GitHub Issue Management 🦾
Tags: githubhack23, programming, githubactions, javascript
Published: 2023-05-14 15:06:48

## What I built 

I have developed an innovative GitHub Action that enhances GitHub issues with the power of artificial intelligence. Its primary functionalities includes finding related issues, providing concise summaries of issues and all associated comments, generating progress updates, recommending suitable labels, and more.

### Category Submission: 
Maintainer Must-Haves: Make the lives of Open Source maintainers easier.

### App Link
https://github.com/marketplace/actions/clarify-and-improve-issues-with-openai-gpt

### Screenshots 

https://github.com/MaurerKrisztian/issue-improver-action-demo/issues/2

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/29u7jyosuyod2o7106uf.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3n6wjch4s7469xkwpjx6.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j3a860i6ypb71byqluij.png)




### Description 

This GitHUb Action can be triggered to gather the relevant issue data, make usefully comments/suggestions with OpenAI GPT models.

Basically, it works like this: prompts are sent to a GPT model, and its response appears as a comment on an issue. The prompt text can contain placeholders like `{{issueTitle}}`, `{{issueBody}}`, `{{allComments}}`, etc. These placeholders are replaced with the actual data from the current issue, but they can also include other information, not just limited to the issue itself.

```json
    "summary": {
      "title": "Summary",
      "prompt": "Provide a concise summary of the main points and objectives presented in the issue '{{issueTitle}}' and its content: {{issueBody}}."
    },
```

One of the key components is the "sections". Each section must have at least a title and prompt parameter. In the action workflow yml, you can specify which sections you require. During the action run, the selected sections' prompts are processed using the OpenAI GPT model. The prompts have default values (refer to src/config/default-config.ts), but you can completely customize them and create your own sections. The generated responses will be added as comments to the issue.


#### Built in sections and inputs:


| Input                      | Required | Default                    | Info                                                                   |
|----------------------------|----------|----------------------------|------------------------------------------------------------------------|
| openai-key                   | Yes      | N/A                        | OpenAI API key                                                         |
| config-file                | No       | issue-improver-config.json | Configuration file                                                     |
| add-related-issues-section | No       | false                      | Create a related issues section.                                       |
| add-summary-section        | No       | false                       | Create a summary section.                                              |
| add-comment-summary-section        | No       |    false                      | Create comment summary                                                 |
| add-custom-section         | No       |    N/A                        | custom section title/id comma separated string. "*" means include all. |
| add-label-section          | No       |  false                        | Create label suggesion                                                 |
| model                      | No       | 'text-davinci-003'         | OpenAI model                                                           |
| max-tokens                 | No       | 150                        | OpenAI max_tokens (response length)                                    |
| debug-mode                | No       | false                      | Enable debug mode: Don't create comment                                |

- related-issues-section
Find related issues among open issues. Some issues are duplicates, while others are related to each other. These details are useful to the maintainer.

- label-section
The action will analyze the issue and all available labels, descriptions, and data to suggest relevant labels.

- summary-section
Summarize the issue text.

- custom-section
In the configuration file, specifically under the `sections.custom` section, you have the ability to create custom sections with your own prompts.

- comment-summary-section
Summarize all comment at the current issue, make progress report etc. Occasionally, certain GitHub issues can be overwhelming with an abundance of comments, making it difficult to comprehend the situation. To address this, I have developed a comment summary feature.


#### debug mode
If you turn on debug mode, it will do the following: resolve prompts, give you more detailed logs of what's happening, and not create comment.. To enable this, set the `debug-mode` input to `true`.

If you want to test the action without making comments to any issues, it's useful to turn on debug mode. This will allow you to view the logs and see what comment would be created if debug mode was turned off. Once you're satisfied with the results, you can turn off debug mode.

#### Action example:
This action will trigger when new issue is opened,
and creates a comment including: related-issues-section, summary-section, label-section, custom-section

```yml
name: Improve issues

on:
  issues:
    types: [opened]

jobs:
  gpt-comment:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Create useful comment with AI
        uses: MaurerKrisztian/issue-improver-action@v1
        with:
          openai-key: ${{ secrets.GPT_KEY }}
          max-tokens: 400
          add-related-issues-section: true
          add-summary-section: true
          add-label-section: true
          add-custom-section: "my_custom_section1,my_custom_section2"
```

#### Comment Summary
The YAML code below demonstrates how to activate comment summary, progress report, using the "!summarize" command.

```yml
on:
  issue_comment:

jobs:
  comment-summary:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Comment summary
        uses: MaurerKrisztian/issue-improver-action@v1
        if: contains(github.event.comment.body, '!summarize')
        with:
          openai-key: ${{ secrets.GPT_KEY }}
          max-tokens: 400
          add-comment-summary-section: true
```

#### Custom section:
All section prompts is fully customisable.
To create custom sections / prompts, simply create a JSON file (location is the `config-file` input) and modify the prompts and section titles as desired. This will owerwite the default config (see: `src/config/default-config.ts`). 

Additionally, you can add new custom sections to the `sections.custom` array within the configuration file.

#### Example config:
```json
{
  "sections": {
    "custom": [
      {
        "title": "Joke",
        "prompt": "Make a joke about this: {{issueTitle}}"
      },
      {
        "title": "Poem",
        "prompt": "Write a short poem about this: {{issueTitle}}"
      }
    ],
    "relatedIssues": {
      "title": "Related Issues",
      "prompt": "From the list of open issues: {{openIssues}}, identify the most relevant ones related to '{{issueTitle}}' and provide a brief description of their similarities. Just the very simmilar related issues to '{{issueTitle}}' shoud be included in the answer, if none is very similar, andwer with 'none',"
    },
    "summary": {
      "title": "Summary",
      "prompt": "Provide a concise summary of the main points and objectives presented in the issue '{{issueTitle}}' and its content: {{issueBody}}."
    },
    "commentSummary": {
      "title": "Comment summary",
      "prompt": "Review the comments in {{issueComments}} for the issue '{{issueTitle}}' and its content: {{issueBody}}. Extract the key takeaways, notable updates, and any consensus reached, and provide a concise summary of the discussion."
    },
    "labelSuggestion": {
      "title": "Label Suggestion",
      "prompt": "Analyze the issue '{{issueTitle}}' and its content: {{issueBody}}, and suggest appropriate labels from the available labels {{allLabels}} that accurately represent the topic, scope, and complexity of the issue. The response shoud only include a label and why its suitable."
    }
  }
}
```

#### Available placeholders:

| Name           | Description                            | 
|----------------|----------------------------------------|
| `{{issueTitle}}` | The issue title                        | 
| `{{issueBody}}`           | The issue body                         |
| `{{issueComments}}`         | All issue comment                      |
| `{{issueAuthor}}`           | Issue creator                          |
| `{{allLabels}}`           | All available labels in the repository |
| `{{openIssues}}`           | All open issues in the repository      |

To optimize the usage of GitHub Action time, the resolution of placeholders is cached and only resolved when necessary. This helps to avoid unnecessary wastage of valuable GitHub Action resources.

If you need a different placeholder, open an issue or send a PR.

I have set up a demo repository with the configured action. Feel free to explore and try it out by visiting the following link: https://github.com/MaurerKrisztian/issue-improver-action-demo

### Link to Source Code 
https://github.com/MaurerKrisztian/issue-improver-action

### Permissive License 
MIT

## Background (What made you decide to build this particular app? What inspired you?) 
My inspiration for creating this specific application stemmed from a curiosity about the ways in which AI can assist us in tasks and simplifying processes. I wanted to explore the potential of artificial intelligence in improving productivity and efficiency.

I have noticed that many open-source projects have few maintainers and a lot of issues. Some issues are duplicates, while others are related to each other, some have a lot of comments and hard to keep up with it. These details are useful to the maintainer. With the assistance of AI, this action will try to solve thies.

### How I built it (How did you utilize GitHub Actions or GitHub Codespaces? Did you learn something new along the way? Pick up a new skill?)

This is my first custom GitHub Action, I learned a lot about how it works. I found GitHub Actions to be a very helpful tool for automating many tasks. My project used both the GitHub API and OpenAI API.

Testing a custom GitHub Action can be tough. Unlike regular code, it needs certain things to happen on GitHub to work correctly. This makes it harder to check if everything is working fine, especially when you can only rely on logs within GitHub for debugging. Thankfully, I discovered a tool named [act](https://github.com/nektos/act) after some struggles. This tool lets you run your GitHub Actions locally, which makes testing a lot easier and faster. It's a real game-changer for developing GitHub Actions.

I also used GitHub Actions in my project repository to build the TypeScript code and push it to the "latest" branch. Because I didn't want to keep node_modules and dist in the main branch. I also made a release and test workflow.

The development process was filled with learning and challenges. It gave me a deeper understanding of GitHub Actions, AI, and their potential in improving productivity and efficiency.

### Additional Resources/Info
I received valuable improvement suggestions from [Kris](https://github.com/kostecky), Thank you!

**Future Plans:**

- Add more placeholders
- Add support for more OpenAI models
- Add support for lengthy context by splitting it into multiple chunks
- Experiment with other use cases to expand the range of applications
- Continuously improve prompts to enhance user experience