Skip to content

Commit

Permalink
Merge pull request #291 from ishowvel/deleted-files
Browse files Browse the repository at this point in the history
Deleted files
  • Loading branch information
gentlementlegen authored Mar 1, 2025
2 parents 0e7c900 + 97c9546 commit 1fb1ea1
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 6 deletions.
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions src/parser/review-incentivizer-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ export class ReviewIncentivizerModule extends BaseModule {
const diff: CommitDiff = {};

for (const file of files) {
if (file.status === "removed") continue;
diff[file.filename] = {
addition: file.additions || 0,
deletion: file.deletions || 0,
Expand All @@ -97,6 +98,7 @@ export class ReviewIncentivizerModule extends BaseModule {

return diff;
}

async getReviewableDiff(
owner: string,
repo: string,
Expand Down
17 changes: 12 additions & 5 deletions tests/process.issue.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import permitGenerationResults from "./__mocks__/results/permit-generation-resul
import reviewIncentivizerResult from "./__mocks__/results/review-incentivizer-results.json";
import userCommentResults from "./__mocks__/results/user-comment-results.json";
import cfg from "./__mocks__/results/valid-configuration.json";
import { RestEndpointMethodTypes } from "@octokit/rest";

const issueUrl = process.env.TEST_ISSUE_URL ?? "https://github.com/ubiquity-os/conversation-rewards/issues/5";

Expand Down Expand Up @@ -215,13 +216,19 @@ describe("Modules tests", () => {
.spyOn(ContentEvaluatorModule.prototype, "_getRateLimitTokens")
.mockImplementation(() => Promise.resolve(Infinity));

jest.spyOn(ReviewIncentivizerModule.prototype, "getTripleDotDiffAsObject").mockImplementation(async () => {
jest.spyOn(ctx.octokit.rest.repos, "compareCommits").mockImplementation(async () => {
return {
"test.txt": {
addition: 50,
deletion: 50,
data: {
files: [
{
filename: "test.txt",
additions: 50,
deletions: 50,
status: "added",
},
],
},
};
} as unknown as RestEndpointMethodTypes["repos"]["compareCommits"]["response"];
});
});

Expand Down
45 changes: 45 additions & 0 deletions tests/review-incentivizer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { db, db as mockDb } from "./__mocks__/db";
import { server } from "./__mocks__/node";
import Mock = jest.Mock;
import { drop } from "@mswjs/data";
import { RestEndpointMethodTypes } from "@octokit/rest";

const ctx = {
eventName: "issues.closed",
Expand Down Expand Up @@ -133,4 +134,48 @@ describe("Review Incentivizer", () => {
expect(spy).not.toHaveBeenCalled();
spy.mockClear();
});

it("Should skip removed files in review incentives diff calculation", async () => {
jest.spyOn(ctx.octokit.rest.repos, "compareCommits").mockImplementationOnce(async () => {
return {
data: {
files: [
{
filename: "added.txt",
additions: 10,
deletions: 5,
status: "added",
},
{
filename: "modified.txt",
additions: 20,
deletions: 10,
status: "modified",
},
{
filename: "removed.txt",
additions: 0,
deletions: 30,
status: "removed",
},
],
},
} as unknown as RestEndpointMethodTypes["repos"]["compareCommits"]["response"];
});

const { ReviewIncentivizerModule } = await import("../src/parser/review-incentivizer-module");
const reviewIncentivizerModule = new ReviewIncentivizerModule(ctx);

const diff = await reviewIncentivizerModule.getTripleDotDiffAsObject(
"ubiquity-os",
"conversation-rewards",
"base",
"head"
);

expect(Object.keys(diff).length).toBe(2);
expect(diff["added.txt"]).toEqual({ addition: 10, deletion: 5 });
expect(diff["modified.txt"]).toEqual({ addition: 20, deletion: 10 });
expect(diff["removed.txt"]).toEqual(undefined);
});
});

0 comments on commit 1fb1ea1

Please sign in to comment.