Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deleted files #291

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
});
});