Skip to content

Commit

Permalink
Merge pull request #1 from emanuel-braz/gpt-release-body
Browse files Browse the repository at this point in the history
feat: add enhanced release notes feature
  • Loading branch information
emanuel-braz authored Sep 27, 2023
2 parents a5c548e + 53b22c3 commit d39c53f
Show file tree
Hide file tree
Showing 20 changed files with 803 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/create_update_release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v4
- name: Release Action
uses: ./create_update_release
uses: ./create-update-release
with:
name: ${{ github.event.inputs.name }}
body: ${{ github.event.inputs.body }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/delete_release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v4
- name: Delete Release Action
uses: ./delete_release
uses: ./delete-release
with:
tag: ${{ github.event.inputs.tag }}
use_latest_pre_release: ${{ github.event.inputs.use_latest_pre_release }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/example_github_uses.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Create release
uses: emanuel-braz/github-actions/create_update_release@0.0.1
uses: emanuel-braz/github-actions/create-update-release@0.0.7
with:
token: ${{ secrets.GITHUB_TOKEN }}
name: "Release ${{inputs.build-name}}+${{inputs.build-number}}"
Expand Down
30 changes: 30 additions & 0 deletions .github/workflows/release_notes.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Generate Enhanced Release Notes
run-name: Action started by ${{ github.actor }}

on:
workflow_dispatch:
inputs:
tagName:
description: 'Tag of the release.'
required: true
type: string

jobs:
print_enhanced_release_notes:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Generate Release Notes
id: release_notes
uses: ./generate-enhanced-notes
with:
token: "${{ secrets.GITHUB_TOKEN }}"
tag_name: ${{ github.event.inputs.tagName }}
openai_key: "${{ secrets.OPENAI_KEY }}"
use_previous_tag_latest_release: true
verbose: true

- name: Print Release Notes (Use it as you want)
run: echo "${{ steps.release_notes.outputs.enhanced_notes }}"
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
node_modules
.vscode/settings.json
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@

#### - [Delete a release](delete_release/README.md)

#### - [Generate enhanced release notes](generate-enhanced-notes/README.md)

#### Soon more actions will be added to have a complete Gitflow utilities.:
- [ ] Manage PR
- [ ] Manage Issue
- [ ] Manage Branchs
- [ ] Create entire Gitflow
- [ ] Add sample code


<br/>
<a href="https://www.buymeacoffee.com/emanuelbraz" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Buy Me A Coffee" style="height: 50px !important;width: 217px !important;" ></a>
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
59 changes: 59 additions & 0 deletions generate-enhanced-notes/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
### Generate Enhanced Notes
First create a secret in your repository called `OPENAI_KEY` with your OpenAI API key.
https://platform.openai.com/account/api-keys

Then create a workflow file (e.g. `.github/workflows/release_notes.yml`) with the following content:

```yaml
name: Generate Enhanced Release Notes
run-name: Action started by ${{ github.actor }}

on:
workflow_dispatch:
inputs:
tagName:
description: 'Tag of the release.'
required: true
type: string

jobs:
print_enhanced_release_notes:
runs-on: ubuntu-latest
steps:
- name: Generate Release Notes
id: release_notes
uses: ./generate-enhanced-notes
with:
token: ${{ secrets.GITHUB_TOKEN }}
tag_name: ${{ github.event.inputs.tagName }}
openai_key: ${{ secrets.OPENAI_KEY }}
use_previous_tag_latest_release: true
verbose: true

- name: Print Release Notes (Use it as you want)
run: echo "${{ steps.release_notes.outputs.enhanced_notes }}"
```
### Inputs (FILTERS)
#### tag_name
**Required** The name of the tag.
#### token
**Required** The token to use to create the release. Use `"${{ secrets.GITHUB_TOKEN }}"`.
#### openai_key
**Required** The key to use to generate the release notes. Use `"${{ secrets.OPENAI_KEY }}"`.
#### previous_tag_name
**Optional** The name of the previous tag. if "usePreviousTagLatestRelease" is true, this is ignored.
#### use_previous_tag_latest_release
**Optional** Whether to use the latest release of the previous tag to generate the release notes. Default `false`.

#### verbose
**Optional** Whether to print verbose output. Default `false`.

## TODO
- [ ] Add support for multiple languages
- [ ] Add support for multiple models
5 changes: 5 additions & 0 deletions generate-enhanced-notes/action.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const GenerateEnhancedNotes = require('./generate_enhanced_notes.js');

(async () => {
await new GenerateEnhancedNotes().call();
})();
33 changes: 33 additions & 0 deletions generate-enhanced-notes/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: emanuel-braz/generate-enhanced-notes
description: Generate release notes using OpenAI's GPT-3.5-turbo
author: Emanuel Braz
branding:
icon: send
color: gray-dark
inputs:
tag_name:
description: The name of the tag of the release.
required: true
token:
description: The token to use to create the release. Use `"${{ secrets.GITHUB_TOKEN }}"`.
required: true
openai_key:
description: The key to use to generate the release notes. Use `"${{ secrets.OPENAI_KEY }}"`.
required: true
previous_tag_name:
description: The name of the previous tag. if "usePreviousTagLatestRelease" is true, this is ignored.
required: false
use_previous_tag_latest_release:
description: Whether to use the latest release of the previous tag to generate the release notes. Default `false`.
required: false
verbose:
description: Whether to print verbose output. Default `false`.
required: false

outputs:
enhanced_notes:
description: The generated release notes.

runs:
using: node16
main: ./action.js
50 changes: 50 additions & 0 deletions generate-enhanced-notes/generate_enhanced_notes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
require('child_process')
.execSync(
'npm install @actions/core @actions/github',
{ cwd: __dirname }
);

const core = require('@actions/core');
const github = require('@actions/github');
const { Logger } = require('../utils/logger.js');

const GitHubService = require('../services/github_service.js');
const GptService = require('../services/gpt_service.js');

class GenerateEnhancedNotes {

async call({ tagName, previousTagName, token, openaiKey, usePreviousTagLatestRelease, owner, repo, verbose }) {

tagName = tagName || core.getInput('tag_name');
previousTagName = previousTagName || core.getInput('previous_tag_name');
token = token || core.getInput('token');
openaiKey = openaiKey || core.getInput('openai_key');
usePreviousTagLatestRelease = usePreviousTagLatestRelease || core.getInput('use_previous_tag_latest_release') == 'true';
verbose = verbose || core.getInput('verbose') == 'true';
owner = owner || github.context.repo.owner
repo = repo || github.context.repo.repo

const api = github.getOctokit(core.getInput('token'));
const logger = new Logger(verbose, core);

if (usePreviousTagLatestRelease) {
var latestRelease = await api.repos.getLatestRelease({
...github.context.repo
});
previousTagName = latestRelease.data.tag_name;
}

const githubService = new GitHubService(token, owner, repo);
var releasenotes = await githubService.generateReleaseNotes(tagName, previousTagName);
logger.log(`RELEASE NOTES:\n\n${releasenotes}`);

const gptService = new GptService(openaiKey);
var enhancedNotes = await gptService.generateReleaseNotes(releasenotes);
logger.log(`ENHANCED RELEASE NOTES:\n\n${enhancedNotes}`);

core.setOutput('enhanced_notes', enhancedNotes);
return enhancedNotes;
}
}

module.exports = GenerateEnhancedNotes;
Loading

0 comments on commit d39c53f

Please sign in to comment.