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 Oct 4, 2023
2 parents ed023ba + 9d00d7f commit 8e6ddaa
Show file tree
Hide file tree
Showing 47 changed files with 3,541 additions and 1,556 deletions.
57 changes: 57 additions & 0 deletions .cspell.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"useGitignore": true,
"version": "0.2",
"language": "en",
"words": [
"autodetection",
"autopay",
"AUTOPAY",
"bucketid",
"bucketname",
"demilestoned",
"devpool",
"ensname",
"fkey",
"gelato",
"Gelato",
"gollum",
"keccak",
"libsodium",
"logdna",
"LOGDNA",
"mdast",
"Mdast",
"mergeable",
"micromark",
"milestoned",
"Numberish",
"orgname",
"pavlovcik",
"permisson",
"prereleased",
"probot",
"Probot",
"ratelimit",
"rebaseable",
"rerequested",
"scalarmult",
"signoff",
"sortcolumn",
"sortorder",
"supabase",
"Supabase",
"SUPABASE",
"svgs",
"timelabel",
"TURL",
"typebox",
"Ubiqui",
"ubiquibot",
"unarchived",
"Unassigning",
"Upserting",
"URLSAFE",
"vitalik",
"WXDAI"
]
}
7 changes: 7 additions & 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 All @@ -20,3 +21,9 @@ CHATGPT_USER_PROMPT_FOR_MEASURE_SIMILARITY='I have two github issues and I need
SIMILARITY_THRESHOLD=80
MEASURE_SIMILARITY_AI_TEMPERATURE=0
IMPORTANT_WORDS_AI_TEMPERATURE=0

# Telegram Log Notification Envs
LOG_WEBHOOK_BOT_URL= # URL of cloudflare worker without trailing /
LOG_WEBHOOK_SECRET= # Random Secret, Shared between the telegram bot and the sender
LOG_WEBHOOK_GROUP_ID= # Group Id, ex: -100124234325
LOG_WEBHOOK_TOPIC_ID= # Topic Id (Optional), Only provide if group is a topic and you're not using General
7 changes: 6 additions & 1 deletion .github/ubiquibot-config.yml
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
price-multiplier: 1.5
price-multiplier: 1.5
# newContributorGreeting:
# enabled: true
# header: "Thank you for contributing to UbiquiBot! Please be sure to set your wallet address before completing your first bounty so that the automatic payout upon task completion will work for you."
# helpMenu: true
# footer: "###### Also please star this repository and [@ubiquity/devpool-directory](https://github.com/ubiquity/devpool-directory/) to show your support. It helps a lot!"
2 changes: 1 addition & 1 deletion .github/workflows/conventional-commits.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ubiquity/action-conventional-commits@v1.1.2
- uses: ubiquity/action-conventional-commits@master
2 changes: 1 addition & 1 deletion app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ default_events:
# - gollum
- issue_comment
- issues
# - label
- label
# - milestone
# - member
# - membership
Expand Down
10 changes: 9 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"lint": "eslint --ext .ts ./src",
"start:serverless": "tsx src/adapters/github/github-actions.ts",
"start:watch": "nodemon --exec 'yarn start'",
"start": "probot run ./lib/src/index.js",
"utils:cspell": "cspell --config .cspell.json 'src/**/*.{js,ts,json,md,yml}'",
"start": "probot run ./lib/index.js",
"prepare": "husky install"
},
"dependencies": {
Expand All @@ -43,12 +44,14 @@
"ajv-formats": "^2.1.1",
"axios": "^1.3.2",
"copyfiles": "^2.4.1",
"cspell": "^7.0.0",
"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",
"jsonwebtoken": "^9.0.2",
"libsodium-wrappers": "^0.7.11",
"lint-staged": "^13.1.0",
"mdast-util-from-markdown": "^0.8.5",
Expand All @@ -59,6 +62,8 @@
"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",
"telegraf": "^4.11.2",
Expand Down Expand Up @@ -88,6 +93,9 @@
"lint-staged": {
"*.{ts,json}": [
"prettier --write"
],
"src/**.{ts,json}": [
"cspell"
]
},
"nodemonConfig": {
Expand Down
54 changes: 53 additions & 1 deletion src/adapters/supabase/helpers/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ export const upsertAccessControl = async (username: string, repository: string,
const { data: _data, error: _error } = await supabase.from("access").insert({
created_at: new Date().toUTCString(),
price_access: false,
time_access: false,
time_access: true,
multiplier_access: false,
priority_access: false,
...properties,
Expand Down Expand Up @@ -521,3 +521,55 @@ export const savePermit = async (permit: InsertPermit): Promise<Permit> => {
}
return getPermitFromDbData(data[0]);
};

export const saveLabelChange = async (username: string, repository: string, label_from: string, label_to: string, hasAccess: boolean) => {
const { supabase } = getAdapters();
const { data, error } = await supabase
.from("label_changes")
.insert({
username,
repository,
label_from,
label_to,
authorized: hasAccess || false,
created: new Date().toISOString(),
updated: new Date().toISOString(),
})
.select();
if (error) {
throw new Error(error.message);
}
if (!data || data.length === 0) {
throw new Error("No data returned");
}
return data[0];
};

export const getLabelChanges = async (repository: string, labels: string[]) => {
const { supabase } = getAdapters();
const logger = getLogger();

const { data, error } = await supabase.from("label_changes").select("*").in("label_to", labels).eq("repository", repository).eq("authorized", false);

logger.debug(`Getting label changes done, { data: ${JSON.stringify(data)}, error: ${JSON.stringify(error)} }`);

if (error) {
throw new Error(`Error getting label changes: ${error.message}`);
}

if (data.length === 0) {
return null;
}
return data[0];
};

export const _approveLabelChange = async (changeId: number) => {
const { supabase } = getAdapters();
const { error } = await supabase.from("label_changes").update({ authorized: true }).eq("id", changeId);

if (error) {
throw new Error(error.message);
}

return;
};
83 changes: 80 additions & 3 deletions src/adapters/supabase/helpers/log.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import axios from "axios";
import { getAdapters, getBotContext, Logger } from "../../../bindings";
import { Payload, LogLevel } from "../../../types";
import { Payload, LogLevel, LogNotification } from "../../../types";
import { getOrgAndRepoFromPath } from "../../../utils/private";

import jwt from "jsonwebtoken";
interface Log {
repo: string | null;
org: string | null;
Expand Down Expand Up @@ -43,13 +44,15 @@ export class GitHubLogger implements Logger {
private retryDelay = 1000; // Delay between retries in milliseconds
private throttleCount = 0;
private retryLimit = 0; // Retries disabled by default
private logNotification;

constructor(app: string, logEnvironment: string, maxLevel: LogLevel, retryLimit: number) {
constructor(app: string, logEnvironment: string, maxLevel: LogLevel, retryLimit: number, logNotification: LogNotification) {
this.app = app;
this.logEnvironment = logEnvironment;
this.maxLevel = getNumericLevel(maxLevel);
this.retryLimit = retryLimit;
this.supabase = getAdapters().supabase;
this.logNotification = logNotification;
}

async sendLogsToSupabase({ repo, org, commentId, issueNumber, logMessage, level, timestamp }: Log) {
Expand Down Expand Up @@ -80,6 +83,66 @@ export class GitHubLogger implements Logger {
}
}

private sendDataWithJwt(message: string | object, errorPayload?: string | object) {
const context = getBotContext();
const payload = context.payload as Payload;

const { comment, issue, repository } = payload;
const commentId = comment?.id;
const issueNumber = issue?.number;
const repoFullName = repository?.full_name;

const { org, repo } = getOrgAndRepoFromPath(repoFullName);

const issueLink = `https://github.com/${org}/${repo}/issues/${issueNumber}${commentId ? `#issuecomment-${commentId}` : ""}`;

return new Promise((resolve, reject) => {
try {
if (!this.logNotification?.enabled) {
reject("Telegram Log Notification is disabled, please check that url, secret and group is provided");
}

if (typeof message === "object") {
message = JSON.stringify(message);
}

if (errorPayload && typeof errorPayload === "object") {
errorPayload = JSON.stringify(errorPayload);
}

const errorMessage = `\`${message}${errorPayload ? " - " + errorPayload : ""}\`\n\nContext: ${issueLink}`;

// Step 1: Sign a JWT with the provided parameter
const jwtToken = jwt.sign(
{
group: this.logNotification.groupId,
topic: this.logNotification.topicId,
msg: errorMessage,
},
this.logNotification.secret,
{ noTimestamp: true }
);

const apiUrl = `${this.logNotification.url}/sendLogs`;
const headers = {
Authorization: `${jwtToken}`,
};

axios
.get(apiUrl, { headers })
.then((response) => {
resolve(response.data);
})
.catch((error) => {
reject(error);
});
} catch (error) {
// Reject the promise with the error
reject(error);
}
});
}

async retryLog(log: Log, retryCount = 0) {
if (retryCount >= this.retryLimit) {
console.error("Max retry limit reached for log:", log);
Expand Down Expand Up @@ -169,6 +232,13 @@ export class GitHubLogger implements Logger {

warn(message: string | object, errorPayload?: string | object) {
this.save(message, LogLevel.WARN, errorPayload);
this.sendDataWithJwt(message, errorPayload)
.then((response) => {
this.save(`Log Notification Success: ${response}`, LogLevel.DEBUG, "");
})
.catch((error) => {
this.save(`Log Notification Error: ${error}`, LogLevel.DEBUG, "");
});
}

debug(message: string | object, errorPayload?: string | object) {
Expand All @@ -177,6 +247,13 @@ export class GitHubLogger implements Logger {

error(message: string | object, errorPayload?: string | object) {
this.save(message, LogLevel.ERROR, errorPayload);
this.sendDataWithJwt(message, errorPayload)
.then((response) => {
this.save(`Log Notification Success: ${response}`, LogLevel.DEBUG, "");
})
.catch((error) => {
this.save(`Log Notification Error: ${error}`, LogLevel.DEBUG, "");
});
}

async get() {
Expand Down
1 change: 1 addition & 0 deletions src/assets/fonts/proxima-nova-regular-b64.ts

Large diffs are not rendered by default.

Loading

0 comments on commit 8e6ddaa

Please sign in to comment.