-
Notifications
You must be signed in to change notification settings - Fork 204
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AI Release Notes #2362
Open
hipstersmoothie
wants to merge
4
commits into
main
Choose a base branch
from
gpt
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
AI Release Notes #2362
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,11 +48,13 @@ jobs: | |
- uses: actions/checkout@v3 | ||
- uses: ./.github/actions/install-deps | ||
- uses: ./.github/actions/build-cache | ||
- uses: 8BitJonny/[email protected] | ||
id: PR | ||
- name: Get PR number | ||
uses: jwalton/gh-find-current-pr@v1 | ||
id: find-pr | ||
- run: yarn auto pr-check --pr $PR --url "$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" | ||
env: | ||
PR: ${{ steps.PR.outputs.number }} | ||
PR: ${{ steps.find-pr.outputs.pr || github.event.number }} | ||
PROTECTED_BRANCH_REVIEWER_TOKEN: ${{ secrets.GH_TOKEN }} | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Ai-Release-Notes Plugin | ||
|
||
|
||
|
||
## Installation | ||
|
||
This plugin is not included with the `auto` CLI installed via NPM. To install: | ||
|
||
```bash | ||
npm i --save-dev @auto-it/ai-release-notes | ||
# or | ||
yarn add -D @auto-it/ai-release-notes | ||
``` | ||
|
||
## Usage | ||
|
||
```json | ||
{ | ||
"plugins": [ | ||
"ai-release-notes" | ||
// other plugins | ||
] | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import Auto from '@auto-it/core'; | ||
import AiReleaseNotes from '../src'; | ||
|
||
describe('Ai-Release-Notes Plugin', () => { | ||
test('should do something', async () => { | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
{ | ||
"name": "@auto-it/ai-release-notes", | ||
"version": "10.46.0", | ||
"main": "dist/index.js", | ||
"description": "", | ||
"license": "MIT", | ||
"author": { | ||
"name": "Andrew Lisowski", | ||
"email": "[email protected]" | ||
}, | ||
"publishConfig": { | ||
"registry": "https://registry.npmjs.org/", | ||
"access": "public" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/intuit/auto" | ||
}, | ||
"files": [ | ||
"dist" | ||
], | ||
"keywords": [ | ||
"automation", | ||
"semantic", | ||
"release", | ||
"github", | ||
"labels", | ||
"automated", | ||
"continuos integration", | ||
"changelog" | ||
], | ||
"scripts": { | ||
"build": "tsc -b", | ||
"start": "npm run build -- -w", | ||
"lint": "eslint src --ext .ts", | ||
"test": "jest --maxWorkers=2 --config ../../package.json" | ||
}, | ||
"dependencies": { | ||
"@auto-it/core": "link:../../packages/core", | ||
"node-fetch": "2.6.7", | ||
"fp-ts": "^2.5.3", | ||
"io-ts": "^2.1.2", | ||
"openai": "^3.2.1", | ||
"tslib": "1.10.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import { Auto, IPlugin, validatePluginConfiguration } from "@auto-it/core"; | ||
import * as t from "io-ts"; | ||
import { Configuration, OpenAIApi } from "openai"; | ||
import fetch from "node-fetch"; | ||
import endent from "endent"; | ||
|
||
const configuration = new Configuration({ | ||
apiKey: process.env.OPENAI_API_KEY, | ||
}); | ||
const openai = new OpenAIApi(configuration); | ||
|
||
const prompt = [ | ||
"Take the role of an experienced engineer with excellent ability to communicate technical concepts to a non-technical audience.", | ||
"Your job is to read the diffs, pull request descriptions, and commit descriptions I provide and produce a summary of the changes.", | ||
"Your summaries should be at max 6 sentences long and contain no references to coding.", | ||
"Try to also sell the feature like a marketer.", | ||
"Reply only with the summaries.", | ||
]; | ||
|
||
const pluginOptions = t.partial({}); | ||
|
||
export type IAiReleaseNotesPluginOptions = t.TypeOf<typeof pluginOptions>; | ||
|
||
/** */ | ||
export default class AiReleaseNotesPlugin implements IPlugin { | ||
/** The name of the plugin */ | ||
name = "ai-release-notes"; | ||
|
||
/** The options of the plugin */ | ||
readonly options: IAiReleaseNotesPluginOptions; | ||
|
||
/** Initialize the plugin with it's options */ | ||
constructor(options: IAiReleaseNotesPluginOptions) { | ||
this.options = options; | ||
} | ||
|
||
/** Tap into auto plugin points. */ | ||
apply(auto: Auto) { | ||
auto.hooks.validateConfig.tapPromise(this.name, async (name, options) => { | ||
// If it's a string thats valid config | ||
if (name === this.name && typeof options !== "string") { | ||
return validatePluginConfiguration(this.name, pluginOptions, options); | ||
} | ||
}); | ||
|
||
auto.hooks.prCheck.tapPromise(this.name, async ({ pr, dryRun }) => { | ||
try { | ||
const diff = await fetch(pr.diff_url).then((res) => res.text()); | ||
const body = pr.body?.split("<!-- GITHUB_RELEASE PR BODY")[0] || ""; | ||
const response = await openai.createChatCompletion({ | ||
model: "gpt-3.5-turbo", | ||
messages: [...prompt, body, diff].map((content) => ({ | ||
role: "user", | ||
content, | ||
})), | ||
temperature: 0, | ||
top_p: 1.0, | ||
n: 1, | ||
frequency_penalty: 0.0, | ||
presence_penalty: 0.0, | ||
stop: ["#", ";"], | ||
}); | ||
const message = endent` | ||
## Release Notes | ||
|
||
${response.data.choices[0].message?.content} | ||
`; | ||
|
||
if (dryRun) { | ||
auto.logger.log.info("Would have posted the following comment:"); | ||
auto.logger.log.info(message); | ||
} else { | ||
await auto.prBody({ | ||
pr: pr.number, | ||
context: this.name, | ||
message, | ||
}); | ||
} | ||
} catch (err) { | ||
console.log(err); | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"include": ["src/**/*", "../../typings/**/*"], | ||
|
||
"compilerOptions": { | ||
"outDir": "./dist", | ||
"rootDir": "./src", | ||
"composite": true | ||
}, | ||
|
||
"references": [ | ||
{ | ||
"path": "../../packages/core" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -97,6 +97,9 @@ | |
}, | ||
{ | ||
"path": "plugins/protected-branch" | ||
}, | ||
{ | ||
"path": "plugins/ai-release-notes" | ||
} | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR is so cool, looking forward to it