Skip to content

Commit

Permalink
fix: many fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
EtherealGlow committed Dec 29, 2023
1 parent 0ad29cc commit 49f0d1d
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 4 deletions.
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
"ignorePatterns": ["**/*.js"],
"rules": {
"no-prototype-builtins": "off",
"prefer-arrow-callback": ["warn", { "allowNamedFunctions": true }], // Disallow arrow functions as expressions
"func-style": ["warn", "declaration", { "allowArrowFunctions": false }], // Disallow the use of function expressions
"@typescript-eslint/no-floating-promises": "error",
Expand Down
3 changes: 0 additions & 3 deletions output.csv

This file was deleted.

Binary file removed output/output.xlsx
Binary file not shown.
12 changes: 12 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"@octokit/types": "^12.4.0",
"@sinclair/typebox": "^0.32.3",
"dotenv": "^16.3.1",
"json": "^11.0.0",
"json2csv": "^6.0.0-alpha.2",
"octokit": "^3.1.2",
"xlsx": "^0.18.5"
Expand Down
3 changes: 2 additions & 1 deletion src/helpers/calculateReward.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { UserType } from "../types/github";
import { getAllIssueComments, getCompletedIssues, getIssueAssignee, parsePermit } from "./issue";
import { AssigneeRewardMap } from "../types/miscellaneous";
import { mergeRewards } from "./excel";

export async function parseRewards(owner: string, repo: string, issueNumber: number): Promise<AssigneeRewardMap> {
const rewardMap: AssigneeRewardMap = {};
Expand Down Expand Up @@ -74,7 +75,7 @@ export async function calculateRepoReward(owner: string, repo: string) {
for (let i = 0; i < issues.length; i++) {
const issueNumber = issues[i].number;
const reward = await parseRewards(owner, repo, issueNumber);
totalReward = { ...totalReward, ...reward };
totalReward = mergeRewards(totalReward, reward);
}
return totalReward;
}
Expand Down
29 changes: 29 additions & 0 deletions src/helpers/excel.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { createWriteStream } from "fs";
import { AssigneeRewardMap } from "../types/miscellaneous";

function getMaxPermits(data: Record<string, { reward: number; permit: string[] }>): number {
let maxPermits = 0;
Expand Down Expand Up @@ -38,3 +39,31 @@ export async function convertToCSV(data: Record<string, { reward: number; permit
stream.write(csvString);
stream.end();
}

export function mergeRewards(map1: AssigneeRewardMap, map2: AssigneeRewardMap): AssigneeRewardMap {
const result: AssigneeRewardMap = {};

// Merge map1 into the result
// eslint-disable-next-line no-prototype-builtins
for (const assignee in map1) {
if (map1.hasOwnProperty(assignee)) {
result[assignee] = {
reward: (result[assignee]?.reward || 0) + map1[assignee].reward,
permit: (result[assignee]?.permit || []).concat(map1[assignee].permit),
};
}
}

// Merge map2 into the result
// eslint-disable-next-line no-prototype-builtins
for (const assignee in map2) {
if (map2.hasOwnProperty(assignee)) {
result[assignee] = {
reward: (result[assignee]?.reward || 0) + map2[assignee].reward,
permit: (result[assignee]?.permit || []).concat(map2[assignee].permit),
};
}
}

return result;
}
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2467,6 +2467,11 @@ json-stringify-safe@^5.0.1:
resolved "https://registry.npmjs.org/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz"
integrity sha512-ZClg6AaYvamvYEE82d3Iyd3vSSIjQ+odgjaTzRuO3s7toCdFKczob2i0zCh7JE8kWn17yvAWhUVxvqGwUalsRA==

json@^11.0.0:
version "11.0.0"
resolved "https://registry.npmjs.org/json/-/json-11.0.0.tgz"
integrity sha512-N/ITv3Yw9Za8cGxuQqSqrq6RHnlaHWZkAFavcfpH/R52522c26EbihMxnY7A1chxfXJ4d+cEFIsyTgfi9GihrA==

json2csv@^6.0.0-alpha.2:
version "6.0.0-alpha.2"
resolved "https://registry.npmjs.org/json2csv/-/json2csv-6.0.0-alpha.2.tgz"
Expand Down

0 comments on commit 49f0d1d

Please sign in to comment.