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

fix: issue_comments linting added issue_comments:edited, created and … #1

Merged
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .cspell.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "https://raw.githubusercontent.com/streetsidesoftware/cspell/main/cspell.schema.json",
"version": "0.2",
"ignorePaths": ["**/*.json", "**/*.css", "node_modules", "**/*.log", "./src/adapters/supabase/**/**.ts"],
"ignorePaths": ["**/*.json", "**/*.css", "node_modules", "**/*.log", "./src/adapters/supabase/**/**.ts", "./src/types/database.ts", "./supabase/config.toml"],
"useGitignore": true,
"language": "en",
"words": [
Expand All @@ -20,7 +20,9 @@
"Typeguards",
"sonarjs",
"knip",
"mischeck"
"mischeck",
"commentbody",
"issuebody"
],
"dictionaries": ["typescript", "node", "software-terms"],
"import": ["@cspell/dict-typescript/cspell-ext.json", "@cspell/dict-node/cspell-ext.json", "@cspell/dict-software-terms"],
Expand Down
4 changes: 3 additions & 1 deletion .dev.vars.example
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
MY_SECRET="MY_SECRET"
SUPABASE_URL=""
SUPABASE_KEY=""
OPENAI_API_KEY=""
4 changes: 3 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
MY_SECRET="MY_SECRET"
SUPABASE_URL=
SUPABASE_KEY=
OPENAI_API_KEY=
6 changes: 6 additions & 0 deletions .github/.ubiquibot-config.yml
sshivaditya2019 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
plugins:
- name: test-app
id: test-app
uses:
- plugin: http://127.0.0.1:5000
runsOn: [ "issue_comment.created", "issue_comment.edited", "issue_comment.deleted" ]
Copy link
Member

Choose a reason for hiding this comment

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

Can't we do "issue_comment" to be concise? @gentlementlegen

Copy link
Member

Choose a reason for hiding this comment

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

Not with the current implementation because it wouldn't match the event and wouldn't be triggered.

Copy link
Member

Choose a reason for hiding this comment

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

This file should be removed, otherwise no plugin will run inside of this repo.

4 changes: 2 additions & 2 deletions .github/knip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import type { KnipConfig } from "knip";
const config: KnipConfig = {
entry: ["build/index.ts"],
project: ["src/**/*.ts"],
ignore: ["src/types/config.ts", "**/__mocks__/**", "**/__fixtures__/**"],
ignore: ["src/types/config.ts", "**/__mocks__/**", "**/__fixtures__/**", "src/types/database.ts"],
ignoreExportsUsedInFile: true,
// eslint can also be safely ignored as per the docs: https://knip.dev/guides/handling-issues#eslint--jest
ignoreDependencies: ["eslint-config-prettier", "eslint-plugin-prettier", "@mswjs/data"],
ignoreDependencies: ["eslint-config-prettier", "eslint-plugin-prettier"],
eslint: true,
};

Expand Down
8 changes: 5 additions & 3 deletions .github/workflows/compute.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: "the name of the plugin"
name: "@ubiquibot/issue-comment-embeddings"
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
name: "@ubiquibot/issue-comment-embeddings"
name: "@ubiquity-os/comment-vector-embeddings"
  • Shouldn't this eventually cover all comments?
  • Ubiquibot is deprecated
  • ideally this plugin should be generalized to allow us to pass in anything to generate embeddings. Maybe we can generate a unique ID based on where it's coming in from (GitHub, Telegram) and the project it's posted to (repository/issue, or group chat id) etc

The purpose of this is to serve as the foundation of the system's awareness across all organization operations.


on:
workflow_dispatch:
Expand All @@ -18,12 +18,13 @@ on:

jobs:
compute:
name: "plugin name"
name: "Comment Embedding Store"
runs-on: ubuntu-latest
permissions: write-all
env:
SUPABASE_URL: ${{ secrets.SUPABASE_URL }}
SUPABASE_KEY: ${{ secrets.SUPABASE_KEY }}
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}

steps:
- uses: actions/checkout@v4
Expand All @@ -38,7 +39,8 @@ jobs:

- name: execute directive
run: npx tsx ./src/main.ts
id: plugin-name
id: issue-comment-embeddings
env:
SUPABASE_URL: ${{ secrets.SUPABASE_URL }}
SUPABASE_KEY: ${{ secrets.SUPABASE_KEY }}
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
67 changes: 67 additions & 0 deletions .github/workflows/database.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: Database

on:
push:
branches:
- main

env:
SUPABASE_ACCESS_TOKEN: ${{ secrets.SUPABASE_ACCESS_TOKEN }}
SUPABASE_DB_PASSWORD: ${{ secrets.SUPABASE_DB_PASSWORD }}
SUPABASE_PROJECT_ID: ${{ secrets.SUPABASE_PROJECT_ID }}

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

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: "20.10.0"

- uses: supabase/setup-cli@v1
with:
version: latest

- name: Link Supabase project
run: supabase link --project-ref $SUPABASE_PROJECT_ID

- name: Run migrations
run: supabase db push

generate_types:
runs-on: ubuntu-latest
needs:
- run-migration
permissions:
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: "20.10.0"

- name: Generate Supabase Types
run: |
yarn install
yarn run "supabase:generate:remote"

- name: Commit and Push generated types
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
git add src/types/database.ts
if [ -n "$(git diff-index --cached --name-only HEAD)" ]; then
git commit -m "chore: updated generated Supabase types" || echo "Lint-staged check failed"
git push origin main
else
echo "No changes to commit"
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#vscode
.vscode
# macOS
.DS_Store
# node
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# `@ubiquibot/plugin-template`
# `@ubiquibot/issue-comment-embeddings`

## Prerequisites

Expand Down
2 changes: 1 addition & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default tsEslint.config({
"@typescript-eslint": tsEslint.plugin,
"check-file": checkFile,
},
ignores: [".github/knip.ts"],
ignores: [".github/knip.ts", "src/types/database.ts"],
extends: [eslint.configs.recommended, ...tsEslint.configs.recommended, sonarjs.configs.recommended],
languageOptions: {
parser: tsEslint.parser,
Expand Down
12 changes: 3 additions & 9 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
{
"name": "ts-template",
"description": "ts-template for Ubiquibot plugins.",
"ubiquity:listeners": ["issue_comment.created"],
"commands": {
"command1": {
"ubiquity:example": "/command1 argument",
"description": "Command 1 with an argument."
}
}
"name": "@ubiquibot/issue-comment-embeddings",
Copy link
Member

Choose a reason for hiding this comment

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

ubiquity-os

"description": "Issue comment plugin for Ubiquibot. It enables the storage, updating, and deletion of issue comment embeddings.",
"ubiquity:listeners": ["issue_comment.created", "issue_comment.edited", "issue_comment.deleted"]
Copy link
Member

Choose a reason for hiding this comment

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

Possibly issue_comment only

}
16 changes: 11 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "plugin-template",
"name": "@ubiquibot/issue-comment-embeddings",
"version": "1.0.0",
"description": "Ubiquibot plugin template repository with TypeScript support.",
"description": "Issue comment plugin for Ubiquibot.",
sshivaditya2019 marked this conversation as resolved.
Show resolved Hide resolved
"author": "Ubiquity DAO",
"license": "MIT",
"main": "src/worker.ts",
Expand All @@ -14,10 +14,12 @@
"format:prettier": "prettier --write .",
"format:cspell": "cspell **/*",
"knip": "knip --config .github/knip.ts",
"knip-ci": "knip --no-exit-code --reporter json --config .github/knip.ts",
"knip-ci": "",
sshivaditya2019 marked this conversation as resolved.
Show resolved Hide resolved
"prepare": "husky install",
"test": "jest --setupFiles dotenv/config --coverage",
"worker": "wrangler dev --env dev --port 4000"
"worker": "wrangler dev --env dev --port 5000",
"supabase:generate:local": "supabase gen types typescript --local > src/types/database.ts",
"supabase:generate:remote": "cross-env-shell \"supabase gen types typescript --project-id $SUPABASE_PROJECT_ID --schema public > src/types/database.ts\""
},
"keywords": [
"typescript",
Expand All @@ -32,8 +34,10 @@
"@octokit/rest": "20.1.1",
"@octokit/webhooks": "13.2.7",
"@sinclair/typebox": "0.32.33",
"@supabase/supabase-js": "^2.45.2",
"@ubiquity-dao/ubiquibot-logger": "^1.3.0",
"dotenv": "16.4.5",
"openai": "^4.56.0",
"typebox-validators": "0.3.5"
},
"devDependencies": {
Expand All @@ -48,6 +52,7 @@
"@types/jest": "^29.5.12",
"@types/node": "20.14.5",
"cspell": "8.9.0",
"cross-env": "7.0.3",
"eslint": "9.5.0",
"eslint-config-prettier": "9.1.0",
"eslint-plugin-check-file": "2.8.0",
Expand All @@ -61,11 +66,12 @@
"lint-staged": "15.2.7",
"npm-run-all": "4.1.5",
"prettier": "3.3.2",
"supabase": "1.176.9",
sshivaditya2019 marked this conversation as resolved.
Show resolved Hide resolved
"ts-jest": "29.1.5",
"tsx": "4.15.6",
"typescript": "5.4.5",
"typescript-eslint": "7.13.1",
"wrangler": "3.60.3"
"wrangler": "3.62.0"
},
"lint-staged": {
"*.ts": [
Expand Down
20 changes: 20 additions & 0 deletions src/adapters/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { SupabaseClient } from "@supabase/supabase-js";
import { Context } from "../types";
import { Comment } from "./supabase/helpers/comment";
import { SuperSupabase } from "./supabase/helpers/supabase";
import { SuperOpenAi } from "./openai/helpers/openai";
import OpenAI from "openai";
import { Embedding } from "./openai/helpers/embedding";

export function createAdapters(supabaseClient: SupabaseClient, openai: OpenAI, context: Context) {
return {
supabase: {
comment: new Comment(supabaseClient, context),
super: new SuperSupabase(supabaseClient, context),
},
openai: {
embedding: new Embedding(openai, context),
super: new SuperOpenAi(openai, context),
},
};
}
25 changes: 25 additions & 0 deletions src/adapters/openai/helpers/embedding.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import OpenAI from "openai";
import { Context } from "../../../types";
import { SuperOpenAi } from "./openai";
const VECTOR_SIZE = 3072;
gentlementlegen marked this conversation as resolved.
Show resolved Hide resolved

export class Embedding extends SuperOpenAi {
protected context: Context;

constructor(client: OpenAI, context: Context) {
super(client, context);
this.context = context;
}

async createEmbedding(text: string): Promise<number[]> {
const params: OpenAI.EmbeddingCreateParams = {
model: "text-embedding-3-large",
input: text,
dimensions: VECTOR_SIZE,
};
const response = await this.client.embeddings.create({
...params,
});
return response.data[0]?.embedding;
}
}
12 changes: 12 additions & 0 deletions src/adapters/openai/helpers/openai.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { OpenAI } from "openai";
import { Context } from "../../../types/context";

export class SuperOpenAi {
protected client: OpenAI;
protected context: Context;

constructor(client: OpenAI, context: Context) {
this.client = client;
this.context = context;
}
}
63 changes: 63 additions & 0 deletions src/adapters/supabase/helpers/comment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { SupabaseClient } from "@supabase/supabase-js";
import { SuperSupabase } from "./supabase";
import { Context } from "../../../types/context";

export interface CommentType {
id: number;
body: string;
embedding: number[];
}

export class Comment extends SuperSupabase {
constructor(supabase: SupabaseClient, context: Context) {
super(supabase, context);
}

async createComment(commentBody: string, commentId: number, issueBody: string) {
//First Check if the comment already exists
const { data, error } = await this.supabase.from("issue_comments").select("*").eq("id", commentId);
if (error) {
this.context.logger.error("Error creating comment", error);
return;
}
if (data && data.length > 0) {
this.context.logger.info("Comment already exists");
return;
} else {
//Create the embedding for this comment
const embedding = await this.context.adapters.openai.embedding.createEmbedding(commentBody);
const { error } = await this.supabase
.from("issue_comments")
.insert([{ id: commentId, commentbody: commentBody, issuebody: issueBody, embedding: embedding }]);
if (error) {
this.context.logger.error("Error creating comment", error);
return;
}
}
this.context.logger.info("Comment created successfully");
}

async updateComment(commentBody: string, commentId: number) {
//Create the embedding for this comment
const embedding = Array.from(await this.context.adapters.openai.embedding.createEmbedding(commentBody));
const { error } = await this.supabase.from("issue_comments").update({ commentbody: commentBody, embedding: embedding }).eq("id", commentId);
if (error) {
this.context.logger.error("Error updating comment", error);
}
}

async getComment(commentId: number): Promise<CommentType[] | null> {
const { data, error } = await this.supabase.from("issue_comments").select("*").eq("id", commentId);
if (error) {
this.context.logger.error("Error getting comment", error);
}
return data;
}

async deleteComment(commentId: number) {
const { error } = await this.supabase.from("issue_comments").delete().eq("id", commentId);
if (error) {
this.context.logger.error("Error deleting comment", error);
}
}
}
12 changes: 12 additions & 0 deletions src/adapters/supabase/helpers/supabase.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { SupabaseClient } from "@supabase/supabase-js";
import { Context } from "../../../types/context";

export class SuperSupabase {
protected supabase: SupabaseClient;
protected context: Context;

constructor(supabase: SupabaseClient, context: Context) {
this.supabase = supabase;
this.context = context;
}
}
Loading