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 #17 from gentlementlegen/fix/cleanup-configuration
Browse files Browse the repository at this point in the history
feat!: configuration cleaned up from the old version
  • Loading branch information
gitcoindev authored May 7, 2024
2 parents 889de85 + 77c2fbd commit b85c169
Show file tree
Hide file tree
Showing 16 changed files with 17 additions and 553 deletions.
67 changes: 0 additions & 67 deletions .github/.ubiquibot-config.yml
Original file line number Diff line number Diff line change
@@ -1,70 +1,3 @@
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

plugins:
'issues.closed':
- skipBotEvents: true
Expand Down
68 changes: 0 additions & 68 deletions src/types/configuration-types.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,7 @@
import { ObjectOptions, Static, StaticDecode, StringOptions, TProperties, Type as T } from "@sinclair/typebox";
import ms from "ms";
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";
import { githubCommentConfigurationType } from "./configuration/github-comment-config";
import { permitGenerationConfigurationType } from "./configuration/permit-generation-configuration";
import { pluginConfigurationSchema } from "./configuration/plugin-configuration";
import { userExtractorConfigurationType } from "./configuration/user-extractor-config";

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.";

export enum LogLevel {
FATAL = "fatal",
Expand All @@ -22,12 +11,6 @@ export enum LogLevel {
DEBUG = "debug",
}

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 });
}
Expand Down Expand Up @@ -64,57 +47,6 @@ export type EnvConfigType = Static<typeof envConfigSchema>;

export 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({
enabled: T.Boolean({ default: true }),
contentEvaluator: contentEvaluatorConfigurationType,
userExtractor: userExtractorConfigurationType,
dataPurge: dataPurgeConfigurationType,
formattingEvaluator: formattingEvaluatorConfigurationType,
permitGeneration: permitGenerationConfigurationType,
githubComment: githubCommentConfigurationType,
}),
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 }),
}),
plugins: pluginConfigurationSchema,
},
{ default: undefined } // top level object can't have default!
Expand Down
38 changes: 0 additions & 38 deletions src/types/configuration/comment-types.ts

This file was deleted.

10 changes: 0 additions & 10 deletions src/types/configuration/common-incentive-config-type.ts

This file was deleted.

10 changes: 0 additions & 10 deletions src/types/configuration/content-evaluator-config.ts

This file was deleted.

10 changes: 0 additions & 10 deletions src/types/configuration/data-purge-config.ts

This file was deleted.

27 changes: 0 additions & 27 deletions src/types/configuration/formatting-evaluator-config.ts

This file was deleted.

18 changes: 0 additions & 18 deletions src/types/configuration/github-comment-config.ts

This file was deleted.

8 changes: 0 additions & 8 deletions src/types/configuration/index.ts

This file was deleted.

10 changes: 0 additions & 10 deletions src/types/configuration/permit-generation-configuration.ts

This file was deleted.

14 changes: 0 additions & 14 deletions src/types/configuration/user-extractor-config.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export * from "./configuration-types";
export * from "./valid-html-elements";
export * from "./configuration";
34 changes: 1 addition & 33 deletions src/utils/generate-configuration.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Value } from "@sinclair/typebox/value";
import mergeWith from "lodash/merge";
import YAML from "yaml";
import { BotConfig, botConfigSchema, stringDuration, validateBotConfig } from "../types";
// @ts-expect-error gets transformed by rollup
import orgConfig from "../../.github/.ubiquibot-config.yml";
import { BotConfig, botConfigSchema, validateBotConfig } from "../types";
import { githubPluginType } from "../types/configuration/plugin-configuration";

export function generateConfiguration(repoConfig?: BotConfig): BotConfig {
Expand Down Expand Up @@ -43,38 +43,6 @@ export function generateConfiguration(repoConfig?: BotConfig): BotConfig {
// That's why we have transform every field manually and catch errors
export function transformConfig(config: BotConfig) {
let errorMsg = "";
try {
config.timers.reviewDelayTolerance = Value.Decode(stringDuration(), config.timers.reviewDelayTolerance);
} catch (err: unknown) {
const decodeError = err as DecodeError;
if (decodeError.value) {
errorMsg += `Invalid reviewDelayTolerance value: ${decodeError.value}\n`;
}
}
try {
config.timers.taskStaleTimeoutDuration = Value.Decode(stringDuration(), config.timers.taskStaleTimeoutDuration);
} catch (err: unknown) {
const decodeError = err as DecodeError;
if (decodeError.value) {
errorMsg += `Invalid taskStaleTimeoutDuration value: ${decodeError.value}\n`;
}
}
try {
config.timers.taskFollowUpDuration = Value.Decode(stringDuration(), config.timers.taskFollowUpDuration);
} catch (err: unknown) {
const decodeError = err as DecodeError;
if (decodeError.value) {
errorMsg += `Invalid taskFollowUpDuration value: ${decodeError.value}\n`;
}
}
try {
config.timers.taskDisqualifyDuration = Value.Decode(stringDuration(), config.timers.taskDisqualifyDuration);
} catch (err: unknown) {
const decodeError = err as DecodeError;
if (decodeError.value) {
errorMsg += `Invalid taskDisqualifyDuration value: ${decodeError.value}\n`;
}
}
errorMsg += transformUseReferences(config);
if (errorMsg) throw new Error(errorMsg);
}
Expand Down
Loading

1 comment on commit b85c169

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

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

Lines Statements Branches Functions
Coverage: 82%
80.41% (78/97) 36% (9/25) 60% (9/15)

JUnit

Tests Skipped Failures Errors Time
3 0 💤 0 ❌ 0 🔥 4.516s ⏱️
Coverage Report (82%)
File% Stmts% Branch% Funcs% LinesUncovered Line #s
All files80.41366082.1 
   .github100100100100 
   .ubiquibot-config.yml100100100100 
src100100100100 
   index.ts100100100100 
src/types76404076 
   configuration-types.ts72.72404072.7219–27
   index.ts100100100100 
   valid-html-elements.ts100100100100 
src/types/configuration9033.337590 
   plugin-configuration.ts84.6133.3366.6684.6119, 29
   webhook-events.ts100100100100 
src/utils77.5536.3666.6680.85 
   generate-configuration.ts77.0836.3666.6680.4313–19, 35–36, 64–66
   index.ts100100100100 

Please sign in to comment.