Skip to content

Commit

Permalink
feat: mul the reward by priority
Browse files Browse the repository at this point in the history
  • Loading branch information
ishowvel committed Dec 18, 2024
1 parent e4d52d9 commit 81b1595
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 21 deletions.
16 changes: 4 additions & 12 deletions src/parser/github-comment-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ export class GithubCommentModule extends BaseModule {
content.push(buildContributionRow("Issue", "Task", result.task.multiplier, result.task.reward));
}

if (result.reviewReward && this.context.config.incentives.reviewIncentivizer?.baseRate) {
if (result.reviewReward) {
if (result.reviewReward.reviewBaseReward?.reward) {
content.push(buildContributionRow("Review", "Base Review", 1, result.reviewReward.reviewBaseReward.reward));
}
Expand All @@ -194,14 +194,7 @@ export class GithubCommentModule extends BaseModule {
result.reviewReward.reviews?.reduce((sum, review) => sum.add(review.reward), new Decimal(0)) ?? new Decimal(0);

if (reviewCount > 0) {
content.push(
buildContributionRow(
"Review",
"Code Review",
reviewCount,
totalReviewReward.toNumber() / this.context.config.incentives.reviewIncentivizer?.baseRate
)
);
content.push(buildContributionRow("Review", "Code Review", reviewCount, totalReviewReward.toNumber()));
}
}

Expand Down Expand Up @@ -288,16 +281,15 @@ export class GithubCommentModule extends BaseModule {
}

_createReviewRows(result: Result[0]) {
if (!result.reviewReward?.reviews?.length || !this.context.config.incentives.reviewIncentivizer?.baseRate) {
if (!result.reviewReward?.reviews?.length) {
return "";
}
const baseRate = this.context.config.incentives.reviewIncentivizer?.baseRate;
function buildReviewRow(review: ReviewScore) {
return `
<tr>
<td>+${review.effect.addition} -${review.effect.deletion}</td>
<td>${review.priority ?? "-"}</td>
<td>${(review.effect.addition + review.effect.deletion) / baseRate}</td>
<td>${review.reward}</td>
</tr>`;
}

Expand Down
13 changes: 4 additions & 9 deletions src/parser/review-incentivizer-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ export class ReviewIncentivizerModule extends BaseModule {
issue_number: data.self?.number,
})
).slice(-1)[0].number;

this.context.logger.info(`Pull request ${linkedPullNumber} is linked to this issue`);

const linkedPullReviews = await getPullRequestReviews(this.context, {
owner: owner,
repo: repo,
Expand Down Expand Up @@ -117,7 +120,7 @@ export class ReviewIncentivizerModule extends BaseModule {
reviews.push({
reviewId: currentReview.id,
effect: reviewEffect,
reward: reviewEffect.addition + reviewEffect.deletion,
reward: ((reviewEffect.addition + reviewEffect.deletion) * priority) / this._baseRate,
priority: priority,
});
} catch (e) {
Expand All @@ -130,14 +133,6 @@ export class ReviewIncentivizerModule extends BaseModule {
return reviews;
}

async calculateReviewsDiffReward(reviews: ReviewScore[]) {
let reviewReward = 0;
for (const review of reviews) {
reviewReward += review.effect.addition + review.effect.deletion;
}
return reviewReward / this._baseRate;
}

get enabled(): boolean {
if (!Value.Check(reviewIncentivizerConfigurationType, this._configuration)) {
this.context.logger.error("Invalid / missing configuration detected for ReviewIncentivizerModule, disabling.");
Expand Down

0 comments on commit 81b1595

Please sign in to comment.