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

feat: conversation rewards #38

Merged
Show file tree
Hide file tree
Changes from 8 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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,5 @@ static/dist
keys
coverage
junit.xml

*.pem
Binary file modified bun.lockb
100755 → 100644
Binary file not shown.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
},
"scripts": {
"dev": "run-p worker proxy",
"predev": "lsof -i tcp:8787 | grep LISTEN | awk '{print $2}' | (if [ -n \"$(awk '{print $2}')\" ]; then xargs kill -9; fi)",
"predev": "tsx predev.ts",
"format": "run-s format:lint format:prettier format:cspell",
"format:lint": "eslint --fix .",
"format:prettier": "prettier --write .",
Expand Down Expand Up @@ -85,5 +85,5 @@
"@commitlint/config-conventional"
]
},
"packageManager": "bun@1.0.23"
"packageManager": "bun@1.1.0"
}
30 changes: 30 additions & 0 deletions predev.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { exec } from "child_process";

const port = "8787";

const isWindows = process.platform === "win32";

const command = isWindows ? `netstat -ano | findstr LISTENING | findstr :${port}` : `lsof -i tcp:${port} | grep LISTEN | awk '{print $2}'`;

exec(command, (error, stdout) => {
if (error) {
// The command will also fail on Windows if the process doesn't exist which is expected
console.error(`Error executing command: ${error.message}`);
return;
}

const pid = isWindows ? stdout.trim().split(/\s+/)[4] : stdout.trim();

if (pid) {
const killCommand = isWindows ? `taskkill /F /PID ${pid}` : `kill -9 ${pid}`;
exec(killCommand, (error) => {
if (error) {
console.error(`Error killing process: ${error.message}`);
return;
}
console.log(`Process ${pid} killed successfully.`);
});
} else {
console.log("No process found listening on port 8787.");
}
});
2 changes: 2 additions & 0 deletions src/github/handlers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { issueCommentCreated } from "./issue-comment/created";
import { repositoryDispatch } from "./repository-dispatch";
import { dispatchWorkflow, getDefaultBranch } from "../utils/workflow-dispatch";
import { DelegatedComputeInputs } from "../types/plugin";
import { issuesClosed } from "./issues/closed";

function tryCatchWrapper(fn: (event: EmitterWebhookEvent) => unknown) {
return async (event: EmitterWebhookEvent) => {
Expand All @@ -18,6 +19,7 @@ function tryCatchWrapper(fn: (event: EmitterWebhookEvent) => unknown) {

export function bindHandlers(eventHandler: GitHubEventHandler) {
eventHandler.on("issue_comment.created", issueCommentCreated);
eventHandler.on("issues.closed", issuesClosed);
eventHandler.on("repository_dispatch", repositoryDispatch);
eventHandler.onAny(tryCatchWrapper((event) => handleEvent(event, eventHandler))); // onAny should also receive GithubContext but the types in octokit/webhooks are weird
}
Expand Down
12 changes: 12 additions & 0 deletions src/github/handlers/issues/closed.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { GitHubContext } from "../../github-context";

export async function issuesClosed(event: GitHubContext<"issues.closed">) {
if (event.payload.issue.state_reason === "not_planned") {
gentlementlegen marked this conversation as resolved.
Show resolved Hide resolved
await event.octokit.issues.createComment({
owner: event.payload.repository.owner.login,
repo: event.payload.repository.name,
issue_number: event.payload.issue.number,
body: "Skipping reward generation as the issue was closed as not planned.",
});
}
}
2 changes: 1 addition & 1 deletion src/github/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Type as T } from "@sinclair/typebox";
import { StaticDecode } from "@sinclair/typebox";
import { githubWebhookEvents } from "./webhook-events";

const pluginNameRegex = new RegExp("^([0-9a-zA-Z-._]+)/([0-9a-zA-Z-._]+)(?::([0-9a-zA-Z-._]+))?(?:@([0-9a-zA-Z-._]+))?$");
const pluginNameRegex = new RegExp("^([0-9a-zA-Z-._]+)\\/([0-9a-zA-Z-._]+)(?::([0-9a-zA-Z-._]+))?(?:@([0-9a-zA-Z-._]+(?:\\/[0-9a-zA-Z-._]+)?))?$");
gentlementlegen marked this conversation as resolved.
Show resolved Hide resolved

type GithubPlugin = {
owner: string;
Expand Down
3 changes: 2 additions & 1 deletion src/github/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Config, configSchema } from "../types/config";
import { expressionRegex } from "../types/plugin";
import { eventNames } from "../types/webhook-events";

const UBIQUIBOT_CONFIG_FULL_PATH = ".github/ubiquibot-config.yml";
const UBIQUIBOT_CONFIG_FULL_PATH = ".github/.ubiquibot-config.yml";
gentlementlegen marked this conversation as resolved.
Show resolved Hide resolved

export async function getConfig(context: GitHubContext): Promise<Config | null> {
const payload = context.payload;
Expand Down Expand Up @@ -101,6 +101,7 @@ async function download({ context, repository, owner }: { context: GitHubContext
});
return data as unknown as string; // this will be a string if media format is raw
} catch (err) {
console.error(err);
return null;
}
}
Expand Down
Loading