Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: undefined configuration #75

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
93ccc25
feat: html score is now based per select item
gentlementlegen Jul 23, 2024
baf7746
chore: fixed tests
gentlementlegen Jul 23, 2024
44904a9
chore: fixed tests
gentlementlegen Jul 23, 2024
45489d3
feat: multipliers are based on symbols representing a regex
gentlementlegen Jul 23, 2024
c345948
chore: fixing tests
gentlementlegen Jul 24, 2024
a372bab
chore: fixing tests
gentlementlegen Jul 24, 2024
5046c14
chore: fixing tests
gentlementlegen Jul 24, 2024
39bd186
chore: fixing tests
gentlementlegen Jul 24, 2024
c92d0a5
chore: fixing tests
gentlementlegen Jul 24, 2024
6a4d9f6
chore: fixing tests
gentlementlegen Jul 24, 2024
eca0aa0
chore: fixing tests
gentlementlegen Jul 24, 2024
d170c9f
chore: fixing tests
gentlementlegen Jul 24, 2024
b8c83c0
chore: fixing tests
gentlementlegen Jul 24, 2024
c2e9443
chore: updated README.md
gentlementlegen Jul 24, 2024
44bb136
chore: merge develop
gentlementlegen Jul 26, 2024
6a9361f
chore: default configuration to null
gentlementlegen Jul 26, 2024
23bc825
chore: fixed README.md and infinite division
gentlementlegen Jul 26, 2024
73458ba
chore: updated README.md
gentlementlegen Jul 26, 2024
5ec57f7
chore: changed total count
gentlementlegen Jul 26, 2024
1e5aedb
chore: optional formatting evaluator
gentlementlegen Jul 26, 2024
1e42677
chore: log configuration
gentlementlegen Jul 26, 2024
5717dc3
chore: log configuration
gentlementlegen Jul 26, 2024
8bf00cc
chore: null defaults for configuration
gentlementlegen Jul 26, 2024
7a64286
chore: null defaults for configuration
gentlementlegen Jul 26, 2024
e92faf0
Merge branch 'refs/heads/feat/symbol-coefficient' into fix/undefined-…
gentlementlegen Jul 26, 2024
af63549
chore: changed error message for module configuration
gentlementlegen Jul 26, 2024
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
68 changes: 39 additions & 29 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. See [these files](./src/configuration) for more details.
Here is a possible valid configuration to enable this plugin. See [these files](./src/configuration/) for more details.


```yaml
Expand All @@ -65,55 +65,65 @@ with:
redeemTask: true
dataPurge:
formattingEvaluator:
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:
- select: [ ISSUE_SPECIFICATION ]
formattingMultiplier: 1
wordValue: 0.1
symbols:
"\\b\\w+\\b": 0.1
scores: # Scores can be set for each item differently
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
- select: [ ISSUE_AUTHOR ]
formattingMultiplier: 1
wordValue: 0.2
symbols:
"\\b\\w+\\b": 0.2
- select: [ ISSUE_ASSIGNEE ]
formattingMultiplier: 0
wordValue: 0
symbols:
"\\b\\w+\\b": 0
- select: [ ISSUE_COLLABORATOR ]
formattingMultiplier: 1
wordValue: 0.1
symbols:
"\\b\\w+\\b": 0.1
- select: [ ISSUE_CONTRIBUTOR ]
formattingMultiplier: 0.25
wordValue: 0.1
symbols:
"\\b\\w+\\b": 0.1
- select: [ PULL_SPECIFICATION ]
formattingMultiplier: 0
wordValue: 0
symbols:
"\\b\\w+\\b": 0
- select: [ PULL_AUTHOR ]
formattingMultiplier: 2
wordValue: 0.2
symbols:
"\\b\\w+\\b": 0.2
- select: [ PULL_ASSIGNEE ]
formattingMultiplier: 1
wordValue: 0.1
symbols:
"\\b\\w+\\b": 0.1
- select: [ PULL_COLLABORATOR ]
formattingMultiplier: 1
wordValue: 0.1
symbols:
"\\b\\w+\\b": 0.1
- select: [ PULL_CONTRIBUTOR ]
formattingMultiplier: 0.25
wordValue: 0.1
symbols:
"\\b\\w+\\b": 0.1
permitGeneration:
githubComment:
post: true
Expand Down
15 changes: 8 additions & 7 deletions src/configuration/config-reader.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
import program from "../parser/command-line";
import { IncentivesConfiguration, incentivesConfigurationSchema, validateIncentivesConfiguration } from "./incentives";
import { Value } from "@sinclair/typebox/value";
import { merge } from "lodash";
import program from "../parser/command-line";
import { IncentivesConfiguration, incentivesConfigurationSchema, validateIncentivesConfiguration } from "./incentives";

let configuration: IncentivesConfiguration | null = null;

try {
const defaultConf = Value.Create(incentivesConfigurationSchema);
configuration = Value.Decode(incentivesConfigurationSchema, defaultConf);
configuration = Value.Default(incentivesConfigurationSchema, {}) as IncentivesConfiguration;
} catch (e) {
console.error(e);
}

if (program.settings) {
const settings = merge(configuration, JSON.parse(program.settings));
const settings = merge(
configuration,
Value.Default(incentivesConfigurationSchema, JSON.parse(program.settings)) as IncentivesConfiguration
);
if (validateIncentivesConfiguration.test(settings)) {
configuration = settings;
configuration = Value.Decode(incentivesConfigurationSchema, settings);
} else {
console.warn("Invalid incentives configuration detected, will revert to defaults.");
for (const error of validateIncentivesConfiguration.errors(settings)) {
console.warn(error);
}
}
}

export default configuration as IncentivesConfiguration;
23 changes: 13 additions & 10 deletions src/configuration/data-collection-config.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import { Static, Type } from "@sinclair/typebox";

export const dataCollectionConfigurationType = Type.Object({
/**
* The maximum amount of retries on failure.
*/
maxAttempts: Type.Number({ default: 10, minimum: 1 }),
/**
* The delay between each retry, in milliseconds.
*/
delayMs: Type.Number({ default: 10000, minimum: 100 }),
});
export const dataCollectionConfigurationType = Type.Object(
{
/**
* The maximum amount of retries on failure.
*/
maxAttempts: Type.Number({ default: 10, minimum: 1 }),
/**
* The delay between each retry, in milliseconds.
*/
delayMs: Type.Number({ default: 10000, minimum: 100 }),
},
{ default: {} }
);

export type DataCollectionConfiguration = Static<typeof dataCollectionConfigurationType>;
185 changes: 95 additions & 90 deletions src/configuration/formatting-evaluator-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,95 +7,100 @@ const type = Type.Union(
)
);

export const formattingEvaluatorConfigurationType = Type.Object({
/**
* Multipliers applied to different parts of the comment body content
*/
multipliers: Type.Array(
Type.Object({
select: Type.Array(type),
formattingMultiplier: Type.Number(),
wordValue: Type.Number(),
}),
{
default: [
{
select: ["ISSUE_SPECIFICATION"],
formattingMultiplier: 1,
wordValue: 0.1,
},
{
select: ["ISSUE_AUTHOR"],
formattingMultiplier: 1,
wordValue: 0.2,
},
{
select: ["ISSUE_ASSIGNEE"],
formattingMultiplier: 0,
wordValue: 0,
},
{
select: ["ISSUE_COLLABORATOR"],
formattingMultiplier: 1,
wordValue: 0.1,
},
{
select: ["ISSUE_CONTRIBUTOR"],
formattingMultiplier: 0.25,
wordValue: 0.1,
},
{
select: ["PULL_SPECIFICATION"],
formattingMultiplier: 0,
wordValue: 0,
},
{
select: ["PULL_AUTHOR"],
formattingMultiplier: 2,
wordValue: 0.2,
},
{
select: ["PULL_ASSIGNEE"],
formattingMultiplier: 1,
wordValue: 0.1,
},
{
select: ["PULL_COLLABORATOR"],
formattingMultiplier: 1,
wordValue: 0.1,
},
{
select: ["PULL_CONTRIBUTOR"],
formattingMultiplier: 0.25,
wordValue: 0.1,
},
],
}
),
/**
* Attributed score per HTML entity
*/
scores: Type.Record(Type.String(), Type.Number(), {
default: {
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,
},
}),
});
const symbolsType = Type.Record(Type.String(), Type.Number(), { minProperties: 1 });

export const formattingEvaluatorConfigurationType = Type.Object(
{
/**
* Multipliers applied to different parts of the comment body content
*/
multipliers: Type.Array(
Type.Object({
select: Type.Array(type),
formattingMultiplier: Type.Number(),
symbols: symbolsType,
/**
* Attributed score per HTML entity
*/
scores: Type.Record(Type.String(), Type.Number(), {
default: {
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,
},
}),
}),
{
default: [
{
select: ["ISSUE_SPECIFICATION"],
formattingMultiplier: 1,
symbols: { "\\b\\w+\\b": 0.1 },
},
{
select: ["ISSUE_AUTHOR"],
formattingMultiplier: 1,
symbols: { "\\b\\w+\\b": 0.2 },
},
{
select: ["ISSUE_ASSIGNEE"],
formattingMultiplier: 0,
symbols: { "\\b\\w+\\b": 0 },
},
{
select: ["ISSUE_COLLABORATOR"],
formattingMultiplier: 1,
symbols: { "\\b\\w+\\b": 0.1 },
},
{
select: ["ISSUE_CONTRIBUTOR"],
formattingMultiplier: 0.25,
symbols: { "\\b\\w+\\b": 0.1 },
},
{
select: ["PULL_SPECIFICATION"],
formattingMultiplier: 0,
symbols: { "\\b\\w+\\b": 0 },
},
{
select: ["PULL_AUTHOR"],
formattingMultiplier: 2,
symbols: { "\\b\\w+\\b": 0.2 },
},
{
select: ["PULL_ASSIGNEE"],
formattingMultiplier: 1,
symbols: { "\\b\\w+\\b": 0.1 },
},
{
select: ["PULL_COLLABORATOR"],
formattingMultiplier: 1,
symbols: { "\\b\\w+\\b": 0.1 },
},
{
select: ["PULL_CONTRIBUTOR"],
formattingMultiplier: 0.25,
symbols: { "\\b\\w+\\b": 0.1 },
},
],
}
),
},
{ default: {} }
);

export type FormattingEvaluatorConfiguration = Static<typeof formattingEvaluatorConfigurationType>;
23 changes: 13 additions & 10 deletions src/configuration/github-comment-config.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import { Static, Type } from "@sinclair/typebox";

export const githubCommentConfigurationType = Type.Object({
/**
* Enables posting to the related GitHub Issue
*/
post: Type.Boolean({ default: true }),
/**
* Enables debug by creating a local html file of the rendered comment
*/
debug: Type.Boolean({ default: false }),
});
export const githubCommentConfigurationType = Type.Object(
{
/**
* Enables posting to the related GitHub Issue
*/
post: Type.Boolean({ default: true }),
/**
* Enables debug by creating a local html file of the rendered comment
*/
debug: Type.Boolean({ default: false }),
},
{ default: {} }
);

export type GithubCommentConfiguration = Static<typeof githubCommentConfigurationType>;
Loading
Loading