Skip to content

Commit

Permalink
fix: base branch can be from outside repo and skip review reward for …
Browse files Browse the repository at this point in the history
…pr author
  • Loading branch information
ishowvel committed Jan 23, 2025
1 parent fdcf1bf commit bf1e87e
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions src/parser/review-incentivizer-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ export class ReviewIncentivizerModule extends BaseModule {
return result;
}

const owner = this.context.payload.repository.owner.login;
const repo = this.context.payload.repository.name;

if (data.linkedReviews.length > 1) {
this.context.logger.info(
`Pull requests ${data.linkedReviews.map((review) => review.self?.number)} are linked to this issue`
Expand All @@ -54,19 +51,20 @@ export class ReviewIncentivizerModule extends BaseModule {
reward.reviewRewards = [];

for (const linkedPullReviews of data.linkedReviews) {
if (linkedPullReviews.reviews && linkedPullReviews.self) {
if (linkedPullReviews.reviews && linkedPullReviews.self && username !== linkedPullReviews.self.user.login) {
const reviewsByUser = linkedPullReviews.reviews.filter((v) => v.user?.login === username);

const reviewBaseReward = reviewsByUser.some((v) => v.state === "APPROVED" || v.state === "CHANGES_REQUESTED")
? { reward: this._conclusiveReviewCredit }
: { reward: 0 };
const headOwnerRepo = linkedPullReviews.self.head.repo.full_name;
const reviewDiffs = await this.fetchReviewDiffRewards(owner, repo, reviewsByUser, headOwnerRepo);
const baseOwner = linkedPullReviews.self.base.repo.owner.login;
const baseRepo = linkedPullReviews.self.base.repo.name;
const reviewDiffs = await this.fetchReviewDiffRewards(baseOwner, baseRepo, headOwnerRepo, reviewsByUser);
reward.reviewRewards.push({ reviews: reviewDiffs, url: linkedPullReviews.self.html_url, reviewBaseReward });
}
}
}

return result;
}

Expand Down Expand Up @@ -109,10 +107,10 @@ export class ReviewIncentivizerModule extends BaseModule {
}

async fetchReviewDiffRewards(
owner: string,
repo: string,
reviewsByUser: GitHubPullRequestReviewState[],
headOwnerRepo: string
prOwner: string,
prRepo: string,
headOwnerRepo: string,
reviewsByUser: GitHubPullRequestReviewState[]
) {
if (reviewsByUser.length == 0) {
return;
Expand All @@ -123,8 +121,8 @@ export class ReviewIncentivizerModule extends BaseModule {

const pullCommits = (
await this.context.octokit.rest.pulls.listCommits({
owner: owner,
repo: repo,
owner: prOwner,
repo: prRepo,
pull_number: pullNumber,
})
).data;
Expand All @@ -144,7 +142,7 @@ export class ReviewIncentivizerModule extends BaseModule {

if (headSha && baseSha !== currentReview.commit_id) {
try {
const reviewEffect = await this.getReviewableDiff(owner, repo, baseSha, headSha, excludedFilePatterns);
const reviewEffect = await this.getReviewableDiff(prOwner, prRepo, baseSha, headSha, excludedFilePatterns);
reviews.push({
reviewId: currentReview.id,
effect: reviewEffect,
Expand Down

0 comments on commit bf1e87e

Please sign in to comment.