Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/development' into incentives-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
whilefoo committed Sep 19, 2023
2 parents 0b5e149 + dba8308 commit 9e88f65
Show file tree
Hide file tree
Showing 46 changed files with 1,030 additions and 567 deletions.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1 +1 @@

* @0xcodercrane
15 changes: 12 additions & 3 deletions .github/ISSUE_TEMPLATE/bounty-template.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
name: "Bounty Proposal"
description: Have a suggestion for how to improve UbiquiBot? Let us know!
title: "Bounty Proposal:"
title: "Bounty Proposal: "

body:
- type: markdown
attributes:
value: |
## Feature Request Form
Thank you for taking the time to file a feature request! Please let us know what you're trying to do, and how UbiquiBot can help.
Thank you for taking the time to file a feature request.
If you register your wallet address, you will be eligible for compensation if this is accepted!
Please let us know how we can improve the bot.
- type: textarea
attributes:
label: Describe the background or context
description: Please let us know what inspired you to write this proposal. Backlinking to specific comments is usually sufficient context.
description: Please let us know what inspired you to write this proposal. Backlinking to specific comments on GitHub, and leaving a remark about how the bot should have interacted with it is usually sufficient context.
validations:
required: false

Expand All @@ -22,3 +24,10 @@ body:
description: A clear description of what you want to happen. Add any considered drawbacks.
validations:
required: true

- type: textarea
attributes:
label: Remarks
description: Any closing remarks?
validations:
required: false
6 changes: 3 additions & 3 deletions .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
blank_issues_enabled: true
contact_links:
- name: Telegram Group Chat
url: https://t.me/UbiquityDAO/29891
about: "Join us on Telegram!"
- name: UbiquiBot Development Group Chat
url: https://t.me/UbiquityDAO/31132
about: "Live chat with us on Telegram!"
14 changes: 9 additions & 5 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
<!-- RULES TO CONTRIBUTE TO UBIQUIBOT
1. You must link the issue number e.g. "Resolves #1234"
2. You must link proof that your code works from a test issue on your forked repo e.g. "Quality Assurance https://github.com/user/repo/issues/1#issuecomment-1"
3. Please do not replace the keyword "Resolves" https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword
-->

Resolves #

<!--
- You must link the issue number e.g. "Resolves #1234"
- You must link the QA issue on your forked repo e.g. "QA for #1234"
- Please do not replace the keyword "Resolves" https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword
-->
Quality Assurance:
6 changes: 1 addition & 5 deletions .github/ubiquibot-config.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
price-multiplier: 1.5

default-labels:
- "Time: <1 Hour"
- "Priority: 1 (Normal)"
price-multiplier: 1.5
26 changes: 25 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ Bounty bot is built using the [probot](https://probot.github.io/) framework so i
├── <a href="https://github.com/ubiquity/ubiquibot/tree/development/src/utils">utils</a> A set of utility functions
</pre>

## Default Config Notes (`ubiquibot-config-default.json`)
## Default Config Notes (`ubiquibot-config-default.ts`)

We can't use a `jsonc` file due to limitations with Netlify. Here is a snippet of some values with notes next to them.

Expand All @@ -239,3 +239,27 @@ We can't use a `jsonc` file due to limitations with Netlify. Here is a snippet o
}
}
```

## Supabase Cron Job (`logs-cleaner`)

##### Dashboard > Project > Database > Extensions

> Search `PG_CRON` and Enable it.

##### Dashboard > Project > SQL Editor

```sql
-- Runs everyday at 03:00 AM to cleanup logs that are older than a week
-- Use the cron time format to modify the trigger time if necessary
select
cron.schedule (
'logs-cleaner', -- Job name
'0 3 * * *', -- Everyday at 03:00 AM
$$DELETE FROM logs WHERE timestamp < now() - INTERVAL '1 week'$$
);


-- Cancel the cron job
select cron.unschedule('logs-cleaner');
```
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@
"@netlify/functions": "^1.4.0",
"@probot/adapter-aws-lambda-serverless": "^3.0.2",
"@probot/adapter-github-actions": "^3.1.3",
"@sinclair/typebox": "^0.25.9",
"@sinclair/typebox": "^0.31.5",
"@supabase/supabase-js": "^2.4.0",
"@types/ms": "^0.7.31",
"@types/parse5": "^7.0.0",
"@typescript-eslint/eslint-plugin": "^5.59.11",
"@typescript-eslint/parser": "^5.59.11",
"@uniswap/permit2-sdk": "^1.2.0",
Expand All @@ -53,6 +54,7 @@
"mdast-util-from-markdown": "^0.8.5",
"mdast-util-gfm": "^0.1.2",
"micromark-extension-gfm": "^0.3.3",
"lodash": "^4.17.21",
"ms": "^2.1.3",
"node-html-parser": "^6.1.5",
"node-html-to-image": "^3.3.0",
Expand All @@ -67,6 +69,7 @@
"@types/eslint": "^8.40.2",
"@types/jest": "^28.1.0",
"@types/libsodium-wrappers": "^0.7.10",
"@types/lodash": "^4.14.197",
"@types/node": "^14.18.37",
"@types/source-map-support": "^0.5.6",
"eslint": "^8.43.0",
Expand Down
4 changes: 2 additions & 2 deletions src/adapters/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export * from "./telegram";

export const createAdapters = (config: BotConfig): Adapters => {
return {
supabase: supabase(config.supabase.url, config.supabase.key),
telegram: new Telegraf(config.telegram.token).telegram,
supabase: supabase(config?.supabase?.url ?? process.env.SUPABASE_URL, config?.supabase?.key ?? process.env.SUPABASE_KEY),
telegram: new Telegraf(config?.telegram?.token ?? process.env.TELEGRAM_BOT_TOKEN).telegram,
};
};
31 changes: 26 additions & 5 deletions src/adapters/supabase/helpers/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ import { Database } from "../types";
import { InsertPermit, Permit } from "../../../helpers";
import { BigNumber, BigNumberish } from "ethers";

interface AccessLevels {
multiplier: boolean;
price: boolean;
priority: boolean;
time: boolean;
}

/**
* @dev Creates a typescript client which will be used to interact with supabase platform
*
Expand Down Expand Up @@ -218,17 +225,17 @@ export const upsertWalletAddress = async (username: string, address: string): Pr
}
logger.info(`Upserting a wallet address done, { data: ${JSON.stringify(_data)} }`);
} else {
const { data: _data, error: _error } = await supabase.from("wallets").insert({
const { error } = await supabase.from("wallets").insert({
user_name: username,
wallet_address: address,
created_at: new Date().toUTCString(),
updated_at: new Date().toUTCString(),
});
if (_error) {
logger.error(`Creating a new wallet_table record failed, error: ${JSON.stringify(_error)}`);
throw new Error(`Creating a new wallet_table record failed, error: ${JSON.stringify(_error)}`);
if (error) {
logger.error(`Creating a new wallet_table record failed, error: ${JSON.stringify(error)}`);
throw new Error(`Creating a new wallet_table record failed, error: ${JSON.stringify(error)}`);
}
logger.info(`Creating a new wallet_table record done, { data: ${JSON.stringify(_data)} }`);
logger.info(`Creating a new wallet_table record done, { data: ${JSON.stringify(data)}, address: $address }`);
}
};

Expand Down Expand Up @@ -340,6 +347,20 @@ export const getAccessLevel = async (username: string, repository: string, label
return accessValues;
};

export const getAllAccessLevels = async (username: string, repository: string): Promise<null | AccessLevels> => {
const logger = getLogger();
const { supabase } = getAdapters();

const { data } = await supabase.from("access").select("*").eq("user_name", username).eq("repository", repository).single();

if (!data) {
logger.info(`Access not found on the database`);
// no access
return null;
}
return { multiplier: data.multiplier_access, time: data.time_access, priority: data.priority_access, price: data.price_access };
};

/**
* Queries the wallet address registered previously
*
Expand Down
47 changes: 29 additions & 18 deletions src/adapters/supabase/helpers/log.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,37 @@
import { getAdapters, getBotContext, Logger } from "../../../bindings";
import { Payload } from "../../../types";
import { getNumericLevel } from "../../../utils/helpers";
import { Payload, LogLevel } from "../../../types";
import { getOrgAndRepoFromPath } from "../../../utils/private";

interface Log {
repo: string | null;
org: string | null;
commentId: number | undefined;
issueNumber: number | undefined;
logMessage: string;
level: Level;
level: LogLevel;
timestamp: string;
}

export enum Level {
ERROR = "error",
WARN = "warn",
INFO = "info",
HTTP = "http",
VERBOSE = "verbose",
DEBUG = "debug",
SILLY = "silly",
}
export const getNumericLevel = (level: LogLevel) => {
switch (level) {
case LogLevel.ERROR:
return 0;
case LogLevel.WARN:
return 1;
case LogLevel.INFO:
return 2;
case LogLevel.HTTP:
return 3;
case LogLevel.VERBOSE:
return 4;
case LogLevel.DEBUG:
return 5;
case LogLevel.SILLY:
return 6;
default:
return -1; // Invalid level
}
};

export class GitHubLogger implements Logger {
private supabase;
Expand All @@ -33,7 +44,7 @@ export class GitHubLogger implements Logger {
private throttleCount = 0;
private retryLimit = 0; // Retries disabled by default

constructor(app: string, logEnvironment: string, maxLevel: Level, retryLimit: number) {
constructor(app: string, logEnvironment: string, maxLevel: LogLevel, retryLimit: number) {
this.app = app;
this.logEnvironment = logEnvironment;
this.maxLevel = getNumericLevel(maxLevel);
Expand Down Expand Up @@ -118,7 +129,7 @@ export class GitHubLogger implements Logger {
}
}

private save(logMessage: string | object, level: Level, errorPayload?: string | object) {
private save(logMessage: string | object, level: LogLevel, errorPayload?: string | object) {
if (getNumericLevel(level) > this.maxLevel) return; // only return errors lower than max level

const context = getBotContext();
Expand Down Expand Up @@ -153,19 +164,19 @@ export class GitHubLogger implements Logger {
}

info(message: string | object, errorPayload?: string | object) {
this.save(message, Level.INFO, errorPayload);
this.save(message, LogLevel.INFO, errorPayload);
}

warn(message: string | object, errorPayload?: string | object) {
this.save(message, Level.WARN, errorPayload);
this.save(message, LogLevel.WARN, errorPayload);
}

debug(message: string | object, errorPayload?: string | object) {
this.save(message, Level.DEBUG, errorPayload);
this.save(message, LogLevel.DEBUG, errorPayload);
}

error(message: string | object, errorPayload?: string | object) {
this.save(message, Level.ERROR, errorPayload);
this.save(message, LogLevel.ERROR, errorPayload);
}

async get() {
Expand Down
9 changes: 6 additions & 3 deletions src/bindings/config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import ms from "ms";

import { BotConfig, BotConfigSchema } from "../types";
import { BotConfig, BotConfigSchema, LogLevel } from "../types";
import {
DEFAULT_BOT_DELAY,
DEFAULT_DISQUALIFY_TIME,
Expand All @@ -13,7 +13,6 @@ import { getPayoutConfigByNetworkId } from "../helpers";
import { ajv } from "../utils";
import { Context } from "probot";
import { getScalarKey, getWideConfig } from "../utils/private";
import { Level } from "../adapters/supabase";

export const loadConfig = async (context: Context): Promise<BotConfig> => {
const {
Expand All @@ -33,6 +32,8 @@ export const loadConfig = async (context: Context): Promise<BotConfig> => {
commandSettings,
assistivePricing,
registerWalletWithVerification,
staleBountyTime,
enableAccessControl,
} = await getWideConfig(context);

const publicKey = await getScalarKey(process.env.X25519_PRIVATE_KEY);
Expand All @@ -41,7 +42,7 @@ export const loadConfig = async (context: Context): Promise<BotConfig> => {
const botConfig: BotConfig = {
log: {
logEnvironment: process.env.LOG_ENVIRONMENT || "production",
level: (process.env.LOG_LEVEL as Level) || Level.DEBUG,
level: (process.env.LOG_LEVEL as LogLevel) || LogLevel.DEBUG,
retryLimit: Number(process.env.LOG_RETRY) || 0,
},
price: {
Expand Down Expand Up @@ -89,6 +90,7 @@ export const loadConfig = async (context: Context): Promise<BotConfig> => {
command: commandSettings,
assign: {
bountyHunterMax: bountyHunterMax,
staleBountyTime: ms(staleBountyTime),
},
sodium: {
privateKey: process.env.X25519_PRIVATE_KEY ?? "",
Expand All @@ -97,6 +99,7 @@ export const loadConfig = async (context: Context): Promise<BotConfig> => {
wallet: {
registerWalletWithVerification: registerWalletWithVerification,
},
accessControl: enableAccessControl,
};

if (botConfig.payout.privateKey == "") {
Expand Down
Loading

0 comments on commit 9e88f65

Please sign in to comment.