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 #15 from ubiquibot/development
Browse files Browse the repository at this point in the history
Merge develop into main
  • Loading branch information
gentlementlegen authored May 4, 2024
2 parents d3c6173 + 889de85 commit 6d6dd37
Show file tree
Hide file tree
Showing 12 changed files with 279 additions and 239 deletions.
21 changes: 6 additions & 15 deletions .github/.ubiquibot-config.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
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!"

incentives:
enabled: true
contentEvaluator:
Expand Down Expand Up @@ -77,8 +67,9 @@ incentives:

plugins:
'issues.closed':
- uses:
- plugin: ubiquity/conversation-rewards@testing/ubiquibot-v2-testing
type: github
with:
evmNetworkId: 100
- skipBotEvents: true
uses:
- plugin: ubiquibot/conversation-rewards@testing/ubiquibot-v2-testing
type: github
with:
evmNetworkId: 100
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Changelog

## 1.0.0 (2024-05-03)


### ⚠ BREAKING CHANGES

* added plugins type
* updated the config to match the new version
* enable on browser env ([#7](https://github.com/ubiquibot/configuration/issues/7))

### Features

* added jest testing and action ([cdca8ed](https://github.com/ubiquibot/configuration/commit/cdca8edfd257face4117837b4620253296c7f431))
* added plugins type ([02aa283](https://github.com/ubiquibot/configuration/commit/02aa28386e60b1c8190a35545120d3fc088de2e7))
* enable on browser env ([#7](https://github.com/ubiquibot/configuration/issues/7)) ([709dd26](https://github.com/ubiquibot/configuration/commit/709dd2621eaa556460a2add1f4f4e1540a6303a6))
* package creation for ubiquibot config ([7afa962](https://github.com/ubiquibot/configuration/commit/7afa9622cd8c30c27405104086af5d8ad05f58be))
* updated the config to match the new version ([0f777c8](https://github.com/ubiquibot/configuration/commit/0f777c8710919abb3439f0b280280705bb21e93d))
12 changes: 5 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ubiquibot/configuration",
"version": "2.0.3",
"version": "2.1.0",
"private": false,
"description": "Configuration helpers for Ubiquibot.",
"author": "Ubiquity DAO",
Expand Down Expand Up @@ -28,12 +28,11 @@
"dependencies": {},
"peerDependencies": {
"@octokit/webhooks": "12.2.0",
"@sinclair/typebox": "0.32.23",
"ajv": "8.13.0",
"ajv-formats": "3.0.1",
"@sinclair/typebox": "0.32.27",
"dotenv": "16.4.5",
"lodash": "4.17.21",
"ms": "2.1.3"
"ms": "2.1.3",
"typebox-validators": "0.3.5"
},
"devDependencies": {
"@commitlint/cli": "18.6.1",
Expand All @@ -55,8 +54,6 @@
"@types/node": "20.11.19",
"@typescript-eslint/eslint-plugin": "7.0.1",
"@typescript-eslint/parser": "7.0.1",
"ajv": "8.12.0",
"ajv-formats": "3.0.1",
"cspell": "8.3.2",
"dotenv": "16.4.5",
"esbuild": "0.20.0",
Expand All @@ -82,6 +79,7 @@
"ts-jest": "29.1.2",
"tslib": "2.6.2",
"tsx": "4.7.1",
"typebox-validators": "0.3.5",
"typescript": "5.3.3"
},
"lint-staged": {
Expand Down
8 changes: 4 additions & 4 deletions src/types/configuration-types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ObjectOptions, Static, StaticDecode, StringOptions, TProperties, Type as T } from "@sinclair/typebox";
import ms from "ms";
import { ajv } from "../utils";
import { StandardValidator } from "typebox-validators";
import { contentEvaluatorConfigurationType } from "./configuration/content-evaluator-config";
import { dataPurgeConfigurationType } from "./configuration/data-purge-config";
import { formattingEvaluatorConfigurationType } from "./configuration/formatting-evaluator-config";
Expand Down Expand Up @@ -59,10 +59,10 @@ export const envConfigSchema = T.Object({
APP_ID: T.Number(),
});

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

const botConfigSchema = strictObject(
export const botConfigSchema = strictObject(
{
keys: strictObject({
evmPrivateEncrypted: T.Optional(T.String()),
Expand Down Expand Up @@ -119,6 +119,6 @@ const botConfigSchema = strictObject(
},
{ default: undefined } // top level object can't have default!
);
export const validateBotConfig = ajv.compile(botConfigSchema);
export const validateBotConfig = new StandardValidator(botConfigSchema);

export type BotConfig = StaticDecode<typeof botConfigSchema>;
2 changes: 1 addition & 1 deletion src/types/configuration/plugin-configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type GithubPlugin = {
ref?: string;
};

function githubPluginType() {
export function githubPluginType() {
return T.Transform(T.String())
.Decode((value) => {
const matches = value.match(pluginNameRegex);
Expand Down
38 changes: 0 additions & 38 deletions src/utils/ajv.ts

This file was deleted.

43 changes: 31 additions & 12 deletions src/utils/generate-configuration.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { Value } from "@sinclair/typebox/value";
import { DefinedError } from "ajv";
import mergeWith from "lodash/merge";
import YAML from "yaml";
import { BotConfig, stringDuration, validateBotConfig } from "../types";
import { BotConfig, botConfigSchema, stringDuration, validateBotConfig } from "../types";
// @ts-expect-error gets transformed by rollup
import orgConfig from "../../.github/.ubiquibot-config.yml";
import { githubPluginType } from "../types/configuration/plugin-configuration";

export function generateConfiguration(repoConfig?: BotConfig): BotConfig {
const merged = mergeWith({}, orgConfig, repoConfig, (objValue: unknown, srcValue: unknown) => {
const defaultConfig = Value.Default(botConfigSchema, {}) as BotConfig;

const merged = mergeWith(defaultConfig, orgConfig, repoConfig, (objValue: unknown, srcValue: unknown) => {
if (Array.isArray(objValue) && Array.isArray(srcValue)) {
// if it's string array, concat and remove duplicates
if (objValue.every((value) => typeof value === "string")) {
Expand All @@ -18,12 +20,12 @@ export function generateConfiguration(repoConfig?: BotConfig): BotConfig {
}
});

const isValid = validateBotConfig(merged);
if (!isValid) {
const errorMessage = getErrorMsg(validateBotConfig.errors as DefinedError[]);
if (errorMessage) {
throw new Error(`Invalid merged configuration: ${errorMessage}`);
if (!validateBotConfig.test(merged)) {
const errors = validateBotConfig.errors(merged);
for (const error of errors) {
console.error(error);
}
throw new Error("Invalid configuration.");
}

// this will run transform functions
Expand All @@ -33,7 +35,6 @@ export function generateConfiguration(repoConfig?: BotConfig): BotConfig {
console.error(`Could not transform the configuration: ${err}`);
throw err;
}

return merged as BotConfig;
}

Expand Down Expand Up @@ -74,12 +75,30 @@ export function transformConfig(config: BotConfig) {
errorMsg += `Invalid taskDisqualifyDuration value: ${decodeError.value}\n`;
}
}
errorMsg += transformUseReferences(config);
if (errorMsg) throw new Error(errorMsg);
}

function getErrorMsg(errors: DefinedError[]) {
const errorsWithoutStrict = errors.filter((error) => error.keyword !== "additionalProperties");
return errorsWithoutStrict.length === 0 ? null : errorsWithoutStrict.map((error) => error.instancePath.replaceAll("/", ".") + " " + error.message).join("\n");
function transformUseReferences(config: BotConfig) {
let errorMsg = "";
try {
for (const plugins of Object.values(config.plugins)) {
for (const plugin of plugins) {
for (const use of plugin.uses) {
// This case happens if the object was not transformed before, otherwise the value can be safely be ignored
if (typeof use.plugin === "string") {
use.plugin = Value.Decode(githubPluginType(), use.plugin);
}
}
}
}
} catch (err: unknown) {
const decodeError = err as DecodeError;
if (decodeError.value) {
errorMsg += `Invalid plugin use value: ${decodeError.value}\n`;
}
}
return errorMsg;
}

/**
Expand Down
1 change: 0 additions & 1 deletion src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export * from "./ajv";
export * from "./generate-configuration";
10 changes: 2 additions & 8 deletions tests/__mocks__/test-default-conf-obj.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
const defaultConfig = {
"price-multiplier": 1.5,
"command-settings": [
{
name: "start",
enabled: false,
},
],
incentives: {
enabled: true,
contentEvaluator: {
Expand Down Expand Up @@ -104,9 +97,10 @@ const defaultConfig = {
plugins: {
"issues.closed": [
{
skipBotEvents: true,
uses: [
{
plugin: "ubiquity/conversation-rewards@testing/ubiquibot-v2-testing",
plugin: "ubiquibot/conversation-rewards@testing/ubiquibot-v2-testing",
type: "github",
with: {
evmNetworkId: 100,
Expand Down
14 changes: 6 additions & 8 deletions tests/__mocks__/test-valid-conf-obj.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
const validConfig = {
"price-multiplier": 1.5,
"command-settings": [
{
name: "start",
enabled: false,
},
],
keys: {},
features: {
assistivePricing: false,
Expand Down Expand Up @@ -149,7 +142,12 @@ const validConfig = {
skipBotEvents: true,
uses: [
{
plugin: "ubiquity/conversation-rewards@testing/ubiquibot-v2-testing",
plugin: {
owner: "ubiquibot",
ref: "testing/ubiquibot-v2-testing",
repo: "conversation-rewards",
workflowId: "compute.yml",
},
type: "github",
with: {
evmNetworkId: 100,
Expand Down
70 changes: 66 additions & 4 deletions tests/__mocks__/test-valid-config.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,66 @@
price-multiplier: 1.5
command-settings:
- name: start
enabled: false
incentives:
enabled: true
contentEvaluator:
enabled: true
userExtractor:
enabled: true
redeemTask: true
dataPurge:
enabled: true
formattingEvaluator:
enabled: true
scores:
br: 0
code: 1
p: 1
em: 0
img: 0
strong: 0
blockquote: 0
h1: 1
h2: 1
h3: 1
h4: 1
h5: 1
h6: 1
a: 1
li: 1
td: 1
hr: 0
multipliers:
- type: [ ISSUE, ISSUER, SPECIFICATION ]
formattingMultiplier: 1
wordValue: 0.1
- type: [ ISSUE, ISSUER, COMMENTED ]
formattingMultiplier: 1
wordValue: 0.2
- type: [ ISSUE, ASSIGNEE, COMMENTED ]
formattingMultiplier: 0
wordValue: 0
- type: [ ISSUE, COLLABORATOR, COMMENTED ]
formattingMultiplier: 1
wordValue: 0.1
- type: [ ISSUE, CONTRIBUTOR, COMMENTED ]
formattingMultiplier: 0.25
wordValue: 0.1
- type: [ REVIEW, ISSUER, TASK ]
formattingMultiplier: 0
wordValue: 0
- type: [ REVIEW, ISSUER, COMMENTED ]
formattingMultiplier: 2
wordValue: 0.2
- type: [ REVIEW, ASSIGNEE, COMMENTED ]
formattingMultiplier: 1
wordValue: 0.1
- type: [ REVIEW, COLLABORATOR, COMMENTED ]
formattingMultiplier: 1
wordValue: 0.1
- type: [ REVIEW, CONTRIBUTOR, COMMENTED ]
formattingMultiplier: 0.25
wordValue: 0.1
permitGeneration:
enabled: true
githubComment:
enabled: true
post: true
debug: false
Loading

0 comments on commit 6d6dd37

Please sign in to comment.