Skip to content

Commit

Permalink
chore: changed cap to match the issue label price
Browse files Browse the repository at this point in the history
  • Loading branch information
gentlementlegen committed Dec 12, 2024
1 parent a829f25 commit 0da61b1
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 23 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ with:
delayMs: 10000
incentives:
requirePriceLabel: true
limitRewards: true
allowContributorGeneration: false
contentEvaluator:
openAi:
model: "gpt-4o"
Expand Down
14 changes: 3 additions & 11 deletions src/helpers/label-price-extractor.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { GitHubIssue } from "../github-types";
import { Result } from "../types/results";

export function getSortedPrices(labels: GitHubIssue["labels"] | undefined) {
if (!labels) return [];
Expand All @@ -26,20 +25,13 @@ export function getSortedPrices(labels: GitHubIssue["labels"] | undefined) {
* Returns the associated task reward of the issue, based on the final task reward taking into account any multipliers
* applied. If no task reward is found, falls back to the task price. If no task price is found, returns 0.
*/
export function getTaskReward(issue: GitHubIssue | null, result: Result) {
const taskReward = Object.values(result).reduce((acc, curr) => {
if (curr.task) {
return curr.task.reward * curr.task.multiplier;
}
return acc;
}, 0);

if (taskReward === 0 && issue) {
export function getTaskReward(issue: GitHubIssue | null) {
if (issue) {
const sortedPriceLabels = getSortedPrices(issue.labels);
if (sortedPriceLabels.length) {
return sortedPriceLabels[0];
}
}

return taskReward;
return 0;
}
2 changes: 1 addition & 1 deletion src/parser/github-comment-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class GithubCommentModule extends BaseModule {
async getBodyContent(data: Readonly<IssueActivity>, result: Result, stripContent = false): Promise<string> {
const keysToRemove: string[] = [];
const bodyArray: (string | undefined)[] = [];
const taskReward = getTaskReward(data.self, result);
const taskReward = getTaskReward(data.self);

if (stripContent) {
this.context.logger.info("Stripping content due to excessive length.");
Expand Down
18 changes: 7 additions & 11 deletions src/parser/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import { FormattingEvaluatorModule } from "./formatting-evaluator-module";
import { GithubCommentModule } from "./github-comment-module";
import { PermitGenerationModule } from "./permit-generation-module";
import { UserExtractorModule } from "./user-extractor-module";
import { getTaskReward } from "../helpers/label-price-extractor";
import { GitHubIssue } from "../github-types";

export class Processor {
private _transformers: Module[] = [];
Expand All @@ -34,18 +36,12 @@ export class Processor {
return this;
}

_getRewardsLimit() {
let taskReward = Infinity;
_getRewardsLimit(issue: GitHubIssue | null) {
if (!this._configuration.limitRewards) {
return taskReward;
return Infinity;
}
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;
const priceTagReward = getTaskReward(issue);
return priceTagReward || Infinity;
}

async run(data: Readonly<IssueActivity>) {
Expand All @@ -55,7 +51,7 @@ export class Processor {
}
// Aggregate total result
for (const item of Object.keys(this._result)) {
this._result[item].total = this._sumRewards(this._result[item], this._getRewardsLimit());
this._result[item].total = this._sumRewards(this._result[item], this._getRewardsLimit(data.self));
}
}
return this._result;
Expand Down

0 comments on commit 0da61b1

Please sign in to comment.