Skip to content

Commit

Permalink
fix(conflicts): fixing errors caused due to newer commits and syncing…
Browse files Browse the repository at this point in the history
… branch with development
  • Loading branch information
Sadaf-A committed Oct 24, 2023
1 parent c3ad5d9 commit bee6ac6
Show file tree
Hide file tree
Showing 27 changed files with 111 additions and 105 deletions.
50 changes: 25 additions & 25 deletions src/adapters/supabase/helpers/client.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createClient, SupabaseClient } from "@supabase/supabase-js";
import { getAdapters, getLogger } from "../../../bindings";
import { Issue, UserProfile } from "../../../types";
import { BotContext, Issue, UserProfile } from "../../../types";
import { Database } from "../types";
import { InsertPermit, Permit } from "../../../helpers";
import { BigNumber, BigNumberish } from "ethers";
Expand Down Expand Up @@ -54,27 +54,27 @@ export const getLastWeeklyTime = async (): Promise<Date | undefined> => {
/**
* @dev Updates the last weekly update timestamp
*/
export const updateLastWeeklyTime = async (time: Date): Promise<void> => {
export const updateLastWeeklyTime = async (context: BotContext, time: Date): Promise<void> => {
const logger = getLogger();
const { supabase } = getAdapters();

const { data, error } = await supabase.from("weekly").select("last_time");
if (error) {
logger.error(`Checking last time failed, error: ${JSON.stringify(error)}`);
logger.error(context, `Checking last time failed, error: ${JSON.stringify(error)}`);
throw new Error(`Checking last time failed, error: ${JSON.stringify(error)}`);
}

if (data && data.length > 0) {
const { data, error } = await supabase.from("weekly").update({ last_time: time.toUTCString() }).neq("last_time", time.toUTCString());
if (error) {
logger.error(`Updating last time failed, error: ${JSON.stringify(error)}`);
logger.error(context, `Updating last time failed, error: ${JSON.stringify(error)}`);
throw new Error(`Updating last time failed, error: ${JSON.stringify(error)}`);
}
logger.info(`Updating last time is done, data: ${data}`);
} else {
const { data, error } = await supabase.from("weekly").insert({ last_time: time.toUTCString() });
if (error) {
logger.error(`Creating last time failed, error: ${JSON.stringify(error)}`);
logger.error(context, `Creating last time failed, error: ${JSON.stringify(error)}`);
throw new Error(`Creating last time failed, error: ${JSON.stringify(error)}`);
}
logger.info(`Creating last time is done, data: ${data}`);
Expand Down Expand Up @@ -138,12 +138,12 @@ const getDbDataFromUserProfile = (userProfile: UserProfile, additions?: UserProf
* Performs an UPSERT on the issues table.
* @param issue The issue entity fetched from github event.
*/
export const upsertIssue = async (issue: Issue, additions: IssueAdditions): Promise<void> => {
export const upsertIssue = async (context: BotContext, issue: Issue, additions: IssueAdditions): Promise<void> => {
const logger = getLogger();
const { supabase } = getAdapters();
const { data, error } = await supabase.from("issues").select("id").eq("issue_number", issue.number);
if (error) {
logger.error(`Checking issue failed, error: ${JSON.stringify(error)}`);
logger.error(context, `Checking issue failed, error: ${JSON.stringify(error)}`);
throw new Error(`Checking issue failed, error: ${JSON.stringify(error)}`);
}

Expand All @@ -154,14 +154,14 @@ export const upsertIssue = async (issue: Issue, additions: IssueAdditions): Prom
.upsert({ id: key, ...getDbDataFromIssue(issue, additions) })
.select();
if (_error) {
logger.error(`Upserting an issue failed, error: ${JSON.stringify(_error)}`);
logger.error(context, `Upserting an issue failed, error: ${JSON.stringify(_error)}`);
throw new Error(`Upserting an issue failed, error: ${JSON.stringify(_error)}`);
}
logger.info(`Upserting an issue done, { data: ${_data}, error: ${_error}`);
} else {
const { data: _data, error: _error } = await supabase.from("issues").insert(getDbDataFromIssue(issue, additions));
if (_error) {
logger.error(`Creating a new issue record failed, error: ${JSON.stringify(_error)}`);
logger.error(context, `Creating a new issue record failed, error: ${JSON.stringify(_error)}`);
throw new Error(`Creating a new issue record failed, error: ${JSON.stringify(_error)}`);
}
logger.info(`Creating a new issue record done, { data: ${_data}, error: ${_error}`);
Expand All @@ -172,26 +172,26 @@ export const upsertIssue = async (issue: Issue, additions: IssueAdditions): Prom
* Performs an UPSERT on the users table.
* @param user The user entity fetched from github event.
*/
export const upsertUser = async (user: UserProfile): Promise<void> => {
export const upsertUser = async (context: BotContext, user: UserProfile): Promise<void> => {
const logger = getLogger();
const { supabase } = getAdapters();
const { data, error } = await supabase.from("users").select("user_login").eq("user_login", user.login);
if (error) {
logger.error(`Checking user failed, error: ${JSON.stringify(error)}`);
logger.error(context, `Checking user failed, error: ${JSON.stringify(error)}`);
throw new Error(`Checking user failed, error: ${JSON.stringify(error)}`);
}

if (data && data.length > 0) {
const { data: _data, error: _error } = await supabase.from("users").upsert(getDbDataFromUserProfile(user)).select();
if (_error) {
logger.error(`Upserting a user failed, error: ${JSON.stringify(_error)}`);
logger.error(context, `Upserting a user failed, error: ${JSON.stringify(_error)}`);
throw new Error(`Upserting a user failed, error: ${JSON.stringify(_error)}`);
}
logger.info(`Upserting a user done, { data: ${JSON.stringify(_data)} }`);
} else {
const { data: _data, error: _error } = await supabase.from("users").insert(getDbDataFromUserProfile(user));
if (_error) {
logger.error(`Creating a new user record failed, error: ${JSON.stringify(_error)}`);
logger.error(context, `Creating a new user record failed, error: ${JSON.stringify(_error)}`);
throw new Error(`Creating a new user record failed, error: ${JSON.stringify(_error)}`);
}
logger.info(`Creating a new user record done, { data: ${JSON.stringify(_data)} }`);
Expand All @@ -203,13 +203,13 @@ export const upsertUser = async (user: UserProfile): Promise<void> => {
* @param username The user name you want to upsert a wallet address for
* @param address The account address
*/
export const upsertWalletAddress = async (username: string, address: string): Promise<void> => {
export const upsertWalletAddress = async (context: BotContext, username: string, address: string): Promise<void> => {
const logger = getLogger();
const { supabase } = getAdapters();

const { data, error } = await supabase.from("wallets").select("user_name").eq("user_name", username);
if (error) {
logger.error(`Checking wallet address failed, error: ${JSON.stringify(error)}`);
logger.error(context, `Checking wallet address failed, error: ${JSON.stringify(error)}`);
throw new Error(`Checking wallet address failed, error: ${JSON.stringify(error)}`);
}

Expand All @@ -220,7 +220,7 @@ export const upsertWalletAddress = async (username: string, address: string): Pr
updated_at: new Date().toUTCString(),
});
if (_error) {
logger.error(`Upserting a wallet address failed, error: ${JSON.stringify(_error)}`);
logger.error(context, `Upserting a wallet address failed, error: ${JSON.stringify(_error)}`);
throw new Error(`Upserting a wallet address failed, error: ${JSON.stringify(_error)}`);
}
logger.info(`Upserting a wallet address done, { data: ${JSON.stringify(_data)} }`);
Expand All @@ -232,7 +232,7 @@ export const upsertWalletAddress = async (username: string, address: string): Pr
updated_at: new Date().toUTCString(),
});
if (error) {
logger.error(`Creating a new wallet_table record failed, error: ${JSON.stringify(error)}`);
logger.error(context, `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)}, address: $address }`);
Expand All @@ -244,13 +244,13 @@ export const upsertWalletAddress = async (username: string, address: string): Pr
* @param username The user name you want to upsert a wallet address for
* @param address The account multiplier
*/
export const upsertWalletMultiplier = async (username: string, multiplier: string, reason: string, org_id: string): Promise<void> => {
export const upsertWalletMultiplier = async (context: BotContext, username: string, multiplier: string, reason: string, org_id: string): Promise<void> => {
const logger = getLogger();
const { supabase } = getAdapters();

const { data, error } = await supabase.from("multiplier").select("user_id").eq("user_id", `${username}_${org_id}`);
if (error) {
logger.error(`Checking wallet multiplier failed, error: ${JSON.stringify(error)}`);
logger.error(context, `Checking wallet multiplier failed, error: ${JSON.stringify(error)}`);
throw new Error(`Checking wallet multiplier failed, error: ${JSON.stringify(error)}`);
}

Expand All @@ -262,7 +262,7 @@ export const upsertWalletMultiplier = async (username: string, multiplier: strin
updated_at: new Date().toUTCString(),
});
if (_error) {
logger.error(`Upserting a wallet multiplier failed, error: ${JSON.stringify(_error)}`);
logger.error(context, `Upserting a wallet multiplier failed, error: ${JSON.stringify(_error)}`);
throw new Error(`Upserting a wallet multiplier failed, error: ${JSON.stringify(_error)}`);
}
logger.info(`Upserting a wallet multiplier done, { data: ${JSON.stringify(_data)} }`);
Expand All @@ -275,7 +275,7 @@ export const upsertWalletMultiplier = async (username: string, multiplier: strin
updated_at: new Date().toUTCString(),
});
if (_error) {
logger.error(`Creating a new multiplier record failed, error: ${JSON.stringify(_error)}`);
logger.error(context, `Creating a new multiplier record failed, error: ${JSON.stringify(_error)}`);
throw new Error(`Creating a new multiplier record failed, error: ${JSON.stringify(_error)}`);
}
logger.info(`Creating a new multiplier record done, { data: ${JSON.stringify(_data)} }`);
Expand All @@ -289,13 +289,13 @@ export const upsertWalletMultiplier = async (username: string, multiplier: strin
* @param access Access granting
* @param bool Disabling or enabling
*/
export const upsertAccessControl = async (username: string, repository: string, access: string, bool: boolean): Promise<void> => {
export const upsertAccessControl = async (context: BotContext, username: string, repository: string, access: string, bool: boolean): Promise<void> => {
const logger = getLogger();
const { supabase } = getAdapters();

const { data, error } = await supabase.from("access").select("user_name").eq("user_name", username).eq("repository", repository);
if (error) {
logger.error(`Checking access control failed, error: ${JSON.stringify(error)}`);
logger.error(context, `Checking access control failed, error: ${JSON.stringify(error)}`);
throw new Error(`Checking access control failed, error: ${JSON.stringify(error)}`);
}

Expand All @@ -309,7 +309,7 @@ export const upsertAccessControl = async (username: string, repository: string,
if (data && data.length > 0) {
const { data: _data, error: _error } = await supabase.from("access").upsert(properties);
if (_error) {
logger.error(`Upserting a access control failed, error: ${JSON.stringify(_error)}`);
logger.error(context, `Upserting a access control failed, error: ${JSON.stringify(_error)}`);
throw new Error(`Upserting a access control failed, error: ${JSON.stringify(_error)}`);
}
logger.info(`Upserting a access control done, { data: ${JSON.stringify(_data)} }`);
Expand All @@ -323,7 +323,7 @@ export const upsertAccessControl = async (username: string, repository: string,
...properties,
});
if (_error) {
logger.error(`Creating a new access control record failed, error: ${JSON.stringify(_error)}`);
logger.error(context, `Creating a new access control record failed, error: ${JSON.stringify(_error)}`);
throw new Error(`Creating a new access control record failed, error: ${JSON.stringify(_error)}`);
}
logger.info(`Creating a new access control record done, { data: ${JSON.stringify(_data)} }`);
Expand Down
5 changes: 2 additions & 3 deletions src/bindings/config.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import ms from "ms";

import { BotConfig, BotConfigSchema, LogLevel } from "../types";
import { BotContext, BotConfig, BotConfigSchema, LogLevel } from "../types";
import { getPayoutConfigByNetworkId } from "../helpers";
import { ajv } from "../utils";
import { Context } from "probot";
import { getScalarKey, getWideConfig } from "../utils/private";

export const loadConfig = async (context: Context): Promise<BotConfig> => {
export const loadConfig = async (context: BotContext): Promise<BotConfig> => {
const {
baseMultiplier,
timeLabels,
Expand Down
10 changes: 5 additions & 5 deletions src/bindings/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ export const getAdapters = () => adapters;
export type Logger = {
info: (msg: string | object, options?: JSON) => void;
debug: (msg: string | object, options?: JSON) => void;
warn: (msg: string | object, options?: JSON) => void;
error: (msg: string | object, options?: JSON) => void;
warn: (context: BotContext, msg: string | object, options?: JSON) => void;
error: (context: BotContext, msg: string | object, options?: JSON) => void;
};

let logger: Logger;
Expand Down Expand Up @@ -58,7 +58,7 @@ export const bindEvents = async (_context: ProbotContext): Promise<void> => {
}

if (botConfigError) {
logger.error(botConfigError.toString());
logger.error(context, botConfigError.toString());
if (eventName === GithubEvent.PUSH_EVENT) {
await validateConfigChange(context);
}
Expand Down Expand Up @@ -93,7 +93,7 @@ export const bindEvents = async (_context: ProbotContext): Promise<void> => {
const valid = validate(payload);
if (!valid) {
logger.info("Payload schema validation failed!!!", payload);
if (validate.errors) logger.warn(validate.errors);
if (validate.errors) logger.warn(context, validate.errors);
return;
}

Expand All @@ -108,7 +108,7 @@ export const bindEvents = async (_context: ProbotContext): Promise<void> => {
// Get the handlers for the action
const handlers = processors[eventName];
if (!handlers) {
logger.warn(`No handler configured for event: ${eventName}`);
logger.warn(context, `No handler configured for event: ${eventName}`);
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/handlers/access/labels-access.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const handleLabelsAccess = async (context: BotContext) => {
if (!payload.label?.name) return;
const sender = payload.sender.login;
const repo = payload.repository;
const permissionLevel = await getUserPermission(sender, context);
const permissionLevel = await getUserPermission(context, sender);
// event in plain english
const eventName = payload.action === "labeled" ? "add" : "remove";
const labelName = payload.label.name;
Expand Down
4 changes: 2 additions & 2 deletions src/handlers/assign/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ export const commentWithAssignMessage = async (context: BotContext): Promise<voi
const commitMessage = `${flattened_assignees} ${deadLinePrefix} ${endDate.toUTCString().replace("GMT", "UTC")}`;
logger.debug(`Creating an issue comment, commit_msg: ${commitMessage}`);

await addCommentToIssue(context, commit_msg, payload.issue?.number);
await addCommentToIssue(context, commitMessage, payload.issue?.number);
};

export const closePullRequestForAnIssue = async (context: BotContext): Promise<void> => {
const logger = getLogger();
const payload = context.payload as Payload;
if (!payload.issue?.number) return;

const prs = await gitLinkedPrParser({
const prs = await gitLinkedPrParser(context, {
owner: payload.repository.owner.login,
repo: payload.repository.name,
issue_number: payload.issue.number,
Expand Down
2 changes: 1 addition & 1 deletion src/handlers/assign/auto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const checkPullRequests = async (context: BotContext) => {

// Loop through the pull requests and assign them to their respective issues if needed
for (const pull of pulls) {
const linkedIssue = await gitLinkedIssueParser({
const linkedIssue = await gitLinkedIssueParser(context, {
owner: payload.repository.owner.login,
repo: payload.repository.name,
pull_number: pull.number,
Expand Down
8 changes: 4 additions & 4 deletions src/handlers/comment/handlers/allow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const setAccess = async (context: BotContext, body: string) => {
else if (part === "true" || part === "false") bool = part;
});
if (!accessType || !username || !bool) {
logger.error("Invalid body for allow command");
logger.error(context, "Invalid body for allow command");
return `Invalid syntax for allow \n usage: '/allow set-(access type) @user true|false' \n ex-1 /allow set-multiplier @user false`;
}
// Check if access control demand is valid
Expand All @@ -41,7 +41,7 @@ export const setAccess = async (context: BotContext, body: string) => {

// check if sender is admin
// passing in context so we don't have to make another request to get the user
const permissionLevel = await getUserPermission(sender, context);
const permissionLevel = await getUserPermission(context, sender);

// if sender is not admin, return
if (permissionLevel !== "admin") {
Expand All @@ -52,10 +52,10 @@ export const setAccess = async (context: BotContext, body: string) => {
// convert accessType to valid table
const tableName = `${accessType}_access`;

await upsertAccessControl(username, repo.full_name, tableName, bool === "true");
await upsertAccessControl(context, username, repo.full_name, tableName, bool === "true");
return `Updated access for @${username} successfully!\t Access: **${accessType}** for "${repo.full_name}"`;
} else {
logger.error("Invalid body for allow command");
logger.error(context, "Invalid body for allow command");
return `Invalid syntax for allow \n usage: '/allow set-(access type) @user true|false' \n ex-1 /allow set-multiplier @user false`;
}
};
2 changes: 1 addition & 1 deletion src/handlers/comment/handlers/authorize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const approveLabelChange = async (context: BotContext) => {

// check if sender is admin
// passing in context so we don't have to make another request to get the user
const permissionLevel = await getUserPermission(sender, context);
const permissionLevel = await getUserPermission(context, sender);

// if sender is not admin, return
if (permissionLevel !== "admin" && permissionLevel !== "billing_manager") {
Expand Down
10 changes: 5 additions & 5 deletions src/handlers/comment/handlers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,13 +181,13 @@ export const issueReopenedCallback = async (context: BotContext): Promise<void>
const permitComment = comments[permitCommentIdx];
const permitUrl = permitComment.body.match(claimUrlRegex);
if (!permitUrl || permitUrl.length < 2) {
logger.error(`Permit URL not found`);
logger.error(context, `Permit URL not found`);
return;
}
const url = new URL(permitUrl[1]);
const claimBase64 = url.searchParams.get("claim");
if (!claimBase64) {
logger.error(`Permit claim search parameter not found`);
logger.error(context, `Permit claim search parameter not found`);
return;
}
let networkId = url.searchParams.get("network");
Expand All @@ -199,7 +199,7 @@ export const issueReopenedCallback = async (context: BotContext): Promise<void>
try {
claim = JSON.parse(Buffer.from(claimBase64, "base64").toString("utf-8"));
} catch (err: unknown) {
logger.error(`Error parsing claim: ${err}`);
logger.error(context, `Error parsing claim: ${err}`);
return;
}
const amount = BigNumber.from(claim.permit.permitted.amount);
Expand All @@ -210,7 +210,7 @@ export const issueReopenedCallback = async (context: BotContext): Promise<void>
// find latest assignment before the permit comment
const events = await getAllIssueAssignEvents(context, issue.number);
if (events.length === 0) {
logger.error(`No assignment found`);
logger.error(context, `No assignment found`);
return;
}
const assignee = events[0].assignee.login;
Expand All @@ -220,7 +220,7 @@ export const issueReopenedCallback = async (context: BotContext): Promise<void>
try {
await addPenalty(assignee, repository.full_name, tokenAddress, networkId.toString(), amount);
} catch (err) {
logger.error(`Error writing penalty to db: ${err}`);
logger.error(context, `Error writing penalty to db: ${err}`);
return;
}

Expand Down
Loading

0 comments on commit bee6ac6

Please sign in to comment.