generated from ubiquity-os/plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 9
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
0x4007
merged 19 commits into
ubiquity-os-marketplace:development
from
sshivaditya2019:development
Aug 31, 2024
Merged
Changes from 14 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
9c0de23
fix: issue_comments linting added issue_comments:edited, created and …
sshivaditya a4ee41e
fix: test and linting
sshivaditya d91b991
fix: plugin name
sshivaditya f890071
fix: wrangler name
sshivaditya 97e267f
feat: modified tests
sshivaditya 0e870ac
fix: fixed tests missing supabase files
sshivaditya 3b25774
Update wrangler.toml
sshivaditya2019 16786d7
fix: github workflow, types package.json, env examples
sshivaditya f325310
fix: knip workflow
sshivaditya 736bea6
fix: cspell fix
sshivaditya 21409d5
fix: manifest.json, compute.yml
sshivaditya 2fec447
fix: readme.md
sshivaditya 9c5fbfe
fix: readme.md
sshivaditya 127cc22
fix: remove config.yml and wrangler.toml namespace entries
sshivaditya 806c6c0
fix: package.json
sshivaditya d12c522
fix: added config.yml
sshivaditya 221d34d
fix: added config.yml
sshivaditya c0f784b
fix: added config.yml
sshivaditya 744e08c
fix: removed config.yml changed name
sshivaditya 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
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 |
---|---|---|
@@ -1 +1,3 @@ | ||
MY_SECRET="MY_SECRET" | ||
SUPABASE_URL="" | ||
SUPABASE_KEY="" | ||
OPENAI_API_KEY="" |
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 |
---|---|---|
@@ -1 +1,3 @@ | ||
MY_SECRET="MY_SECRET" | ||
SUPABASE_URL= | ||
SUPABASE_KEY= | ||
OPENAI_API_KEY= |
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
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,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 }} |
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
#vscode | ||
.vscode | ||
# macOS | ||
.DS_Store | ||
# node | ||
|
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 |
---|---|---|
@@ -1,86 +1,55 @@ | ||
# `@ubiquibot/plugin-template` | ||
|
||
## Prerequisites | ||
|
||
- A good understanding of how the [kernel](https://github.com/ubiquity/ubiquibot-kernel) works and how to interact with it. | ||
- A basic understanding of the Ubiquibot configuration and how to define your plugin's settings. | ||
|
||
## Getting Started | ||
|
||
1. Create a new repository using this template. | ||
2. Clone the repository to your local machine. | ||
3. Install the dependencies preferably using `yarn` or `bun`. | ||
|
||
## Creating a new plugin | ||
|
||
- If your plugin is to be used as a slash command which should have faster response times as opposed to longer running GitHub action tasks, you should use the `worker` type. | ||
|
||
1. Ensure you understand and have setup the [kernel](https://github.com/ubiquity/ubiquibot-kernel). | ||
2. Update [compute.yml](./.github/workflows/compute.yml) with your plugin's name and update the `id`. | ||
3. Update [context.ts](./src/types/context.ts) with the events that your plugin will fire on. | ||
4. Update [manifest.json](./manifest.json) with a proper description of your plugin. | ||
5. Update [plugin-inputs.ts](./src/types/plugin-inputs.ts) to match the `with:` settings in your org or repo level configuration. | ||
|
||
- Your plugin config should look similar to this: | ||
|
||
```yml | ||
plugins: | ||
- name: hello-world | ||
id: hello-world | ||
uses: | ||
- plugin: http://localhost:4000 | ||
with: | ||
# Define configurable items here and the kernel will pass these to the plugin. | ||
configurableResponse: "Hello, is it me you are looking for?" | ||
# `@ubiquibot/issue-comment-embeddings` | ||
|
||
This is a plugin for [Ubiquibot](https://github.com/ubiquity/ubiquibot-kernel). It listens for issue comments, and adds them to a vector store. It handles comment edits and deletions as well. | ||
|
||
## Configuration | ||
- Host the plugin on a server that Ubiquibot can access. | ||
To set up the `.dev.vars` file, you will need to provide the following variables: | ||
- `SUPABASE_URL`: The URL for your Supabase instance. | ||
- `SUPABASE_KEY`: The key for your Supabase instance. | ||
- `OPENAI_API_KEY`: The API key for OpenAI. | ||
|
||
## Usage | ||
- Add the following to your `.ubiquibot.config.yml` file with the appropriate URL: | ||
```javascript | ||
-plugin: http://127.0.0.1:4000 | ||
runsOn: [ "issue_comment.created", "issue_comment.edited", "issue_comment.deleted" ] | ||
``` | ||
|
||
###### At this stage, your plugin will fire on your defined events with the required settings passed in from the kernel. You can now start writing your plugin's logic. | ||
|
||
6. Start building your plugin by adding your logic to the [plugin.ts](./src/plugin.ts) file. | ||
|
||
## Testing a plugin | ||
|
||
### Worker Plugins | ||
|
||
- `yarn/bun worker` - to run the worker locally. | ||
- To trigger the worker, `POST` requests to http://localhost:4000/ with an event payload similar to: | ||
|
||
```ts | ||
await fetch("http://localhost:4000/", { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
body: JSON.stringify({ | ||
stateId: "", | ||
eventName: "", | ||
eventPayload: "", | ||
settings: "", | ||
ref: "", | ||
authToken: "", | ||
}), | ||
}); | ||
## Testing Locally | ||
- Run `yarn install` to install the dependencies. | ||
- Run `yarn worker` to start the server. | ||
- Make HTTP requests to the server to test the plugin with content type `Application/JSON` | ||
``` | ||
{ | ||
"stateId": "", | ||
"eventName": "issue_comment.created", | ||
"eventPayload": { | ||
"comment": { | ||
"user": { | ||
"login" : "COMMENTER" | ||
}, | ||
"body": "<COMMENT_BODY>" , | ||
"id": <UNIQUE_COMMENT_ID> | ||
}, | ||
"repository" : { | ||
"name" : "REPONAME", | ||
"owner":{ | ||
"login" : "USERNAME" | ||
} | ||
}, | ||
"issue": { | ||
"number": <ISSUE_NUMBER>, | ||
"body": "<ISSUE_TEXT>" | ||
} | ||
}, | ||
"env": {}, | ||
"settings": {}, | ||
"ref": "", | ||
"authToken": "" | ||
} | ||
``` | ||
- Replace the placeholders with the appropriate values. | ||
|
||
A full example can be found [here](https://github.com/ubiquibot/assistive-pricing/blob/623ea3f950f04842f2d003bda3fc7b7684e41378/tests/http/request.http). | ||
|
||
### Action Plugins | ||
|
||
- Ensure the kernel is running and listening for events. | ||
- Fire an event in/to the repo where the kernel is installed. This can be done in a number of ways, the easiest being via the GitHub UI or using the GitHub API, such as posting a comment, opening an issue, etc in the org/repo where the kernel is installed. | ||
- The kernel will process the event and dispatch it using the settings defined in your `.ubiquibot-config.yml`. | ||
- The `compute.yml` workflow will run and execute your plugin's logic. | ||
- You can view the logs in the Actions tab of your repo. | ||
|
||
[Nektos Act](https://github.com/nektos/act) - a tool for running GitHub Actions locally. | ||
|
||
## More information | ||
|
||
- [Full Ubiquibot Configuration](https://github.com/ubiquity/ubiquibot/blob/0fde7551585499b1e0618ec8ea5e826f11271c9c/src/types/configuration-types.ts#L62) - helpful for defining your plugin's settings as they are strongly typed and will be validated by the kernel. | ||
- [Ubiquibot V1](https://github.com/ubiquity/ubiquibot) - helpful for porting V1 functionality to V2, helper/utility functions, types, etc. Everything is based on the V1 codebase but with a more modular approach. When using V1 code, keep in mind that most all code will need refactored to work with the new V2 architecture. | ||
|
||
## Examples | ||
|
||
- [Start/Stop Slash Command](https://github.com/ubq-testing/start-stop-module) - simple | ||
- [Assistive Pricing Plugin](https://github.com/ubiquibot/assistive-pricing) - complex | ||
- [Conversation Rewards](https://github.com/ubiquibot/conversation-rewards) - really complex | ||
## Testing | ||
- Run `yarn test` to run the tests. |
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 |
---|---|---|
@@ -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", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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"] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Possibly |
||
} |
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,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), | ||
}, | ||
}; | ||
} |
Oops, something went wrong.
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.
The purpose of this is to serve as the foundation of the system's awareness across all organization operations.