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

Merge development into main #203

Merged
merged 39 commits into from
Nov 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
8e8fc82
feat: track unique URLs in formatting evaluator
gentlementlegen Nov 17, 2024
ab0b831
Merge branch 'feat/webpage' into fix/link-credit
gentlementlegen Nov 19, 2024
5eb31af
chore: update src/parser/content-evaluator-module.ts
gentlementlegen Nov 19, 2024
9bb7e94
chore: updated manifest.json and dist build
github-actions[bot] Nov 19, 2024
bab7d21
chore: updated manifest.json and dist build
github-actions[bot] Nov 19, 2024
ab2f9be
fix(parser): remove footnotes and improve URL extraction
gentlementlegen Nov 19, 2024
c0e6650
Merge remote-tracking branch 'origin/fix/link-credit' into fix/link-c…
gentlementlegen Nov 19, 2024
706bb32
chore: updated manifest.json and dist build
github-actions[bot] Nov 19, 2024
320ecb8
refactor: reuse urlRegex in parsing logic
gentlementlegen Nov 19, 2024
8bd5c28
chore: updated manifest.json and dist build
github-actions[bot] Nov 19, 2024
78546ce
refactor: simplify reward split result mock file
gentlementlegen Nov 19, 2024
9ff6ba9
feat(rewards): add limitRewards to cap non-task rewards
gentlementlegen Nov 19, 2024
1944449
chore: updated manifest.json and dist build
github-actions[bot] Nov 19, 2024
b01dc77
fix: add useCache option to payload processing
gentlementlegen Nov 19, 2024
b64d54a
Merge branch 'development' into fix/link-credit
gentlementlegen Nov 19, 2024
f804ea5
Merge branch 'fix/link-credit' into feat/reward-limit
gentlementlegen Nov 19, 2024
133dcdf
chore: replace env
gentlementlegen Nov 19, 2024
1925cb9
feat: command interface
whilefoo Nov 20, 2024
6b3a53b
feat: command input
whilefoo Nov 21, 2024
56d81ea
chore: upgrade sdk
whilefoo Nov 24, 2024
6cef4b7
chore: remove tsx
whilefoo Nov 24, 2024
f3bec94
chore: trigger actions
whilefoo Nov 24, 2024
cd42282
fix: payload for backend uses the owner and repo payload
gentlementlegen Nov 25, 2024
73c9ca3
Merge pull request #200 from gentlementlegen/fix/payload
0x4007 Nov 25, 2024
c7b55dc
fix(parser): handle URLs with query parameters correctly
gentlementlegen Nov 25, 2024
26dc72e
chore: updated manifest.json and dist build
github-actions[bot] Nov 25, 2024
ac3b1da
Merge pull request #198 from ubiquity-whilefoo/command-interface
gentlementlegen Nov 25, 2024
9831cdf
chore: updated manifest.json and dist build
ubiquity-os[bot] Nov 25, 2024
f8af8a3
Merge branch 'development' into fix/link-credit
gentlementlegen Nov 25, 2024
90a648b
chore: updated manifest.json and dist build
github-actions[bot] Nov 25, 2024
74efe55
Merge pull request #188 from gentlementlegen/fix/link-credit
gentlementlegen Nov 26, 2024
8cbee7c
Merge branch 'development' into feat/reward-limit
gentlementlegen Nov 26, 2024
0ff3824
chore: updated manifest.json and dist build
github-actions[bot] Nov 26, 2024
171f523
fix(reward-limits): adjust rewards limit calculation
gentlementlegen Nov 26, 2024
e656884
chore: updated manifest.json and dist build
github-actions[bot] Nov 26, 2024
1186e77
Update src/types/plugin-input.ts
gentlementlegen Nov 29, 2024
950ff17
chore: updated manifest.json and dist build
github-actions[bot] Nov 29, 2024
9981d32
Merge pull request #195 from gentlementlegen/feat/reward-limit
gentlementlegen Nov 29, 2024
4810e4d
chore: changed yarn to bun in formatting-checks.yml
gentlementlegen Nov 30, 2024
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 .github/workflows/compute.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ on:
description: "Ref"
signature:
description: "Payload signature from the kernel"
command:
description: "Command"

jobs:
compute:
Expand Down
13 changes: 5 additions & 8 deletions .github/workflows/formatting-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,11 @@ jobs:
- name: Checkout code
uses: actions/checkout@v4

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

- name: Run formatting checks
run: |
yarn install
yarn eslint --fix-dry-run --ignore-pattern dist/
yarn format:cspell
yarn prettier --check .
bun install
bun eslint --fix-dry-run --ignore-pattern dist/
bun format:cspell
bun prettier --check .
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ static/dist
junit.xml
coverage
test-dashboard.md
*.private.env.json
*.private.env.json
output.html
Binary file modified bun.lockb
Binary file not shown.
6 changes: 3 additions & 3 deletions dist/index.js

Large diffs are not rendered by default.

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", "dist/", "tests/__mocks__/**", "coverage/**"],
ignores: [".github/knip.ts", "dist/", "tests/__mocks__/**", "coverage/**", "dist/**"],
extends: [eslint.configs.recommended, ...tsEslint.configs.recommended, sonarjs.configs.recommended],
languageOptions: {
parser: tsEslint.parser,
Expand Down
2 changes: 1 addition & 1 deletion knip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const config: KnipConfig = {
project: ["src/**/*.ts"],
ignore: ["src/data-collection/examples/*.ts", "src/configuration/common-config-type.ts", "dist/**"],
ignoreExportsUsedInFile: true,
ignoreDependencies: ["ts-node", "msw", "@mswjs/data", "@octokit/plugin-paginate-graphql"],
ignoreDependencies: ["ts-node", "msw", "@mswjs/data"],
jest: {
config: ["jest.config.ts"],
entry: ["src/**/*.test.ts"],
Expand Down
5 changes: 5 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@
"default": true,
"type": "boolean"
},
"limitRewards": {
"default": true,
"description": "Should the rewards of non-assignees be limited to the task reward?",
"type": "boolean"
},
"contentEvaluator": {
"default": null,
"anyOf": [
Expand Down
11 changes: 4 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"type": "module",
"scripts": {
"test": "cross-env NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" jest --setupFiles dotenv/config --coverage",
"start": "tsx src/index.ts",
"format": "run-s format:lint format:prettier format:cspell",
"format:lint": "eslint --fix .",
"format:prettier": "prettier --write .",
Expand All @@ -31,22 +30,19 @@
"@actions/github": "^6.0.0",
"@octokit/graphql-schema": "^15.25.0",
"@octokit/rest": "^21.0.2",
"@sinclair/typebox": "^0.33.21",
"@sinclair/typebox": "0.34.3",
"@supabase/supabase-js": "2.42.0",
"@ubiquity-dao/rpc-handler": "1.3.0",
"@ubiquity-os/permit-generation": "^2.0.6",
"@ubiquity-os/plugin-sdk": "^1.0.11",
"@ubiquity-os/plugin-sdk": "^1.1.0",
"@ubiquity-os/ubiquity-os-logger": "^1.3.2",
"@octokit/plugin-paginate-graphql": "^5.2.4",
"decimal.js": "10.4.3",
"ethers": "^5.7.2",
"js-tiktoken": "1.0.15",
"jsdom": "24.0.0",
"markdown-it": "14.1.0",
"openai": "4.56.0",
"ts-jest": "^29.2.5",
"tsx": "4.7.1",
"yaml": "^2.6.0"
"yaml": "^2.6.1"
},
"devDependencies": {
"@babel/core": "7.23.9",
Expand Down Expand Up @@ -83,6 +79,7 @@
"sqlite": "^5.1.1",
"sqlite3": "^5.1.7",
"ts-node": "10.9.2",
"ts-jest": "^29.2.5",
"typescript": "^5.6.3",
"typescript-eslint": "^8.13.0"
},
Expand Down
1 change: 1 addition & 0 deletions src/configuration/formatting-evaluator-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const commentType = stringLiteralUnion(
);

export const wordRegex = /\b\w+\b/;
export const urlRegex = /https?:\/\/\S+/g;

const htmlEntity = Type.Object({
score: Type.Number(),
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { run } from "./run";
import envConfigSchema, { EnvConfig } from "./types/env-type";
import { PluginSettings, pluginSettingsSchema, SupportedEvents } from "./types/plugin-input";

export default createActionsPlugin<PluginSettings, EnvConfig, SupportedEvents>(
export default createActionsPlugin<PluginSettings, EnvConfig, null, SupportedEvents>(
(context) => {
return run(context);
},
Expand Down
2 changes: 1 addition & 1 deletion src/parser/content-evaluator-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export class ContentEvaluatorModule extends BaseModule {
);

if (Object.keys(relevancesByAi).length !== commentsToEvaluate.length + prCommentsToEvaluate.length) {
throw this.context.logger.fatal("Relevance / Comment length mismatch!", {
throw this.context.logger.error("Relevance / Comment length mismatch!", {
relevancesByAi,
commentsToEvaluate,
prCommentsToEvaluate,
Expand Down
2 changes: 2 additions & 0 deletions src/parser/data-purge-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ export class DataPurgeModule extends BaseModule {
.replace(/^\/.+/g, "")
// Remove HTML comments
.replace(/<!--[\s\S]*?-->/g, "")
// Remove the footnotes
.replace(/^###### .*?\[\^\d+\^][\s\S]*$/gm, "")
// Keep only one new line needed by markdown-it package to convert to html
.replace(/\n\s*\n/g, "\n")
.trim();
Expand Down
23 changes: 21 additions & 2 deletions src/parser/formatting-evaluator-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { commentEnum, CommentType } from "../configuration/comment-types";
import {
FormattingEvaluatorConfiguration,
formattingEvaluatorConfigurationType,
urlRegex,
wordRegex,
} from "../configuration/formatting-evaluator-config";
import { IssueActivity } from "../issue-activity";
Expand Down Expand Up @@ -151,6 +152,7 @@ export class FormattingEvaluatorModule extends BaseModule {
_classifyTagsWithWordCount(htmlElement: HTMLElement, commentType: GithubCommentScore["type"]) {
const formatting: Record<string, { score: number; elementCount: number }> = {};
const elements = htmlElement.getElementsByTagName("*");
const urlSet = new Set<string>();

for (const element of elements) {
const tagName = element.tagName.toLowerCase();
Expand All @@ -168,9 +170,26 @@ export class FormattingEvaluatorModule extends BaseModule {
element.remove();
continue;
}
this._updateTagCount(formatting, tagName, score);
if (tagName === "a") {
const url = element.getAttribute("href");
if (url) {
urlSet.add(url.split(/[#?]/)[0]);
}
} else {
const bodyContent = element.textContent;
const matches = bodyContent?.match(urlRegex);
matches?.map((url) => url.split(/[#?]/)[0]).forEach((url) => urlSet.add(url));
this._updateTagCount(formatting, tagName, score);
}
}
const words = this._countWordsFromRegex(htmlElement.textContent ?? "", this._multipliers[commentType]?.wordValue);
urlSet.forEach(() => {
this._updateTagCount(formatting, "a", this._multipliers[commentType].html["a"].score ?? 0);
});
const words = this._countWordsFromRegex(
htmlElement.textContent?.replace(urlRegex, "") ?? "",
this._multipliers[commentType]?.wordValue
);

return { formatting, words };
}

Expand Down
26 changes: 21 additions & 5 deletions src/parser/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,28 @@ export class Processor {
return this;
}

_getRewardsLimit() {
let taskReward = Infinity;
if (!this._configuration.limitRewards) {
return taskReward;
}
for (const item of Object.keys(this._result)) {
if (this._result[item].task) {
taskReward = this._result[item].task.reward * this._result[item].task.multiplier;
return taskReward;
}
}
return taskReward;
}

async run(data: Readonly<IssueActivity>) {
for (const transformer of this._transformers) {
if (transformer.enabled) {
this._result = await transformer.transform(data, this._result);
}
// Aggregate total result
for (const item of Object.keys(this._result)) {
this._result[item].total = this._sumRewards(this._result[item]);
this._result[item].total = this._sumRewards(this._result[item], this._getRewardsLimit());
}
}
return this._result;
Expand All @@ -51,21 +65,23 @@ export class Processor {
const { file } = this._configuration;
const result = JSON.stringify(this._result, typeReplacer, 2);
if (!file) {
this._context.logger.debug(result);
this._context.logger.verbose(result);
} else {
fs.writeFileSync(file, result);
}
return result;
}

_sumRewards(obj: Record<string, unknown>) {
_sumRewards(obj: Record<string, unknown>, taskRewardLimit = Infinity) {
let totalReward = new Decimal(0);

for (const [key, value] of Object.entries(obj)) {
if (key === "reward" && typeof value === "number") {
totalReward = totalReward.add(value);
totalReward = totalReward.add(Math.min(value, taskRewardLimit));
} else if (typeof value === "object") {
totalReward = totalReward.add(this._sumRewards(value as Record<string, unknown>));
totalReward = totalReward.add(
Math.min(this._sumRewards(value as Record<string, unknown>, taskRewardLimit), taskRewardLimit)
);
}
}

Expand Down
6 changes: 5 additions & 1 deletion src/types/plugin-input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ export const pluginSettingsSchema = T.Object(
* If set to false, the plugin runs even if the price label is missing, and will evaluate comments.
*/
requirePriceLabel: T.Boolean({ default: true }),
limitRewards: T.Boolean({
default: true,
description: "Should the rewards of non-assignees be limited to the task reward?",
}),
contentEvaluator: T.Union([contentEvaluatorConfigurationType, T.Null()], { default: null }),
userExtractor: T.Union([userExtractorConfigurationType, T.Null()], { default: null }),
dataPurge: T.Union([dataPurgeConfigurationType, T.Null()], { default: null }),
Expand All @@ -50,4 +54,4 @@ export const pluginSettingsSchema = T.Object(
export type PluginSettings = StaticDecode<typeof pluginSettingsSchema>;

export type SupportedEvents = "issues.closed";
export type ContextPlugin = Context<PluginSettings, EnvConfig, SupportedEvents>;
export type ContextPlugin = Context<PluginSettings, EnvConfig, null, SupportedEvents>;
8 changes: 6 additions & 2 deletions src/web/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ const baseApp = createPlugin<PluginSettings, EnvConfig, SupportedEvents>(

const app = {
fetch: async (request: Request, env: object, ctx: ExecutionContext) => {
if (request.method === "POST" && new URL(request.url).pathname === "/") {
if (
request.method === "POST" &&
new URL(request.url).pathname === "/" &&
request.headers.get("origin") === "http://localhost:4000"
) {
try {
const originalBody = await request.json();
const modifiedBody = await getPayload(
Expand Down Expand Up @@ -108,7 +112,7 @@ app.get("/openai/*", () => {
return Response.json("OpenAI GET");
});

const port = 3000;
const port = 4000;

export default {
fetch: app.fetch,
Expand Down
Loading
Loading