From 481d490b28f65466989a0c2c7a7e27d45105075c Mon Sep 17 00:00:00 2001 From: Andrew Lisowski Date: Tue, 2 May 2023 14:18:46 -0700 Subject: [PATCH 1/4] working --- auto.config.ts | 1 + plugins/ai-release-notes/README.md | 24 ++++++++ .../__tests__/ai-release-notes.test.ts | 7 +++ plugins/ai-release-notes/package.json | 46 +++++++++++++++ plugins/ai-release-notes/src/index.ts | 57 +++++++++++++++++++ plugins/ai-release-notes/tsconfig.json | 16 ++++++ tsconfig.dev.json | 5 +- yarn.lock | 41 +++++++++++-- 8 files changed, 190 insertions(+), 7 deletions(-) create mode 100644 plugins/ai-release-notes/README.md create mode 100644 plugins/ai-release-notes/__tests__/ai-release-notes.test.ts create mode 100644 plugins/ai-release-notes/package.json create mode 100644 plugins/ai-release-notes/src/index.ts create mode 100644 plugins/ai-release-notes/tsconfig.json diff --git a/auto.config.ts b/auto.config.ts index e5d7cf265..470c0b7c2 100644 --- a/auto.config.ts +++ b/auto.config.ts @@ -48,6 +48,7 @@ export default function rc(): AutoRc { "./scripts/auto-update-curl-version.js", ["all-contributors", allContributorsOptions], ["brew", brewOptions], + "ai-release-notes", ], labels: [ { diff --git a/plugins/ai-release-notes/README.md b/plugins/ai-release-notes/README.md new file mode 100644 index 000000000..804bd0546 --- /dev/null +++ b/plugins/ai-release-notes/README.md @@ -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 + ] +} +``` diff --git a/plugins/ai-release-notes/__tests__/ai-release-notes.test.ts b/plugins/ai-release-notes/__tests__/ai-release-notes.test.ts new file mode 100644 index 000000000..b9ef8c56c --- /dev/null +++ b/plugins/ai-release-notes/__tests__/ai-release-notes.test.ts @@ -0,0 +1,7 @@ +import Auto from '@auto-it/core'; +import AiReleaseNotes from '../src'; + +describe('Ai-Release-Notes Plugin', () => { + test('should do something', async () => { + }); +}); diff --git a/plugins/ai-release-notes/package.json b/plugins/ai-release-notes/package.json new file mode 100644 index 000000000..1eb7ca8f1 --- /dev/null +++ b/plugins/ai-release-notes/package.json @@ -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" + } +} diff --git a/plugins/ai-release-notes/src/index.ts b/plugins/ai-release-notes/src/index.ts new file mode 100644 index 000000000..bad058bdb --- /dev/null +++ b/plugins/ai-release-notes/src/index.ts @@ -0,0 +1,57 @@ +import { Auto, IPlugin, validatePluginConfiguration } from "@auto-it/core"; +import * as t from "io-ts"; +import { Configuration, OpenAIApi } from "openai"; +import fetch from "node-fetch"; + +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.", + "The summary should be targeted at consumer of the changed code.", + "Your summaries should be at max 6 sentences long and contain no references to coding.", + "Reply only with the summaries.", +]; + +const pluginOptions = t.partial({}); + +export type IAiReleaseNotesPluginOptions = t.TypeOf; + +/** */ +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 }) => { + const diff = await fetch(pr.diff_url).then((res) => res.text()); + const response = await openai.createCompletion({ + model: "gpt-4-32k", + prompt: [...prompt, pr.body, diff], + max_tokens: 7, + temperature: 0, + }); + + console.log(response); + }); + } +} diff --git a/plugins/ai-release-notes/tsconfig.json b/plugins/ai-release-notes/tsconfig.json new file mode 100644 index 000000000..bfbef6fc7 --- /dev/null +++ b/plugins/ai-release-notes/tsconfig.json @@ -0,0 +1,16 @@ +{ + "extends": "../../tsconfig.json", + "include": ["src/**/*", "../../typings/**/*"], + + "compilerOptions": { + "outDir": "./dist", + "rootDir": "./src", + "composite": true + }, + + "references": [ + { + "path": "../../packages/core" + } + ] +} diff --git a/tsconfig.dev.json b/tsconfig.dev.json index f9aa43eb0..e90f27594 100644 --- a/tsconfig.dev.json +++ b/tsconfig.dev.json @@ -97,6 +97,9 @@ }, { "path": "plugins/protected-branch" + }, + { + "path": "plugins/ai-release-notes" } ] -} +} \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index 4360489bc..528e93565 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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" @@ -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" @@ -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" @@ -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" @@ -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" @@ -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" @@ -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" @@ -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" From c76f02aaafea7623505fced0971c72b6a862b4d2 Mon Sep 17 00:00:00 2001 From: Andrew Lisowski Date: Tue, 2 May 2023 14:28:49 -0700 Subject: [PATCH 2/4] add token --- .github/workflows/build.yml | 1 + plugins/ai-release-notes/src/index.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3dd238375..74a1737f7 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -53,6 +53,7 @@ jobs: - run: yarn auto pr-check --pr $PR --url "$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" env: PR: ${{ steps.PR.outputs.number }} + PROTECTED_BRANCH_REVIEWER_TOKEN: ${{ secrets.GH_TOKEN }} env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/plugins/ai-release-notes/src/index.ts b/plugins/ai-release-notes/src/index.ts index bad058bdb..0095a10bc 100644 --- a/plugins/ai-release-notes/src/index.ts +++ b/plugins/ai-release-notes/src/index.ts @@ -44,6 +44,7 @@ export default class AiReleaseNotesPlugin implements IPlugin { auto.hooks.prCheck.tapPromise(this.name, async ({ pr }) => { const diff = await fetch(pr.diff_url).then((res) => res.text()); + console.log("DEBUG", pr); const response = await openai.createCompletion({ model: "gpt-4-32k", prompt: [...prompt, pr.body, diff], From 1e0f378da047243b7b74d857df11cd4fb4d96b5c Mon Sep 17 00:00:00 2001 From: Andrew Lisowski Date: Tue, 2 May 2023 14:41:53 -0700 Subject: [PATCH 3/4] better PR detection --- .github/workflows/build.yml | 7 ++++--- plugins/ai-release-notes/src/index.ts | 6 +++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 74a1737f7..0dc0fc7e8 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -48,11 +48,12 @@ 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 }} diff --git a/plugins/ai-release-notes/src/index.ts b/plugins/ai-release-notes/src/index.ts index 0095a10bc..0d725dcfb 100644 --- a/plugins/ai-release-notes/src/index.ts +++ b/plugins/ai-release-notes/src/index.ts @@ -43,11 +43,11 @@ export default class AiReleaseNotesPlugin implements IPlugin { }); auto.hooks.prCheck.tapPromise(this.name, async ({ pr }) => { - const diff = await fetch(pr.diff_url).then((res) => res.text()); - console.log("DEBUG", pr); + const diff = await fetch(pr.patch_url).then((res) => res.text()); + const body = pr.body?.split("