Skip to content

Commit

Permalink
Merge pull request ubiquity#795 from ubiquity/development
Browse files Browse the repository at this point in the history
Staging to production
  • Loading branch information
0xcodercrane authored Sep 22, 2023
2 parents dfe9e2c + b417336 commit a3306ad
Show file tree
Hide file tree
Showing 49 changed files with 2,965 additions and 1,803 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ SUPABASE_KEY=
AUTO_PAY_MODE=
ANALYTICS_MODE=


# Use `trace` to get verbose logging or `info` to show less
LOG_LEVEL=debug
LOGDNA_INGESTION_KEY=
Expand Down
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:
5 changes: 1 addition & 4 deletions .github/ubiquibot-config.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
price-multiplier: 1.5
default-labels:
- "Time: <1 Hour"
- "Priority: 1 (Normal)"
priceMultiplier: 1.5
2 changes: 1 addition & 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 Down
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,29 +31,32 @@
"@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",
"@vercel/ncc": "^0.34.0",
"ajv": "^8.11.2",
"ajv-formats": "^2.1.1",
"axios": "^1.3.2",
"decimal.js": "^10.4.3",
"copyfiles": "^2.4.1",
"decimal.js": "^10.4.3",
"ethers": "^5.7.2",
"exponential-backoff": "^3.1.1",
"husky": "^8.0.2",
"jimp": "^0.22.4",
"js-yaml": "^4.1.0",
"libsodium-wrappers": "^0.7.11",
"lint-staged": "^13.1.0",
"lodash": "^4.17.21",
"ms": "^2.1.3",
"node-html-parser": "^6.1.5",
"node-html-to-image": "^3.3.0",
"nodemon": "^2.0.19",
"openai": "^4.2.0",
"parse5": "^7.1.2",
"prettier": "^2.7.1",
"probot": "^12.2.4",
Expand All @@ -65,6 +68,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
13 changes: 10 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,7 +32,10 @@ export const loadConfig = async (context: Context): Promise<BotConfig> => {
commandSettings,
assistivePricing,
registerWalletWithVerification,
staleBountyTime,
enableAccessControl,
openAIKey,
openAITokenLimit,
} = await getWideConfig(context);

const publicKey = await getScalarKey(process.env.X25519_PRIVATE_KEY);
Expand All @@ -42,7 +44,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 @@ -90,6 +92,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 @@ -98,6 +101,10 @@ export const loadConfig = async (context: Context): Promise<BotConfig> => {
wallet: {
registerWalletWithVerification: registerWalletWithVerification,
},
ask: {
apiKey: openAIKey,
tokenLimit: openAITokenLimit || 0,
},
accessControl: enableAccessControl,
};

Expand Down
Loading

0 comments on commit a3306ad

Please sign in to comment.