Skip to content

Commit

Permalink
Merge pull request #158 from ubiquity-os-marketplace/development
Browse files Browse the repository at this point in the history
Merge development into main
  • Loading branch information
gentlementlegen authored Oct 12, 2024
2 parents adde9f8 + 6257029 commit 536eaa3
Show file tree
Hide file tree
Showing 8 changed files with 481 additions and 18 deletions.
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/helpers/constants.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export const GITHUB_PAYLOAD_LIMIT = 65536;
export const GITHUB_COMMENT_PAYLOAD_LIMIT = 65536;
export const GITHUB_DISPATCH_PAYLOAD_LIMIT = 10240;
10 changes: 5 additions & 5 deletions src/parser/content-evaluator-module.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import { Value } from "@sinclair/typebox/value";
import Decimal from "decimal.js";
import { encodingForModel } from "js-tiktoken";
import OpenAI from "openai";
import { commentEnum, CommentKind, CommentType } from "../configuration/comment-types";
import configuration from "../configuration/config-reader";
import { OPENAI_API_KEY } from "../configuration/constants";
import {
ContentEvaluatorConfiguration,
contentEvaluatorConfigurationType,
} from "../configuration/content-evaluator-config";
import { IssueActivity } from "../issue-activity";
import { GithubCommentScore, Module, Result } from "./processor";
import { Value } from "@sinclair/typebox/value";
import { commentEnum, CommentKind, CommentType } from "../configuration/comment-types";
import logger from "../helpers/logger";
import { IssueActivity } from "../issue-activity";
import {
AllComments,
CommentToEvaluate,
openAiRelevanceResponseSchema,
PrCommentToEvaluate,
Relevances,
} from "../types/content-evaluator-module-type";
import { encodingForModel } from "js-tiktoken";
import { GithubCommentScore, Module, Result } from "./processor";

/**
* Evaluates and rates comments.
Expand Down
21 changes: 15 additions & 6 deletions src/parser/formatting-evaluator-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
import logger from "../helpers/logger";
import { IssueActivity } from "../issue-activity";
import { GithubCommentScore, Module, WordResult, Result } from "./processor";
import { typeReplacer } from "../helpers/result-replacer";

interface Multiplier {
multiplier: number;
Expand Down Expand Up @@ -40,11 +41,17 @@ export class FormattingEvaluatorModule implements Module {
this._multipliers = this._configuration.multipliers.reduce((acc, curr) => {
return {
...acc,
[curr.role.reduce((a, b) => this._getEnumValue(b) | a, 0)]: {
html: curr.rewards.html,
multiplier: curr.multiplier,
wordValue: curr.rewards.wordValue,
},
...curr.role.reduce(
(acc, a) => {
acc[this._getEnumValue(a)] = {
html: curr.rewards.html,
multiplier: curr.multiplier,
wordValue: curr.rewards.wordValue,
};
return acc;
},
{} as typeof this._multipliers
),
};
}, {});
}
Expand Down Expand Up @@ -151,7 +158,9 @@ export class FormattingEvaluatorModule implements Module {
continue;
}
} else {
logger.error(`Could not find multiplier for element <${tagName}> in comment [${element.outerHTML}]`);
logger.error(
`Could not find multiplier for element <${tagName}> with association <${typeReplacer("type", commentType)}> in comment [${element.outerHTML}]`
);
element.remove();
continue;
}
Expand Down
6 changes: 3 additions & 3 deletions src/parser/github-comment-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { IssueActivity } from "../issue-activity";
import { getOctokitInstance } from "../octokit";
import program from "./command-line";
import { GithubCommentScore, Module, Result } from "./processor";
import { GITHUB_PAYLOAD_LIMIT } from "../helpers/constants";
import { GITHUB_COMMENT_PAYLOAD_LIMIT } from "../helpers/constants";

interface SortedTasks {
issues: { specification: GithubCommentScore | null; comments: GithubCommentScore[] };
Expand Down Expand Up @@ -79,11 +79,11 @@ export class GithubCommentModule implements Module {

const body = bodyArray.join("");
// We check this length because GitHub has a comment length limit
if (body.length > GITHUB_PAYLOAD_LIMIT) {
if (body.length > GITHUB_COMMENT_PAYLOAD_LIMIT) {
// First, we try to diminish the metadata content to only contain the URL
bodyArray[bodyArray.length - 2] = `\n${getGithubWorkflowRunUrl()}`;
const newBody = bodyArray.join("");
if (newBody.length <= GITHUB_PAYLOAD_LIMIT) {
if (newBody.length <= GITHUB_COMMENT_PAYLOAD_LIMIT) {
return newBody;
} else {
return this.getBodyContent(result, true);
Expand Down
6 changes: 4 additions & 2 deletions src/run.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import configuration from "./configuration/config-reader";
import { collectLinkedMergedPulls } from "./data-collection/collect-linked-pulls";
import { GITHUB_PAYLOAD_LIMIT } from "./helpers/constants";
import { GITHUB_DISPATCH_PAYLOAD_LIMIT } from "./helpers/constants";
import githubCommentModuleInstance from "./helpers/github-comment-module-instance";
import { getSortedPrices } from "./helpers/label-price-extractor";
import logger from "./helpers/logger";
Expand All @@ -22,6 +22,7 @@ export async function run() {
await githubCommentModuleInstance.postComment(result.logMessage.diff);
return result.logMessage.raw;
}
logger.debug("Will use the following configuration:", { configuration });
await githubCommentModuleInstance.postComment(logger.ok("Evaluating results. Please wait...").logMessage.diff);
const issue = parseGitHubUrl(eventPayload.issue.html_url);
const activity = new IssueActivity(issue);
Expand All @@ -34,7 +35,8 @@ export async function run() {
const processor = new Processor();
await processor.run(activity);
let result = processor.dump();
if (result.length > GITHUB_PAYLOAD_LIMIT) {
if (result.length > GITHUB_DISPATCH_PAYLOAD_LIMIT) {
logger.info("Truncating payload as it will trigger an error.");
const resultObject = JSON.parse(result) as Result;
for (const [key, value] of Object.entries(resultObject)) {
resultObject[key] = {
Expand Down
Loading

0 comments on commit 536eaa3

Please sign in to comment.