Skip to content
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
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 5 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,13 @@ jobs:
- uses: actions/checkout@v3
- uses: ./.github/actions/install-deps
- uses: ./.github/actions/build-cache
- uses: 8BitJonny/gh-get-current-pr@2.2.0
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 }}

Expand Down
1 change: 1 addition & 0 deletions auto.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export default function rc(): AutoRc {
"./scripts/auto-update-curl-version.js",
["all-contributors", allContributorsOptions],
["brew", brewOptions],
"ai-release-notes",
],
labels: [
{
Expand Down
24 changes: 24 additions & 0 deletions plugins/ai-release-notes/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Ai-Release-Notes Plugin


Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
## Prerequisites
To generate an AI powered `## Release Notes` in the PR, you will need an [`OPENAI_API_KEY`](https://platform.openai.com/account/api-keys) set in your environment

This PR is so cool, looking forward to it


## 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
]
}
```
7 changes: 7 additions & 0 deletions plugins/ai-release-notes/__tests__/ai-release-notes.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import Auto from '@auto-it/core';

Check failure on line 1 in plugins/ai-release-notes/__tests__/ai-release-notes.test.ts

View workflow job for this annotation

GitHub Actions / lint

'Auto' is defined but never used
import AiReleaseNotes from '../src';

Check failure on line 2 in plugins/ai-release-notes/__tests__/ai-release-notes.test.ts

View workflow job for this annotation

GitHub Actions / lint

'AiReleaseNotes' is defined but never used

describe('Ai-Release-Notes Plugin', () => {
test('should do something', async () => {

Check warning on line 5 in plugins/ai-release-notes/__tests__/ai-release-notes.test.ts

View workflow job for this annotation

GitHub Actions / lint

Test has no assertions
});
});
46 changes: 46 additions & 0 deletions plugins/ai-release-notes/package.json
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": "lisowski54@gmail.com"
},
"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"
}
}
84 changes: 84 additions & 0 deletions plugins/ai-release-notes/src/index.ts
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";

Check failure on line 5 in plugins/ai-release-notes/src/index.ts

View workflow job for this annotation

GitHub Actions / lint

'endent' should be listed in the project's dependencies. Run 'npm i -S endent' to add it

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);
}
});
}
}
16 changes: 16 additions & 0 deletions plugins/ai-release-notes/tsconfig.json
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"
}
]
}
5 changes: 4 additions & 1 deletion tsconfig.dev.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@
},
{
"path": "plugins/protected-branch"
},
{
"path": "plugins/ai-release-notes"
}
]
}
}
41 changes: 35 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
integrity sha512-K1kQv1BZVtMXQqdpNZt9Pgh85KwamsWX9gYyq1xG4cpyb+EacfMiNfumrju16piFXanCUrCR0P1DowPjV2qV/A==

"@auto-it/bot-list@link:packages/bot-list":
version "10.38.0"
version "10.46.0"

"@auto-it/core@link:packages/core":
version "10.38.0"
version "10.46.0"
dependencies:
"@auto-it/bot-list" "link:packages/bot-list"
"@endemolshinegroup/cosmiconfig-typescript-loader" "^3.0.2"
Expand Down Expand Up @@ -60,7 +60,7 @@
url-join "^4.0.0"

"@auto-it/npm@link:plugins/npm":
version "10.38.0"
version "10.46.0"
dependencies:
"@auto-it/core" "link:packages/core"
"@auto-it/package-json-utils" "link:packages/package-json-utils"
Expand All @@ -78,13 +78,13 @@
user-home "^2.0.0"

"@auto-it/package-json-utils@link:packages/package-json-utils":
version "10.38.0"
version "10.46.0"
dependencies:
parse-author "^2.0.0"
parse-github-url "1.0.2"

"@auto-it/released@link:plugins/released":
version "10.38.0"
version "10.46.0"
dependencies:
"@auto-it/bot-list" "link:packages/bot-list"
"@auto-it/core" "link:packages/core"
Expand All @@ -94,7 +94,7 @@
tslib "2.1.0"

"@auto-it/version-file@link:plugins/version-file":
version "10.38.0"
version "10.46.0"
dependencies:
"@auto-it/core" "link:packages/core"
fp-ts "^2.5.3"
Expand Down Expand Up @@ -4045,6 +4045,13 @@ aws4@^1.8.0:
resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.11.0.tgz#d61f46d83b2519250e2784daf5b09479a8b41c59"
integrity sha512-xh1Rl34h6Fi1DC2WWKfxUTVqRsNnr6LsKz2+hfwDxQJWmrx8+c7ylaqBMcHfl1U1r2dsifOvKX3LQuLNZ+XSvA==

axios@^0.26.0:
version "0.26.1"
resolved "https://registry.npmjs.org/axios/-/axios-0.26.1.tgz#1ede41c51fcf51bbbd6fd43669caaa4f0495aaa9"
integrity sha512-fPwcX4EvnSHuInCMItEhAGnaSEXRBjtzh9fOtsE6E1G6p7vl7edEeZe11QHf18+6+9gR5PbKV/sGKNaD8YaMeA==
dependencies:
follow-redirects "^1.14.8"

azure-devops-node-api@^10.2.2:
version "10.2.2"
resolved "https://registry.yarnpkg.com/azure-devops-node-api/-/azure-devops-node-api-10.2.2.tgz#9f557e622dd07bbaa9bd5e7e84e17c761e2151b2"
Expand Down Expand Up @@ -7158,6 +7165,11 @@ flush-write-stream@^1.0.0:
inherits "^2.0.3"
readable-stream "^2.3.6"

follow-redirects@^1.14.8:
version "1.15.2"
resolved "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.2.tgz#b460864144ba63f2681096f274c4e57026da2c13"
integrity sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==

for-in@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/for-in/-/for-in-1.0.2.tgz#81068d295a8142ec0ac726c6e2200c30fb6d5e80"
Expand All @@ -7182,6 +7194,15 @@ form-data@^3.0.0:
combined-stream "^1.0.8"
mime-types "^2.1.12"

form-data@^4.0.0:
version "4.0.0"
resolved "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz#93919daeaf361ee529584b9b31664dc12c9fa452"
integrity sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==
dependencies:
asynckit "^0.4.0"
combined-stream "^1.0.8"
mime-types "^2.1.12"

form-data@~2.3.2:
version "2.3.3"
resolved "https://registry.yarnpkg.com/form-data/-/form-data-2.3.3.tgz#dcce52c05f644f298c6a7ab936bd724ceffbf3a6"
Expand Down Expand Up @@ -11266,6 +11287,14 @@ open@^7.4.2:
is-docker "^2.0.0"
is-wsl "^2.1.1"

openai@^3.2.1:
version "3.2.1"
resolved "https://registry.npmjs.org/openai/-/openai-3.2.1.tgz#1fa35bdf979cbde8453b43f2dd3a7d401ee40866"
integrity sha512-762C9BNlJPbjjlWZi4WYK9iM2tAVAv0uUp1UmI34vb0CN5T2mjB/qM6RYBmNKMh/dN9fC+bxqPwWJZUTWW052A==
dependencies:
axios "^0.26.0"
form-data "^4.0.0"

opener@^1.5.1:
version "1.5.2"
resolved "https://registry.yarnpkg.com/opener/-/opener-1.5.2.tgz#5d37e1f35077b9dcac4301372271afdeb2a13598"
Expand Down