Skip to content

Commit

Permalink
Merge pull request #58 from gentlementlegen/fix/configuration-improve…
Browse files Browse the repository at this point in the history
…ments

fix!: configuration improvements
  • Loading branch information
gentlementlegen authored Jul 26, 2024
2 parents 6d8bd23 + 1aa9f3a commit d862d53
Show file tree
Hide file tree
Showing 28 changed files with 363 additions and 428 deletions.
29 changes: 11 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Reward formula: `((count * wordValue) * (score * formattingMultiplier) * n) * re

## Plugin configuration

Here is a possible valid configuration to enable this plugin.
Here is a possible valid configuration to enable this plugin. See [these files](./src/configuration) for more details.


```yaml
Expand All @@ -59,17 +59,12 @@ with:
maxAttempts: 10
delayMs: 10000
incentives:
enabled: true
requirePriceLabel: true
contentEvaluator:
enabled: true
userExtractor:
enabled: true
redeemTask: true
dataPurge:
enabled: true
formattingEvaluator:
enabled: true
scores:
br: 0
code: 1
Expand All @@ -89,40 +84,38 @@ with:
td: 1
hr: 0
multipliers:
- targets: [ ISSUE, ISSUER, SPECIFICATION ]
- select: [ ISSUE_SPECIFICATION ]
formattingMultiplier: 1
wordValue: 0.1
- targets: [ ISSUE, ISSUER, COMMENTED ]
- select: [ ISSUE_AUTHOR ]
formattingMultiplier: 1
wordValue: 0.2
- targets: [ ISSUE, ASSIGNEE, COMMENTED ]
- select: [ ISSUE_ASSIGNEE ]
formattingMultiplier: 0
wordValue: 0
- targets: [ ISSUE, COLLABORATOR, COMMENTED ]
- select: [ ISSUE_COLLABORATOR ]
formattingMultiplier: 1
wordValue: 0.1
- targets: [ ISSUE, CONTRIBUTOR, COMMENTED ]
- select: [ ISSUE_CONTRIBUTOR ]
formattingMultiplier: 0.25
wordValue: 0.1
- targets: [ REVIEW, ISSUER, TASK ]
- select: [ PULL_SPECIFICATION ]
formattingMultiplier: 0
wordValue: 0
- targets: [ REVIEW, ISSUER, COMMENTED ]
- select: [ PULL_AUTHOR ]
formattingMultiplier: 2
wordValue: 0.2
- targets: [ REVIEW, ASSIGNEE, COMMENTED ]
- select: [ PULL_ASSIGNEE ]
formattingMultiplier: 1
wordValue: 0.1
- targets: [ REVIEW, COLLABORATOR, COMMENTED ]
- select: [ PULL_COLLABORATOR ]
formattingMultiplier: 1
wordValue: 0.1
- targets: [ REVIEW, CONTRIBUTOR, COMMENTED ]
- select: [ PULL_CONTRIBUTOR ]
formattingMultiplier: 0.25
wordValue: 0.1
permitGeneration:
enabled: true
githubComment:
enabled: true
post: true
debug: false
```
31 changes: 15 additions & 16 deletions src/configuration/comment-types.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
export enum CommentType {
export enum CommentKind {
/**
* Review related item
* Pull-request related item
*/
REVIEW = 0b1,
PULL = 0b1,
/**
* Issue related item
*/
ISSUE = 0b10,
}

export enum CommentAssociation {
/**
* User assigned to the {@link CommentType.ISSUE} or {@link CommentType.REVIEW}
* User assigned to the {@link CommentKind.ISSUE} or {@link CommentKind.PULL}
*/
ASSIGNEE = 0b100,
/**
* The author of the {@link CommentType.ISSUE} or {@link CommentType.REVIEW}
* The author of the {@link CommentKind.ISSUE} or {@link CommentKind.PULL}
*/
ISSUER = 0b1000,
AUTHOR = 0b1000,
/**
* A user that is part of the organization or owner of the repo
*/
Expand All @@ -24,15 +27,11 @@ export enum CommentType {
*/
CONTRIBUTOR = 0b100000,
/**
* A user comment action on a {@link CommentType.ISSUE} or {@link CommentType.REVIEW}
*/
COMMENTED = 0b1000000,
/**
* Pull request opening item
*/
TASK = 0b10000000,
/**
* Issue opening item
* {@link CommentKind.ISSUE} or {@link CommentKind.PULL} opening item
*/
SPECIFICATION = 0b100000000,
SPECIFICATION = 0b10000000,
}

export const commentEnum = { ...CommentAssociation, ...CommentKind };

export type CommentType = `${keyof typeof CommentKind}_${keyof typeof CommentAssociation}`;
7 changes: 1 addition & 6 deletions src/configuration/content-evaluator-config.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import { Static, Type } from "@sinclair/typebox";

export const contentEvaluatorConfigurationType = Type.Object({
/**
* Enables or disables this module
*/
enabled: Type.Boolean({ default: true }),
});
export const contentEvaluatorConfigurationType = Type.Object({});

export type ContentEvaluatorConfiguration = Static<typeof contentEvaluatorConfigurationType>;
7 changes: 1 addition & 6 deletions src/configuration/data-purge-config.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import { Type, Static } from "@sinclair/typebox";

export const dataPurgeConfigurationType = Type.Object({
/**
* Enables or disables this module
*/
enabled: Type.Boolean({ default: true }),
});
export const dataPurgeConfigurationType = Type.Object({});

export type DataPurgeConfiguration = Static<typeof dataPurgeConfigurationType>;
34 changes: 17 additions & 17 deletions src/configuration/formatting-evaluator-config.ts
Original file line number Diff line number Diff line change
@@ -1,71 +1,71 @@
import { Static, Type } from "@sinclair/typebox";
import { CommentType } from "./comment-types";
import { CommentAssociation, CommentKind, CommentType } from "./comment-types";

const type = Type.Union([...Object.keys(CommentType).map((key) => Type.Literal(key as keyof typeof CommentType))]);
const type = Type.Union(
Object.keys(CommentKind).flatMap((kind) =>
Object.keys(CommentAssociation).map((association) => Type.Literal(`${kind}_${association}` as CommentType))
)
);

export const formattingEvaluatorConfigurationType = Type.Object({
/**
* Enables or disables this module
*/
enabled: Type.Boolean({ default: true }),
/**
* Multipliers applied to different parts of the comment body content
*/
multipliers: Type.Array(
Type.Object({
targets: Type.Array(type),
select: Type.Array(type),
formattingMultiplier: Type.Number(),
wordValue: Type.Number(),
}),
{
default: [
{
targets: ["ISSUE", "ISSUER", "SPECIFICATION"],
select: ["ISSUE_SPECIFICATION"],
formattingMultiplier: 1,
wordValue: 0.1,
},
{
targets: ["ISSUE", "ISSUER", "COMMENTED"],
select: ["ISSUE_AUTHOR"],
formattingMultiplier: 1,
wordValue: 0.2,
},
{
targets: ["ISSUE", "ASSIGNEE", "COMMENTED"],
select: ["ISSUE_ASSIGNEE"],
formattingMultiplier: 0,
wordValue: 0,
},
{
targets: ["ISSUE", "COLLABORATOR", "COMMENTED"],
select: ["ISSUE_COLLABORATOR"],
formattingMultiplier: 1,
wordValue: 0.1,
},
{
targets: ["ISSUE", "CONTRIBUTOR", "COMMENTED"],
select: ["ISSUE_CONTRIBUTOR"],
formattingMultiplier: 0.25,
wordValue: 0.1,
},
{
targets: ["REVIEW", "ISSUER", "TASK"],
select: ["PULL_SPECIFICATION"],
formattingMultiplier: 0,
wordValue: 0,
},
{
targets: ["REVIEW", "ISSUER", "COMMENTED"],
select: ["PULL_AUTHOR"],
formattingMultiplier: 2,
wordValue: 0.2,
},
{
targets: ["REVIEW", "ASSIGNEE", "COMMENTED"],
select: ["PULL_ASSIGNEE"],
formattingMultiplier: 1,
wordValue: 0.1,
},
{
targets: ["REVIEW", "COLLABORATOR", "COMMENTED"],
select: ["PULL_COLLABORATOR"],
formattingMultiplier: 1,
wordValue: 0.1,
},
{
targets: ["REVIEW", "CONTRIBUTOR", "COMMENTED"],
select: ["PULL_CONTRIBUTOR"],
formattingMultiplier: 0.25,
wordValue: 0.1,
},
Expand Down
4 changes: 0 additions & 4 deletions src/configuration/github-comment-config.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import { Static, Type } from "@sinclair/typebox";

export const githubCommentConfigurationType = Type.Object({
/**
* Enables or disables this module
*/
enabled: Type.Boolean({ default: true }),
/**
* Enables posting to the related GitHub Issue
*/
Expand Down
16 changes: 6 additions & 10 deletions src/configuration/incentives.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ export const incentivesConfigurationSchema = T.Object({
*/
erc20RewardToken: T.String({ default: "0xe91D153E0b41518A2Ce8Dd3D7944Fa863463a97d" }),
incentives: T.Object({
/**
* Enables or disables the incentive plugin
*/
enabled: T.Boolean({ default: true }),
/**
* Optionally specify a file to write the results in
*/
Expand All @@ -34,12 +30,12 @@ export const incentivesConfigurationSchema = T.Object({
* If set to true, the plugin runs even if the price label is missing, and will evaluate comments.
*/
requirePriceLabel: T.Boolean({ default: true }),
contentEvaluator: contentEvaluatorConfigurationType,
userExtractor: userExtractorConfigurationType,
dataPurge: dataPurgeConfigurationType,
formattingEvaluator: formattingEvaluatorConfigurationType,
permitGeneration: permitGenerationConfigurationType,
githubComment: githubCommentConfigurationType,
contentEvaluator: T.Union([contentEvaluatorConfigurationType, T.Null()]),
userExtractor: T.Union([userExtractorConfigurationType, T.Null()]),
dataPurge: T.Union([dataPurgeConfigurationType, T.Null()]),
formattingEvaluator: T.Union([formattingEvaluatorConfigurationType, T.Null()]),
permitGeneration: T.Union([permitGenerationConfigurationType, T.Null()]),
githubComment: T.Union([githubCommentConfigurationType, T.Null()]),
}),
dataCollection: dataCollectionConfigurationType,
});
Expand Down
7 changes: 1 addition & 6 deletions src/configuration/permit-generation-configuration.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import { Static, Type } from "@sinclair/typebox";

export const permitGenerationConfigurationType = Type.Object({
/**
* Enables or disables this module
*/
enabled: Type.Boolean({ default: true }),
});
export const permitGenerationConfigurationType = Type.Object({});

export type PermitGenerationConfiguration = Static<typeof permitGenerationConfigurationType>;
4 changes: 0 additions & 4 deletions src/configuration/user-extractor-config.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import { Static, Type } from "@sinclair/typebox";

export const userExtractorConfigurationType = Type.Object({
/**
* Enables or disables this module
*/
enabled: Type.Boolean({ default: true }),
/**
* Is the task redeemable, e.g. can the user collect the bounty?
*/
Expand Down
16 changes: 16 additions & 0 deletions src/helpers/result-replacer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { commentEnum } from "../configuration/comment-types";

export function typeReplacer(key: string, value: string | number) {
// Changes "type" to be human-readable
if (key === "type" && typeof value === "number") {
const typeNames: string[] = [];
const types = Object.values(commentEnum) as number[];
types.reverse().forEach((typeValue) => {
if (value & typeValue) {
typeNames.push(commentEnum[typeValue]);
}
});
return typeNames.join("_");
}
return value;
}
Loading

0 comments on commit d862d53

Please sign in to comment.