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

Adds Github Action Support #6

Merged
Merged
Show file tree
Hide file tree
Changes from 7 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
50 changes: 50 additions & 0 deletions .github/workflows/compute.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: "@ubiquity-os/command-ask"
sshivaditya2019 marked this conversation as resolved.
Show resolved Hide resolved

on:
workflow_dispatch:
inputs:
stateId:
description: "State Id"
eventName:
description: "Event Name"
eventPayload:
description: "Event Payload"
settings:
description: "Settings"
authToken:
description: "Auth Token"
ref:
description: "Ref"
Copy link
Member

Choose a reason for hiding this comment

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

This should have an explanation it's unclear what this is


sshivaditya2019 marked this conversation as resolved.
Show resolved Hide resolved
jobs:
compute:
name: "LLM Reply"
runs-on: ubuntu-latest
permissions: write-all
env:
SUPABASE_URL: ${{ secrets.SUPABASE_URL }}
SUPABASE_KEY: ${{ secrets.SUPABASE_KEY }}
VOYAGEAI_API_KEY: ${{secrets.VOYAGEAI_API_KEY}}
sshivaditya2019 marked this conversation as resolved.
Show resolved Hide resolved
OPENAI_API_KEY: ${{secrets.OPENAI_API_KEY}}
UBIQUITY_OS_APP_NAME: ${{secrets.UBIQUITY_OS_APP_NAME}}

steps:
- uses: actions/checkout@v4

- name: setup node
uses: actions/setup-node@v4
with:
node-version: "20.10.0"

- name: install dependencies
run: yarn

- name: execute directive
run: npx tsx ./src/main.ts
sshivaditya2019 marked this conversation as resolved.
Show resolved Hide resolved
id: command-ask
env:
SUPABASE_URL: ${{ secrets.SUPABASE_URL }}
SUPABASE_KEY: ${{ secrets.SUPABASE_KEY }}
VOYAGEAI_API_KEY: ${{secrets.VOYAGEAI_API_KEY}}
OPENAI_API_KEY: ${{secrets.OPENAI_API_KEY}}
UBIQUITY_OS_APP_NAME: ${{secrets.UBIQUITY_OS_APP_NAME}}
22 changes: 22 additions & 0 deletions .github/workflows/update-configuration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Update Manifest and Commit Changes

on:
workflow_dispatch:
push:


sshivaditya2019 marked this conversation as resolved.
Show resolved Hide resolved
jobs:
update-manifest:
name: "Update Manifest and Commit Changes"
runs-on: ubuntu-latest
steps:
- name: Update Manifest and Commit Changes
uses: ubiquity-os/action-deploy-plugin@main
with:
manifestPath: ${{ github.workspace }}/manifest.json
schemaPath: ${{ github.workspace }}/src/types/plugin-input.js
sshivaditya2019 marked this conversation as resolved.
Show resolved Hide resolved
pluginEntry: ${{ github.workspace }}/src/plugin.ts
commitMessage: "chore: updated manifest.json and dist build"
nodeVersion: "20.10.0"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
"voyageai": "^0.0.1-5"
},
"devDependencies": {
"@actions/core": "^1.11.1",
"@actions/github": "^6.0.0",
"@commitlint/cli": "19.3.0",
"@commitlint/config-conventional": "19.2.2",
"@cspell/dict-node": "5.0.1",
Expand Down Expand Up @@ -66,7 +68,7 @@
"tsx": "4.15.6",
"typescript": "5.4.5",
"typescript-eslint": "7.13.1",
"wrangler": "3.60.3"
"wrangler": "^3.81.0"
},
"lint-staged": {
"*.ts": [
Expand Down
4 changes: 3 additions & 1 deletion src/adapters/supabase/helpers/comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ export class Comment extends SuperSupabase {
}
return data;
}

async findSimilarComments(query: string, threshold: number, currentId: string): Promise<CommentSimilaritySearchResult[] | null> {
const embedding = await this.context.adapters.voyage.embedding.createEmbedding({ text: query, prompt: "This is a query for the stored documents:" });
//Escape the any special characters in the query for use in the SQL query
query = query.replace(/'/g, "''").replace(/\\/g, "\\\\").replace(/"/g, '\\"').replace(/%/g, "\\%").replace(/_/g, "\\_");
this.context.logger.info(`Query: ${query}`);
const { data, error } = await this.supabase.rpc("find_similar_comments", {
current_id: currentId,
query_text: query,
Expand Down
1 change: 1 addition & 0 deletions src/adapters/supabase/helpers/issues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export class Issue extends SuperSupabase {
}
async findSimilarIssues(plaintext: string, threshold: number, currentId: string): Promise<IssueSimilaritySearchResult[] | null> {
const embedding = await this.context.adapters.voyage.embedding.createEmbedding({ text: plaintext, prompt: "This is a query for the stored documents:" });
plaintext = plaintext.replace(/'/g, "''").replace(/\\/g, "\\\\").replace(/"/g, '\\"').replace(/%/g, "\\%").replace(/_/g, "\\_");
const { data, error } = await this.supabase.rpc("find_similar_issue_ftse", {
current_id: currentId,
query_text: plaintext,
Expand Down
1 change: 0 additions & 1 deletion src/handlers/comments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ export function streamlineComments(comments: SimplifiedComment[]) {
if (user?.type === "Bot") continue;
const key = createKey(url);
const [owner, repo] = splitKey(key);

if (!streamlined[key]) {
streamlined[key] = [];
}
Expand Down
4 changes: 2 additions & 2 deletions src/helpers/format-chat-history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,9 @@ function createComment(comment: StreamlinedComments) {
return "";
}
// Remove duplicates
const uniqueComments = comment.comments.filter((c, i, a) => a.findIndex((cc) => cc.id === c.id) === i);
//const uniqueComments = comment.comments.filter((c, i, a) => a.findIndex((cc) => cc.id === c.id) === i);
sshivaditya2019 marked this conversation as resolved.
Show resolved Hide resolved
// Format comments
const formattedComments = uniqueComments.map((c) => `${c.id} ${c.user}: ${c.body}\n`);
const formattedComments = comment.comments.map((c) => `${c.id} ${c.user}: ${c.body}\n`);
return formattedComments.join("");
}

Expand Down
1 change: 0 additions & 1 deletion src/helpers/issue-fetching.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ export async function fetchLinkedIssues(params: FetchParams) {
for (const comment of comments) {
const foundIssues = idIssueFromComment(comment.body);
const foundCodes = comment.body ? await fetchCodeLinkedFromIssue(comment.body, params.context, comment.issueUrl) : [];

if (foundIssues) {
for (const linkedIssue of foundIssues) {
const linkedKey = createKey(linkedIssue.url, linkedIssue.issueNumber);
Expand Down
5 changes: 3 additions & 2 deletions src/helpers/issue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ export async function fetchCodeLinkedFromIssue(
path: parsedUrl.path,
});
}

if ("content" in response.data) {
const content = Buffer.from(response.data.content, "base64").toString();
return { body: content, id: parsedUrl.path };
Expand All @@ -163,7 +162,9 @@ export async function fetchCodeLinkedFromIssue(
repo: context.payload.repository.name,
issueNumber: parseInt(issue.match(/\/issues\/(\d+)/)?.[1] || "0", 10),
issueUrl: url,
user: null,
user: {
sshivaditya2019 marked this conversation as resolved.
Show resolved Hide resolved
...context.payload.sender,
},
}));
}

Expand Down
39 changes: 39 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import * as core from "@actions/core";
import * as github from "@actions/github";
import { Value } from "@sinclair/typebox/value";
import { envSchema } from "./types/env";
import { pluginSettingsSchema, PluginInputs, pluginSettingsValidator } from "./types";
import { plugin } from "./plugin";

/**
* How a GitHub action executes the plugin.
*/
export async function run() {
const payload = github.context.payload.inputs;
const env = Value.Decode(envSchema, process.env);
const settings = Value.Decode(pluginSettingsSchema, Value.Default(pluginSettingsSchema, JSON.parse(payload.settings)));

if (!pluginSettingsValidator.test(settings)) {
throw new Error("Invalid settings provided");
}

const inputs: PluginInputs = {
stateId: payload.stateId,
eventName: payload.eventName,
eventPayload: JSON.parse(payload.eventPayload),
settings,
authToken: payload.authToken,
ref: payload.ref,
};

await plugin(inputs, env);
}

run()
.then((result) => {
core.setOutput("result", result);
})
.catch((error) => {
console.error(error);
core.setFailed(error);
});
4 changes: 2 additions & 2 deletions src/types/github-types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export type LinkedIssues = {
};

export type SimplifiedComment = {
user: User | null;
user: User | Partial<User>;
body: string;
id: string;
org: string;
Expand All @@ -37,7 +37,7 @@ export type SimplifiedComment = {

export type FetchedCodes = {
body: string;
user: User | null;
user: User | Partial<User>;
issueUrl: string;
id: string;
org: string;
Expand Down
1 change: 1 addition & 0 deletions tests/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ describe("Ask plugin tests", () => {

=== Linked Issue #3 Conversation === ubiquity/test-repo #3 ===

4 ubiquity: Just a comment [#1](https://www.github.com/ubiquity/test-repo/issues/1)
4 ubiquity: Just a comment [#1](https://www.github.com/ubiquity/test-repo/issues/1)
=== End Linked Issue #3 Conversation ===\n
`;
Expand Down
Loading