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

Commit

Permalink
Merge pull request #2 from FernandVEYRIER/feat/package
Browse files Browse the repository at this point in the history
feat: ubiquibot configuration package
  • Loading branch information
0x4007 authored Feb 19, 2024
2 parents 4b10b8c + 9086669 commit 2333281
Show file tree
Hide file tree
Showing 23 changed files with 6,829 additions and 6,816 deletions.
9 changes: 9 additions & 0 deletions .github/ubiquibot-config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
price-multiplier: 1.5
command-settings:
- name: start
enabled: false
# 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!"
28 changes: 28 additions & 0 deletions .github/workflows/publish-package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: publish-package

on:
workflow_dispatch:
push:
branches:
- main

jobs:
release-please:
runs-on: ubuntu-latest
steps:
- uses: google-github-actions/release-please-action@v3
with:
release-type: node
package-name: @ubiquibot/configuration
default-branch: main
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '20.10.0'
registry-url: https://registry.npmjs.org/
- run: |
yarn install --immutable --immutable-cache --check-cache
yarn pack
yarn publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ node_modules
.pnp.cjs
.pnp.loader.mjs
static/dist
.env
.env

*.tgz
Empty file added .npmignore
Empty file.
9 changes: 2 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
# `@ubiquity/ts-template`
# `@ubiquibot/configuration`

This template repository includes support for the following:

- TypeScript
- Environment Variables
- Conventional Commits
- Automatic deployment to Cloudflare Pages
Helpers to parse and merge configuration files for Ubiquibot.
33 changes: 0 additions & 33 deletions build/esbuild-build.ts

This file was deleted.

18 changes: 0 additions & 18 deletions build/esbuild-server.ts

This file was deleted.

4 changes: 0 additions & 4 deletions build/index.ts

This file was deleted.

66 changes: 40 additions & 26 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"name": "ts-template",
"name": "@ubiquibot/configuration",
"version": "1.0.0",
"description": "Template repository with TypeScript support.",
"main": "build/index.ts",
"private": false,
"description": "Configuration helpers for Ubiquibot.",
"main": "src/index.ts",
"author": "Ubiquity DAO",
"license": "MIT",
"engines": {
Expand All @@ -25,30 +26,38 @@
"open-source"
],
"dependencies": {
"dotenv": "^16.3.1"
"@sinclair/typebox": "0.32.14",
"ajv": "8.12.0",
"ajv-formats": "2.1.1",
"dotenv": "16.4.4",
"lodash": "4.17.21",
"ms": "2.1.3",
"ubiquibot-logger": "0.3.5"
},
"devDependencies": {
"@commitlint/cli": "^18.4.3",
"@commitlint/config-conventional": "^18.4.3",
"@cspell/dict-node": "^4.0.3",
"@cspell/dict-software-terms": "^3.3.17",
"@cspell/dict-typescript": "^3.1.2",
"@types/node": "^20.10.0",
"@typescript-eslint/eslint-plugin": "^6.13.1",
"@typescript-eslint/parser": "^6.13.1",
"cspell": "^8.3.2",
"esbuild": "^0.19.8",
"eslint": "^8.54.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-prettier": "^5.0.1",
"eslint-plugin-sonarjs": "^0.23.0",
"husky": "^8.0.3",
"knip": "^3.3.0",
"lint-staged": "^15.1.0",
"npm-run-all": "^4.1.5",
"prettier": "^3.1.0",
"tsx": "^4.6.0",
"typescript": "^5.3.2"
"@commitlint/cli": "18.6.1",
"@commitlint/config-conventional": "18.6.2",
"@cspell/dict-node": "4.0.3",
"@cspell/dict-software-terms": "3.3.18",
"@cspell/dict-typescript": "3.1.2",
"@types/lodash": "4.14.202",
"@types/ms": "0.7.34",
"@types/node": "20.11.19",
"@typescript-eslint/eslint-plugin": "7.0.1",
"@typescript-eslint/parser": "7.0.1",
"cspell": "8.3.2",
"esbuild": "0.20.0",
"eslint": "8.56.0",
"eslint-config-prettier": "9.1.0",
"eslint-plugin-prettier": "5.1.3",
"eslint-plugin-sonarjs": "0.24.0",
"husky": "9.0.11",
"knip": "5.0.1",
"lint-staged": "15.2.2",
"npm-run-all": "4.1.5",
"prettier": "3.2.5",
"tsx": "4.7.1",
"typescript": "5.3.3"
},
"lint-staged": {
"*.ts": [
Expand All @@ -63,5 +72,10 @@
"extends": [
"@commitlint/config-conventional"
]
}
},
"files": [
"src/*",
"README.md",
"package.json"
]
}
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from "./types";
export * from "./utils";
120 changes: 120 additions & 0 deletions src/types/configuration-types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
import { ObjectOptions, Static, StaticDecode, StringOptions, TProperties, Type as T } from "@sinclair/typebox";
import ms from "ms";
import { LogLevel } from "ubiquibot-logger/pretty-logs";

import { ajv } from "../utils/ajv";
import { validHTMLElements } from "./valid-html-elements";

const promotionComment =
"###### If you enjoy the DevPool experience, please follow [Ubiquity on GitHub](https://github.com/ubiquity) and star [this repo](https://github.com/ubiquity/devpool-directory) to show your support. It helps a lot!";
const defaultGreetingHeader =
"Thank you for contributing! Please be sure to set your wallet address before completing your first task so that you can collect your reward.";

const htmlEntities = validHTMLElements.map((value) => T.Literal(value));

const allHtmlElementsSetToZero = validHTMLElements.reduce(
(accumulator, current) => {
accumulator[current] = 0;
return accumulator;
},
{} as Record<keyof HTMLElementTagNameMap, number>
);

const allCommands = ["start", "stop", "help", "query", "ask", "multiplier", "labels", "authorize", "wallet"] as const;

const defaultTimeLabels = ["Time: <1 Hour", "Time: <2 Hours", "Time: <4 Hours", "Time: <1 Day", "Time: <1 Week"];

const defaultPriorityLabels = ["Priority: 1 (Normal)", "Priority: 2 (Medium)", "Priority: 3 (High)", "Priority: 4 (Urgent)", "Priority: 5 (Emergency)"];

function strictObject<T extends TProperties>(obj: T, options?: ObjectOptions) {
return T.Object<T>(obj, { additionalProperties: false, default: {}, ...options });
}

export function stringDuration(options?: StringOptions) {
return T.Transform(T.String(options))
.Decode((value) => {
const decoded = ms(value);
if (decoded === undefined || isNaN(decoded)) {
throw new Error(`Invalid duration string: ${value}`);
}
return ms(value);
})
.Encode((value) => ms(value));
}

const envConfigSchema = T.Object({
WEBHOOK_PROXY_URL: T.Optional(T.String({ format: "uri" })), // optional for production
LOG_LEVEL: T.Enum(LogLevel, { default: LogLevel.DEBUG }),
LOG_RETRY_LIMIT: T.Number({ default: 8 }),
SUPABASE_URL: T.String({ format: "uri" }),
SUPABASE_KEY: T.String(),
PRIVATE_KEY: T.String(),
APP_ID: T.Number(),
});

export const validateEnvConfig = ajv.compile(envConfigSchema);
export type EnvConfig = Static<typeof envConfigSchema>;

const botConfigSchema = strictObject(
{
keys: strictObject({
evmPrivateEncrypted: T.Optional(T.String()),
openAi: T.Optional(T.String()),
}),
features: strictObject({
assistivePricing: T.Boolean({ default: false }),
defaultLabels: T.Array(T.String(), { default: [] }),
newContributorGreeting: strictObject({
enabled: T.Boolean({ default: false }),
header: T.String({ default: defaultGreetingHeader }),
displayHelpMenu: T.Boolean({ default: true }),
footer: T.String({ default: promotionComment }),
}),
publicAccessControl: strictObject({
setLabel: T.Boolean({ default: true }),
fundExternalClosedIssue: T.Boolean({ default: true }),
}),
isNftRewardEnabled: T.Boolean({ default: false }),
}),

timers: strictObject({
reviewDelayTolerance: stringDuration({ default: "1 day" }),
taskStaleTimeoutDuration: stringDuration({ default: "4 weeks" }),
taskFollowUpDuration: stringDuration({ default: "0.5 weeks" }),
taskDisqualifyDuration: stringDuration({ default: "1 week" }),
}),
payments: strictObject({
maxPermitPrice: T.Number({ default: Number.MAX_SAFE_INTEGER }),
evmNetworkId: T.Number({ default: 1 }),
basePriceMultiplier: T.Number({ default: 1 }),
issueCreatorMultiplier: T.Number({ default: 1 }),
}),
disabledCommands: T.Array(T.String(), { default: allCommands }),
incentives: strictObject({
comment: strictObject({
elements: T.Record(T.Union(htmlEntities), T.Number({ default: 0 }), { default: allHtmlElementsSetToZero }),
totals: strictObject({
character: T.Number({ default: 0, minimum: 0 }),
word: T.Number({ default: 0, minimum: 0 }),
sentence: T.Number({ default: 0, minimum: 0 }),
paragraph: T.Number({ default: 0, minimum: 0 }),
comment: T.Number({ default: 0, minimum: 0 }),
}),
}),
}),
labels: strictObject({
time: T.Array(T.String(), { default: defaultTimeLabels }),
priority: T.Array(T.String(), { default: defaultPriorityLabels }),
}),
miscellaneous: strictObject({
maxConcurrentTasks: T.Number({ default: Number.MAX_SAFE_INTEGER }),
promotionComment: T.String({ default: promotionComment }),
registerWalletWithVerification: T.Boolean({ default: false }),
openAiTokenLimit: T.Number({ default: 100000 }),
}),
},
{ default: undefined } // top level object can't have default!
);
export const validateBotConfig = ajv.compile(botConfigSchema);

export type BotConfig = StaticDecode<typeof botConfigSchema>;
2 changes: 2 additions & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from "./configuration-types";
export * from "./valid-html-elements";
Loading

1 comment on commit 2333281

@ubiquibot
Copy link

@ubiquibot ubiquibot bot commented on 2333281 Feb 19, 2024

Choose a reason for hiding this comment

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

@pavlovcik Valid configuration.

Warning! Unnecessary properties:
.price-multiplier
.command-settings

Please sign in to comment.