Skip to content

Commit

Permalink
feat: add payload creator for issue close event
Browse files Browse the repository at this point in the history
Implemented getPayload function to streamline issue close event payload.
  • Loading branch information
gentlementlegen committed Nov 10, 2024
1 parent 93b33df commit dfd04f5
Show file tree
Hide file tree
Showing 6 changed files with 280 additions and 243 deletions.
Binary file modified bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"@supabase/supabase-js": "2.42.0",
"@ubiquity-dao/rpc-handler": "1.3.0",
"@ubiquity-os/permit-generation": "^2.0.6",
"@ubiquity-os/plugin-sdk": "link:@ubiquity-os/plugin-sdk",
"@ubiquity-os/plugin-sdk": "^1.0.11",
"@ubiquity-os/ubiquity-os-logger": "^1.3.2",
"@octokit/plugin-paginate-graphql": "^5.2.4",
"decimal.js": "10.4.3",
Expand Down
43 changes: 35 additions & 8 deletions src/web/server.ts → src/web/api/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { createPlugin } from "@ubiquity-os/plugin-sdk";
import { Manifest } from "@ubiquity-os/plugin-sdk/manifest";
import { LogLevel } from "@ubiquity-os/ubiquity-os-logger";
import { ExecutionContext } from "hono";
import { serveStatic } from "hono/bun";
import manifest from "../../manifest.json";
import { IssueActivity } from "../issue-activity";
import { Processor } from "../parser/processor";
import { parseGitHubUrl } from "../start";
import envConfigSchema, { EnvConfig } from "../types/env-type";
import { PluginSettings, pluginSettingsSchema, SupportedEvents } from "../types/plugin-input";
import manifest from "../../../manifest.json";
import { IssueActivity } from "../../issue-activity";
import { Processor } from "../../parser/processor";
import { parseGitHubUrl } from "../../start";
import envConfigSchema, { EnvConfig } from "../../types/env-type";
import { PluginSettings, pluginSettingsSchema, SupportedEvents } from "../../types/plugin-input";

const app = createPlugin<PluginSettings, EnvConfig, SupportedEvents>(
const baseApp = createPlugin<PluginSettings, EnvConfig, SupportedEvents>(
async (context) => {
const { payload } = context;
const issue = parseGitHubUrl(payload.issue.html_url);
Expand All @@ -31,7 +32,32 @@ const app = createPlugin<PluginSettings, EnvConfig, SupportedEvents>(
}
);

// You will need to build the client code first `bun run ui:build`
const app = {
fetch: async (request: Request, env: object, ctx: ExecutionContext) => {
if (request.method === "POST" && new URL(request.url).pathname === "/") {
console.log("Pre-processing POST / request");
// read config file
// create JSON body from FE received body
// disable open ai routes accordingly?

// Clone the request since we need to read it twice
const clonedRequest = request.clone();
try {
const body = await clonedRequest.json();
console.log("Request body:", body);
} catch (error) {
console.error(error);
return new Response("Invalid JSON", { status: 400 });
}
}
return baseApp.fetch(request, env, ctx);
},
use: baseApp.use.bind(baseApp),
post: baseApp.post.bind(baseApp),
get: baseApp.get.bind(baseApp),
};

// Serves the statically compiled frontend
app.use(
"/*",
serveStatic({
Expand All @@ -40,6 +66,7 @@ app.use(
})
);

// Fakes OpenAi routes
app.post("/openai/*", async (c) => {
const text = await c.req.json();
const regex = /START EVALUATING:\s*\[([\s\S]*?)]/g;
Expand Down
240 changes: 240 additions & 0 deletions src/web/api/payload.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,240 @@
export function getPayload(ownerRepo: string, issueId: number, useOpenAi = false) {
return {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
ref: "development",
stateId: "1234",
signature: "",
eventName: "issues.closed",
action: "closed",
env: {
SUPABASE_URL: "http://localhost:5432",
SUPABASE__KEY: "1234",
},
settings: {
evmPrivateEncrypted:
"YfEnpznMNbSPhCQzWy1Uevi4xQC25SqJrHd87CjjS1gsu92QrCReSgvl8Z_pVI1ZM57PNC1mZSgHbNgX9ITmOJc6qaOJ_mRe_sP_8jBcNimusDCQcWEkcPIW7Md-QGDPnwuN8FIavS7I0uiOIRYK6h0NK02-3uzPqhM",
incentives: {
userExtractor: {},
dataPurge: {},
formattingEvaluator: {},
contentEvaluator: {
...(!useOpenAi && {
openAi: {
endpoint: "http://localhost:3000/openai",
},
}),
},
permitGeneration: null,
githubComment: {
post: true,
debug: false,
},
},
},
authToken: import.meta.env.VITE_GITHUB_TOKEN,
eventPayload: {
issue: {
state_reason: "completed",
url: `https://api.github.com/repos/${ownerRepo}/issues/${issueId}`,
repository_url: `https://api.github.com/repos/${ownerRepo}`,
labels_url: `https://api.github.com/repos/${ownerRepo}/issues/${issueId}/labels{/name}`,
comments_url: `https://api.github.com/repos/${ownerRepo}/issues/${issueId}/comments`,
events_url: `https://api.github.com/repos/${ownerRepo}/issues/${issueId}/events`,
html_url: `https://github.com/${ownerRepo}/issues/${issueId}`,
id: 1,
node_id: "MDU6SXNzdWUx",
number: issueId,
title: "Found a bug",
user: {
login: "ubiquity-os",
id: 1,
node_id: "MDQ6VXNlcjE=",
avatar_url: "https://github.com/images/error/ubiquity-os_happy.gif",
gravatar_id: "",
url: "https://api.github.com/users/ubiquity-os",
html_url: "https://github.com/ubiquity-os",
followers_url: "https://api.github.com/users/ubiquity-os/followers",
following_url: "https://api.github.com/users/ubiquity-os/following{/other_user}",
gists_url: "https://api.github.com/users/ubiquity-os/gists{/gist_id}",
starred_url: "https://api.github.com/users/ubiquity-os/starred{/owner}{/repo}",
subscriptions_url: "https://api.github.com/users/ubiquity-os/subscriptions",
organizations_url: "https://api.github.com/users/ubiquity-os/orgs",
repos_url: "https://api.github.com/users/ubiquity-os/repos",
events_url: "https://api.github.com/users/ubiquity-os/events{/privacy}",
received_events_url: "https://api.github.com/users/ubiquity-os/received_events",
type: "User",
site_admin: false,
},
state: "closed",
locked: false,
assignee: {
login: "ubiquity-os",
id: 1,
node_id: "MDQ6VXNlcjE=",
avatar_url: "https://github.com/images/error/ubiquity-os_happy.gif",
gravatar_id: "",
url: "https://api.github.com/users/ubiquity-os",
html_url: "https://github.com/ubiquity-os",
followers_url: "https://api.github.com/users/ubiquity-os/followers",
following_url: "https://api.github.com/users/ubiquity-os/following{/other_user}",
gists_url: "https://api.github.com/users/ubiquity-os/gists{/gist_id}",
starred_url: "https://api.github.com/users/ubiquity-os/starred{/owner}{/repo}",
subscriptions_url: "https://api.github.com/users/ubiquity-os/subscriptions",
organizations_url: "https://api.github.com/users/ubiquity-os/orgs",
repos_url: "https://api.github.com/users/ubiquity-os/repos",
events_url: "https://api.github.com/users/ubiquity-os/events{/privacy}",
received_events_url: "https://api.github.com/users/ubiquity-os/received_events",
type: "User",
site_admin: false,
},
labels: [
{
id: 208045946,
node_id: "MDU6TGFiZWwyMDgwNDU5NDY=",
url: `https://api.github.com/repos/${ownerRepo}/labels/bug`,
name: "bug",
description: "Something isn't working",
color: "f29513",
default: true,
},
],
comments: 0,
created_at: "2011-04-22T13:33:48Z",
updated_at: "2011-04-22T13:33:48Z",
closed_at: "2011-04-22T13:33:48Z",
author_association: "OWNER",
body: "I'm having a problem with this.",
},
repository: {
id: 1296269,
node_id: "MDEwOlJlcG9zaXRvcnkxMjk2MjY5",
name: "conversation-rewards",
full_name: "ubiquity-os/conversation-rewards",
owner: {
login: "ubiquity-os",
id: 159901852,
node_id: "MDQ6VXNlcjE=",
avatar_url: "https://github.com/images/error/ubiquity-os_happy.gif",
gravatar_id: "",
url: "https://api.github.com/users/ubiquity-os",
html_url: "https://github.com/ubiquity-os",
followers_url: "https://api.github.com/users/ubiquity-os/followers",
following_url: "https://api.github.com/users/ubiquity-os/following{/other_user}",
gists_url: "https://api.github.com/users/ubiquity-os/gists{/gist_id}",
starred_url: "https://api.github.com/users/ubiquity-os/starred{/owner}{/repo}",
subscriptions_url: "https://api.github.com/users/ubiquity-os/subscriptions",
organizations_url: "https://api.github.com/users/ubiquity-os/orgs",
repos_url: "https://api.github.com/users/ubiquity-os/repos",
events_url: "https://api.github.com/users/ubiquity-os/events{/privacy}",
received_events_url: "https://api.github.com/users/ubiquity-os/received_events",
type: "User",
site_admin: false,
},
private: false,
html_url: "https://github.com/ubiquity-os/conversation-rewards",
description: "This your first repo!",
fork: false,
url: "https://api.github.com/repos/ubiquity-os/conversation-rewards",
archive_url: "https://api.github.com/repos/ubiquity-os/conversation-rewards/{archive_format}{/ref}",
assignees_url: "https://api.github.com/repos/ubiquity-os/conversation-rewards/assignees{/user}",
blobs_url: "https://api.github.com/repos/ubiquity-os/conversation-rewards/git/blobs{/sha}",
branches_url: "https://api.github.com/repos/ubiquity-os/conversation-rewards/branches{/branch}",
collaborators_url:
"https://api.github.com/repos/ubiquity-os/conversation-rewards/collaborators{/collaborator}",
comments_url: "https://api.github.com/repos/ubiquity-os/conversation-rewards/comments{/number}",
commits_url: "https://api.github.com/repos/ubiquity-os/conversation-rewards/commits{/sha}",
compare_url: "https://api.github.com/repos/ubiquity-os/conversation-rewards/compare/{base}...{head}",
contents_url: "https://api.github.com/repos/ubiquity-os/conversation-rewards/contents/{+path}",
contributors_url: "https://api.github.com/repos/ubiquity-os/conversation-rewards/contributors",
deployments_url: "https://api.github.com/repos/ubiquity-os/conversation-rewards/deployments",
downloads_url: "https://api.github.com/repos/ubiquity-os/conversation-rewards/downloads",
events_url: "https://api.github.com/repos/ubiquity-os/conversation-rewards/events",
forks_url: "https://api.github.com/repos/ubiquity-os/conversation-rewards/forks",
git_commits_url: "https://api.github.com/repos/ubiquity-os/conversation-rewards/git/commits{/sha}",
git_refs_url: "https://api.github.com/repos/ubiquity-os/conversation-rewards/git/refs{/sha}",
git_tags_url: "https://api.github.com/repos/ubiquity-os/conversation-rewards/git/tags{/sha}",
git_url: "git:github.com/ubiquity-os/conversation-rewards.git",
issue_comment_url: "https://api.github.com/repos/ubiquity-os/conversation-rewards/issues/comments{/number}",
issue_events_url: "https://api.github.com/repos/ubiquity-os/conversation-rewards/issues/events{/number}",
issues_url: "https://api.github.com/repos/ubiquity-os/conversation-rewards/issues{/number}",
keys_url: "https://api.github.com/repos/ubiquity-os/conversation-rewards/keys{/key_id}",
labels_url: "https://api.github.com/repos/ubiquity-os/conversation-rewards/labels{/name}",
languages_url: "https://api.github.com/repos/ubiquity-os/conversation-rewards/languages",
merges_url: "https://api.github.com/repos/ubiquity-os/conversation-rewards/merges",
milestones_url: "https://api.github.com/repos/ubiquity-os/conversation-rewards/milestones{/number}",
notifications_url:
"https://api.github.com/repos/ubiquity-os/conversation-rewards/notifications{?since,all,participating}",
pulls_url: "https://api.github.com/repos/ubiquity-os/conversation-rewards/pulls{/number}",
releases_url: "https://api.github.com/repos/ubiquity-os/conversation-rewards/releases{/id}",
stargazers_url: "https://api.github.com/repos/ubiquity-os/conversation-rewards/stargazers",
statuses_url: "https://api.github.com/repos/ubiquity-os/conversation-rewards/statuses/{sha}",
subscribers_url: "https://api.github.com/repos/ubiquity-os/conversation-rewards/subscribers",
subscription_url: "https://api.github.com/repos/ubiquity-os/conversation-rewards/subscription",
tags_url: "https://api.github.com/repos/ubiquity-os/conversation-rewards/tags",
teams_url: "https://api.github.com/repos/ubiquity-os/conversation-rewards/teams",
trees_url: "https://api.github.com/repos/ubiquity-os/conversation-rewards/git/trees{/sha}",
homepage: "https://github.com",
language: null,
forks_count: 9,
stargazers_count: 80,
watchers_count: 80,
size: 108,
default_branch: "master",
open_issues_count: 0,
is_template: false,
topics: [],
has_issues: true,
has_projects: true,
has_wiki: true,
has_pages: false,
has_downloads: true,
archived: false,
disabled: false,
visibility: "public",
pushed_at: "2011-01-26T19:06:43Z",
created_at: "2011-01-26T19:01:12Z",
updated_at: "2011-01-26T19:14:43Z",
permissions: {
admin: false,
maintain: false,
push: false,
triage: false,
pull: true,
},
allow_rebase_merge: true,
temp_clone_token: "",
allow_squash_merge: true,
allow_auto_merge: false,
delete_branch_on_merge: true,
allow_merge_commit: true,
subscribers_count: 42,
network_count: 0,
},
sender: {
login: "ubiquity-os",
id: 159901852,
node_id: "MDQ6VXNlcjE=",
avatar_url: "https://github.com/images/error/ubiquity-os_happy.gif",
gravatar_id: "",
url: "https://api.github.com/users/ubiquity-os",
html_url: "https://github.com/ubiquity-os",
followers_url: "https://api.github.com/users/ubiquity-os/followers",
following_url: "https://api.github.com/users/ubiquity-os/following{/other_user}",
gists_url: "https://api.github.com/users/ubiquity-os/gists{/gist_id}",
starred_url: "https://api.github.com/users/ubiquity-os/starred{/owner}{/repo}",
subscriptions_url: "https://api.github.com/users/ubiquity-os/subscriptions",
organizations_url: "https://api.github.com/users/ubiquity-os/orgs",
repos_url: "https://api.github.com/users/ubiquity-os/repos",
events_url: "https://api.github.com/users/ubiquity-os/events{/privacy}",
received_events_url: "https://api.github.com/users/ubiquity-os/received_events",
type: "User",
site_admin: false,
},
},
}),
};
}
Loading

0 comments on commit dfd04f5

Please sign in to comment.