Skip to content
This repository has been archived by the owner on Sep 19, 2024. It is now read-only.

Fix/database functions #849

Closed
wants to merge 160 commits into from

Conversation

0x4007
Copy link
Member

@0x4007 0x4007 commented Oct 4, 2023

Still hacking away at this. Overtaking #644

@0x4007
Copy link
Member Author

0x4007 commented Oct 7, 2023

Database backup and schema backup: Archive.zip

Will do some due diligence and verify the code to be mostly functional before pushing this through.

@0x4007 0x4007 marked this pull request as ready for review October 7, 2023 21:26
@0x4007 0x4007 requested a review from 0xcodercrane as a code owner October 7, 2023 21:26
@@ -31,7 +31,7 @@ jobs:
env:
SUPABASE_ACCESS_TOKEN: ${{ github.ref == 'refs/heads/main' && secrets.PRODUCTION_SUPABASE_ACCESS_TOKEN || secrets.STAGING_SUPABASE_ACCESS_TOKEN }}
SUPABASE_DB_PASSWORD: ${{ github.ref == 'refs/heads/main' && secrets.PRODUCTION_SUPABASE_DB_PASSWORD || secrets.STAGING_SUPABASE_DB_PASSWORD }}
PROJECT_ID: ${{ github.ref == 'refs/heads/main' && secrets.PRODUCTION_SUPABASE_PROJECT_ID || secrets.STAGING_SUPABASE_PROJECT_ID }}
SUPABASE_PROJECT_ID: ${{ github.ref == 'refs/heads/main' && secrets.PRODUCTION_SUPABASE_PROJECT_ID || secrets.STAGING_SUPABASE_PROJECT_ID }}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update secret

Comment on lines +28 to +39
LOG_ENVIRONMENT: "production"
SUPABASE_URL: ${{ secrets.SUPABASE_URL }}
SUPABASE_KEY: ${{ secrets.SUPABASE_KEY }}
X25519_PRIVATE_KEY: "QCDb30UHUkwJAGhLWC-R2N0PiEbd4vQY6qH2Wloybyo"
APP_ID: ${{ secrets.APP_ID }}
PRIVATE_KEY: ${{ secrets.PRIVATE_KEY }}
WEBHOOK_PROXY_URL: ${{ secrets.WEBHOOK_PROXY_URL }}
WEBHOOK_SECRET: ${{ secrets.WEBHOOK_SECRET }}
TEST_ORGANIZATION_NAME: ${{ secrets.TEST_ORGANIZATION_NAME }}
TEST_REPOSITORY_NAME: ${{ secrets.TEST_REPOSITORY_NAME }}
TEST_ADMIN_PAT: ${{ secrets.TEST_ADMIN_PAT }}
TEST_OUTSIDE_COLLABORATOR_PAT: ${{ secrets.TEST_OUTSIDE_COLLABORATOR_PAT }}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These will probably need to be updated as I think I'll use a new database instance to drop all the old unused triggers/functions/enums etc from the old database.

Comment on lines +20 to +26
access: new Access(client),
wallet: new Wallet(client),
user: new User(client),
debit: new Settlement(client),
settlement: new Settlement(client),
label: new Label(client),
super: new Super(client),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty major refactoring where I tried to associate an object to handle every interaction with a table of its namesake.

Comment on lines +21 to +24
info: (msg: string, options?: JSON) => string;
debug: (msg: string, options?: JSON) => string;
warn: (msg: string, options?: JSON) => string;
error: (msg: string, options?: JSON) => string;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now we can throw and return logger.xxx() without being redundant and copying the string twice.

@@ -1,5 +1,5 @@
export const GLOBAL_STRINGS = {
unassignComment: "Releasing the bounty back to dev pool because the allocated duration already ended!",
unassignComment: "Releasing the task due to lack of updates.",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed 'bounty' from the terminology everywhere to make this more widely appealing.

const sender = payload.sender.login;
const repo = payload.repository;
const permissionLevel = await getUserPermission(sender, context);
const userCan = await isUserAdminOrBillingManager(sender, context);
Copy link
Member Author

@0x4007 0x4007 Oct 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isUserAdminOrBillingManager was incorrectly implemented. I fixed it.

import { Payload } from "../../../types";

export const setAccess = async (body: string) => {
export async function setAccess(body: string): Promise<string> {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Traditional function declarations are superior for general use. The only time arrow functions should be used are for tiny functions that are inlined.

Comment on lines +19 to +61
// export async function payout(body: string) {
// const { payload: _payload } = getBotContext();
// const logger = getLogger();
// if (body != IssueCommentCommands.PAYOUT && body.replace(/`/g, "") != IssueCommentCommands.PAYOUT) {
// logger.info(`Skipping to payout. body: ${body}`);
// return;
// }

const payload = _payload as Payload;
logger.info(`Received '/payout' command from user: ${payload.sender.login}`);
const issue = (_payload as Payload).issue;
if (!issue) {
logger.info(`Skipping '/payout' because of no issue instance`);
return;
}
// const payload = _payload as Payload;
// logger.info(`Received '/payout' command from user: ${payload.sender.login}`);
// const issue = (_payload as Payload).issue;
// if (!issue) {
// logger.info(`Skipping '/payout' because of no issue instance`);
// return;
// }

const _labels = payload.issue?.labels;
if (_labels?.some((e) => e.name.toLowerCase() === "Permitted".toLowerCase())) {
logger.info(`Permit already generated for ${payload.issue?.number}`);
return;
}
// const _labels = payload.issue?.labels;
// if (_labels?.some((e) => e.name.toLowerCase() === "Permitted".toLowerCase())) {
// logger.info(`Permit already generated for ${payload.issue?.number}`);
// return;
// }

const IssueComments = await getAllIssueComments(issue.number);
if (IssueComments.length === 0) {
return `Permit generation failed due to internal GitHub Error`;
}
// const IssueComments = await getAllIssueComments(issue.number);
// if (IssueComments.length === 0) {
// return `Permit generation failed due to internal GitHub Error`;
// }

const hasPosted = IssueComments.find((e) => e.user.type === "Bot" && e.body.includes("https://pay.ubq.fi?claim"));
if (hasPosted) {
logger.info(`Permit already generated for ${payload.issue?.number}`);
return;
}
// const hasPosted = IssueComments.find((e) => e.user.type === "Bot" && e.body.includes("https://pay.ubq.fi?claim"));
// if (hasPosted) {
// logger.info(`Permit already generated for ${payload.issue?.number}`);
// return;
// }

// assign function incentivesCalculation to a variable
const calculateIncentives = await incentivesCalculation();
// // assign function incentivesCalculation to a variable
// const calculateIncentives = await incentivesCalculation();

const creatorReward = await calculateIssueCreatorReward(calculateIncentives);
const assigneeReward = await calculateIssueAssigneeReward(calculateIncentives);
const conversationRewards = await calculateIssueConversationReward(calculateIncentives);
const pullRequestReviewersReward = await calculatePullRequestReviewsReward(calculateIncentives);
// const creatorReward = await calculateIssueCreatorReward(calculateIncentives);
// const assigneeReward = await calculateIssueAssigneeReward(calculateIncentives);
// const conversationRewards = await calculateIssueConversationReward(calculateIncentives);
// const pullRequestReviewersReward = await calculateReviewContributorRewards(calculateIncentives);

return await handleIssueClosed(creatorReward, assigneeReward, conversationRewards, pullRequestReviewersReward, calculateIncentives);
};
// return await handleIssueClosed(creatorReward, assigneeReward, conversationRewards, pullRequestReviewersReward, calculateIncentives);
// }
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm unsure why I left this commented out. I have yet to see this used in production. Perhaps this was implemented incorrectly? Or else I'll need to review later.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was never called anywhere.

resultMessage += `@${user}'s access levels are set as follows:\n
Multiplier: ${multiplier}\n
Reason: ${multiplier_reason}\n
Labels: ${JSON.stringify(labels)}\n
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Labels are now dynamic. I just listed the array here.

Copy link
Member Author

@0x4007 0x4007 Oct 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file was a bit insane. I think I broke it apart into 14 separate files most of which are over a hundred lines of code long.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file should soon be consolidated elsewhere. This originally acted as my crutch while I was refactoring.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These were collateral damage from find and replace nuking "bounty" from the codebase.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Vestige from partially implemented Telegram bot.

@0x4007 0x4007 closed this Oct 9, 2023
@0x4007 0x4007 mentioned this pull request Oct 9, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants