Skip to content

Commit

Permalink
feat: add release_notes outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
emanuel-braz committed Sep 27, 2023
1 parent 9261c0e commit d83860f
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 22 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/release_notes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ jobs:

outputs:
enhanced_notes: ${{ steps.release_notes.outputs.enhanced_notes }}
release_notes: ${{ steps.release_notes.outputs.release_notes }}

steps:
- uses: actions/checkout@v4
Expand All @@ -41,4 +42,8 @@ jobs:
needs: enhanced_release_notes
steps:
- name: Print Release Notes (Use it as you want)
run: echo "${{ needs.enhanced_release_notes.outputs.enhanced_notes }}"
run: |
echo "---"
echo "${{ needs.enhanced_release_notes.outputs.release_notes }}"
echo "---"
echo "${{ needs.enhanced_release_notes.outputs.enhanced_notes }}"
18 changes: 16 additions & 2 deletions generate-enhanced-notes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,13 @@ jobs:
verbose: true

- name: Print Release Notes (Use it as you want)
run: echo "${{ steps.release_notes.outputs.enhanced_notes }}"
run: |
echo "${{ steps.release_notes.outputs.release_notes }}"
echo "---"
echo "${{ steps.release_notes.outputs.enhanced_notes }}"
```
### Inputs (FILTERS)
### Inputs
#### tag_name
**Required** The name of the tag.
Expand All @@ -55,6 +58,17 @@ jobs:
#### verbose
**Optional** Whether to print verbose output. Default `false`.

---
### Outputs

#### enhanced_notes
The enhanced release notes.

#### release_notes
The original release notes.



## TODO
- [ ] Add support for multiple languages
- [ ] Add support for multiple models
2 changes: 2 additions & 0 deletions generate-enhanced-notes/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ inputs:
outputs:
enhanced_notes:
description: The generated release notes.
release_notes:
description: The default release notes.

runs:
using: node16
Expand Down
25 changes: 22 additions & 3 deletions generate-enhanced-notes/generate_enhanced_notes.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,21 @@ const GptService = require('../services/gpt_service.js');

class GenerateEnhancedNotes {

filterPrTitles(input) {
const lines = input.split('\n');

const filteredLines = lines.filter((line) => !/^## What's Changed|^## New Contributors|^\* @|^\*\*Full Changelog\*\*:/.test(line));

const output = filteredLines.map((line) => {
const index = line.lastIndexOf(' by @');
if (index !== -1) {
return line.substring(0, index);
}
return line;
}).filter(Boolean).join('\n');
return output.trim();
}

async call() {

var tagName = core.getInput('tag_name');
Expand All @@ -36,13 +51,17 @@ class GenerateEnhancedNotes {

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

var releaseNoteFiltered = this.filterPrTitles(releasenotes);
logger.log(`FILTERED RELEASE NOTES:\n\n${releaseNoteFiltered}`);

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

core.setOutput('enhanced_notes', enhancedNotes);

return enhancedNotes;
}
}
Expand Down
17 changes: 1 addition & 16 deletions services/github_service.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,6 @@ class GitHubService {
this.repo = repo;
}

filterPrTitles(input) {
const lines = input.split('\n');

const filteredLines = lines.filter((line) => !/^## What's Changed|^## New Contributors|^\* @|^\*\*Full Changelog\*\*:/.test(line));

const output = filteredLines.map((line) => {
const index = line.lastIndexOf(' by @');
if (index !== -1) {
return line.substring(0, index);
}
return line;
}).filter(Boolean).join('\n');
return output.trim();
}

async generateReleaseNotes(tagName, previousTagName) {
try {
const response = await axios.post(`https://api.github.com/repos/${this.owner}/${this.repo}/releases/generate-notes`,
Expand All @@ -44,7 +29,7 @@ class GitHubService {

if (response.status === 200) {
var data = response.data.body;
return this.filterPrTitles(data);
return data;
} else {
throw new Error(`Error generating release notes`);
}
Expand Down

0 comments on commit d83860f

Please sign in to comment.