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

E2E tests #640

Open
wants to merge 18 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions .github/workflows/e2e-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
on:
- workflow_dispatch
- push

jobs:
e2e-test:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: "18.16.0"

- name: Install
run: yarn install

- name: Build
run: yarn build

- name: Test
env:
LOG_ENVIRONMENT: "production"
SUPABASE_URL: ${{ secrets.SUPABASE_URL }}
SUPABASE_KEY: ${{ secrets.SUPABASE_KEY }}
X25519_PRIVATE_KEY: "QCDb30UHUkwJAGhLWC-R2N0PiEbd4vQY6qH2Wloybyo"
Copy link
Member

Choose a reason for hiding this comment

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

Should this be exposed? Not sure exactly what it is used for.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

it's okay, it must be the same because the test's config wallet private key in encrypted with this private key

APP_ID: ${{ secrets.APP_ID }}
PRIVATE_KEY: ${{ secrets.PRIVATE_KEY }}
WEBHOOK_PROXY_URL: ${{ secrets.WEBHOOK_PROXY_URL }}
WEBHOOK_SECRET: ${{ secrets.WEBHOOK_SECRET }}
TEST_REPO: ${{ secrets.TEST_REPO }}
TEST_ORGANIZATION: ${{ secrets.TEST_ORGANIZATION }}
TEST_ADMIN_PAT: ${{ secrets.TEST_ADMIN_PAT }}
TEST_OUTSIDE_COLLABORATOR_PAT: ${{ secrets.TEST_OUTSIDE_COLLABORATOR_PAT }}
run: "yarn test:e2e"
1 change: 1 addition & 0 deletions .github/workflows/kebab-case.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jobs:
"^\.\/build"
"^\.\/vendor"
"^\.\/\.next"
"^\.\/tests"
"\.sql$"
"\.md$"
"\.d.ts$"
Expand Down
4 changes: 4 additions & 0 deletions jest.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"rootDir": "lib/",
"maxConcurrency": 1
}
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@
"lint": "eslint --ext .ts ./src",
"start:serverless": "tsx src/adapters/github/github-actions.ts",
"start:watch": "nodemon --exec 'yarn start'",
"start": "probot run ./lib/index.js",
"prepare": "husky install"
"start": "probot run ./lib/src/index.js",
"prepare": "husky install",
"test:e2e": "jest"
},
"dependencies": {
"@actions/core": "^1.10.0",
Expand Down Expand Up @@ -56,6 +57,7 @@
"node-html-parser": "^6.1.5",
"node-html-to-image": "^3.3.0",
"nodemon": "^2.0.19",
"octokit": "^3.1.0",
"openai": "^4.2.0",
"parse5": "^7.1.2",
0x4007 marked this conversation as resolved.
Show resolved Hide resolved
"prettier": "^2.7.1",
Expand All @@ -65,14 +67,15 @@
"yaml": "^2.2.2"
},
"devDependencies": {
"@jest/globals": "^29.6.2",
"@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",
"jest": "^26.6.3",
"jest": "^29.6.2",
"nock": "^13.0.5",
"rimraf": "3.0.2",
"smee-client": "^1.2.2",
Expand Down
15 changes: 8 additions & 7 deletions src/adapters/supabase/helpers/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,18 +347,19 @@ export const getAccessLevel = async (username: string, repository: string, label
return accessValues;
};

export const getAllAccessLevels = async (username: string, repository: string): Promise<null | AccessLevels> => {
export const getAllAccessLevels = async (username: string, repository: string): Promise<AccessLevels | null> => {
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
const { data, error } = await supabase.from("access").select("*").eq("user_name", username).eq("repository", repository);
if (error) {
logger.error(`Checking access control failed, error: ${JSON.stringify(error)}`);
throw new Error(`Checking access control failed, error: ${JSON.stringify(error)}`);
}
if (!data || data.length === 0) {
return null;
}
return { multiplier: data.multiplier_access, time: data.time_access, priority: data.priority_access, price: data.price_access };
return { multiplier: data[0].multiplier_access, time: data[0].time_access, priority: data[0].priority_access, price: data[0].price_access };
};

/**
Expand Down
3 changes: 2 additions & 1 deletion src/handlers/access/labels-access.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getAccessLevel } from "../../adapters/supabase";
import { getBotConfig, getBotContext, getLogger } from "../../bindings";
import { addCommentToIssue, getUserPermission, removeLabel, addLabelToIssue } from "../../helpers";
import { Payload } from "../../types";
import { Payload, UserType } from "../../types";

export const handleLabelsAccess = async () => {
const { accessControl } = getBotConfig();
Expand All @@ -12,6 +12,7 @@ export const handleLabelsAccess = async () => {
const payload = context.payload as Payload;
if (!payload.issue) return;
if (!payload.label?.name) return;
if (payload.sender.type === UserType.Bot) return true;
const sender = payload.sender.login;
const repo = payload.repository;
const permissionLevel = await getUserPermission(sender, context);
Expand Down
15 changes: 15 additions & 0 deletions src/handlers/payout/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import Decimal from "decimal.js";
import { bountyInfo } from "../wildcard";
import { IncentivesCalculationResult } from "./action";
import { BigNumber } from "ethers";
import { GLOBAL_STRINGS } from "../../configs";

export interface CreatorCommentResult {
title: string;
Expand Down Expand Up @@ -40,6 +41,20 @@ export const calculateIssueConversationReward = async (calculateIncentives: Ince
return { error: `incentivizeComments: skip to generate a permit url because it has been already posted` };
}

for (const botComment of permitComments.filter((cmt) => cmt.user.type === UserType.Bot).reverse()) {
const botCommentBody = botComment.body;
if (botCommentBody.includes(GLOBAL_STRINGS.autopayComment)) {
const pattern = /\*\*(\w+)\*\*/;
const res = botCommentBody.match(pattern);
if (res) {
if (res[1] === "false") {
return { error: "autopay is disabled" };
}
break;
}
}
}

const assignees = issue?.assignees ?? [];
const assignee = assignees.length > 0 ? assignees[0] : undefined;
if (!assignee) {
Expand Down
Loading