Skip to content

Commit

Permalink
Merge pull request #15 from gentlementlegen/feat/configuration
Browse files Browse the repository at this point in the history
feat: configuration is now fetched from Ubiquibot package
  • Loading branch information
gentlementlegen authored May 15, 2024
2 parents a43b17d + 41938f6 commit ecd6281
Show file tree
Hide file tree
Showing 38 changed files with 570 additions and 295 deletions.
10 changes: 3 additions & 7 deletions .github/workflows/compute.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ jobs:
SUPABASE_KEY: ${{ secrets.SUPABASE_KEY }}
NFT_MINTER_PRIVATE_KEY: ${{ secrets.NFT_MINTER_PRIVATE_KEY }}
NFT_CONTRACT_ADDRESS: ${{ secrets.NFT_CONTRACT_ADDRESS }}
EVM_PRIVATE_ENCRYPTED: ${{ secrets.EVM_PRIVATE_ENCRYPTED }}
APP_ID: ${{ secrets.APP_ID }}
UBIQUIBOT_APP_PRIVATE_KEY: ${{ secrets.UBIQUIBOT_APP_PRIVATE_KEY }}

steps:
- name: Checkout code
Expand All @@ -41,9 +38,8 @@ jobs:
with:
node-version: "20.10.0"

- run: ${{ toJSON(inputs) }}
shell: cat {0}

- name: Generate Rewards
uses: ./
with:
issueUrl: "${{ fromJSON(inputs.eventPayload).issue.html_url }}"
evmPrivateEncrypted: "${{ secrets.EVM_PRIVATE_ENCRYPTED }}"
evmNetworkId: "${{ fromJSON(inputs.settings).evmNetworkId }}"
3 changes: 3 additions & 0 deletions .github/workflows/jest-testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ name: Run Jest Tests
on:
workflow_dispatch:
pull_request:
push:
branches:
- development

jobs:
test:
Expand Down
33 changes: 0 additions & 33 deletions .github/workflows/main.yml

This file was deleted.

21 changes: 4 additions & 17 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
name: "Conversation Rewards"
description: "Compute rewards for contributors' discussion on issues that are closed as complete."
inputs:
issueUrl:
description: "The URL the the issue needing to be parsed"
required: true
evmNetworkId:
description: "The EVM network ID to use"
required: true
evmPrivateEncrypted:
description: "The encrypted EVM private key"
required: true
outputs:
result:
description: "The result containing all the rewards of the users"
Expand All @@ -19,11 +9,8 @@ runs:
steps:
- run: |
yarn --cwd ${{ github.action_path }} --production=true
yarn --cwd ${{ github.action_path }} start --issue "${{ inputs.issueUrl }}" --file "${{ github.action_path }}/results.json"
output=$(cat ${{ github.action_path }}/results.json | tr -s ' ' | tr -d '\n')
echo "Output of calculations:"
echo "$output"
echo "Pushing results to REWARDS output"
echo "REWARDS=$output" >> $GITHUB_OUTPUT
id: main
id: install
shell: bash
- run: yarn --cwd ${{ github.action_path }} start
shell: bash
id: main
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,22 @@
"open-source"
],
"dependencies": {
"@actions/core": "1.10.1",
"@actions/github": "6.0.0",
"@commander-js/extra-typings": "12.0.1",
"@octokit/rest": "20.1.0",
"@sinclair/typebox": "0.32.20",
"@octokit/webhooks": "13.2.7",
"@sinclair/typebox": "0.32.23",
"@supabase/supabase-js": "2.42.0",
"@ubiquibot/permit-generation": "1.2.2",
"commander": "12.0.0",
"decimal.js": "10.4.3",
"dotenv": "16.4.5",
"js-tiktoken": "1.0.10",
"jsdom": "24.0.0",
"lodash": "4.17.21",
"markdown-it": "14.1.0",
"openai": "4.29.1",
"tsx": "4.7.1",
"typebox-validators": "0.3.5",
"yaml": "2.4.1"
},
"devDependencies": {
Expand Down
65 changes: 0 additions & 65 deletions rewards-configuration.default.yml

This file was deleted.

38 changes: 38 additions & 0 deletions src/configuration/comment-types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
export enum CommentType {
/**
* Review related item
*/
REVIEW = 0b1,
/**
* Issue related item
*/
ISSUE = 0b10,
/**
* User assigned to the {@link CommentType.ISSUE} or {@link CommentType.REVIEW}
*/
ASSIGNEE = 0b100,
/**
* The author of the {@link CommentType.ISSUE} or {@link CommentType.REVIEW}
*/
ISSUER = 0b1000,
/**
* A user that is part of the organization or owner of the repo
*/
COLLABORATOR = 0b10000,
/**
* A user that is NOT part of the organization nor owner of the repo
*/
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
*/
SPECIFICATION = 0b100000000,
}
9 changes: 0 additions & 9 deletions src/configuration/common-config-type.ts

This file was deleted.

29 changes: 24 additions & 5 deletions src/configuration/config-reader.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,27 @@
import * as fs from "fs";
import YAML from "yaml";
import program from "../parser/command-line";
import { IncentivesConfiguration, incentivesConfigurationSchema, validateIncentivesConfiguration } from "./incentives";
import { Value } from "@sinclair/typebox/value";
import { merge } from "lodash";

const file = fs.readFileSync(program.opts().config, "utf8");
const configuration = YAML.parse(file);
let configuration: IncentivesConfiguration | null = null;

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

if (program.settings) {
const settings = merge(configuration, JSON.parse(program.settings));
if (validateIncentivesConfiguration.test(settings)) {
configuration = 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;
1 change: 0 additions & 1 deletion src/configuration/constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { config } from "dotenv";

config();
export const GITHUB_TOKEN = process.env.GITHUB_TOKEN;
export const OPENAI_API_KEY = process.env.OPENAI_API_KEY;
9 changes: 5 additions & 4 deletions src/configuration/content-evaluator-config.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { Static, Type } from "@sinclair/typebox";

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

export type ContentEvaluatorConfiguration = Static<typeof contentEvaluatorConfigurationType>;

export default contentEvaluatorConfigurationType;
10 changes: 10 additions & 0 deletions src/configuration/data-purge-config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Type, Static } from "@sinclair/typebox";

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

export type DataPurgeConfiguration = Static<typeof dataPurgeConfigurationType>;
Loading

1 comment on commit ecd6281

@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: 79%
79.3% (341/430) 67.85% (133/196) 81.52% (75/92)

JUnit

Tests Skipped Failures Errors Time
22 0 💤 0 ❌ 0 🔥 9.928s ⏱️
Coverage Report (79%)
File% Stmts% Branch% Funcs% LinesUncovered Line #s
All files79.367.8581.5279.56 
src77.7778.5775.8680 
   get-authentication-token.ts100100100100 
   github-types.ts100100100100 
   index.ts41.665033.3341.6612–16, 22–26
   issue-activity.ts96.0781.811009646–47
   start.ts58.065061.5364.2894–112, 124
src/configuration83.335010082.6 
   comment-types.ts0000 
   config-reader.ts66.665010066.6612, 20–22
   constants.ts100100100100 
   content-evaluator-config.ts100100100100 
   data-purge-config.ts100100100100 
   formatting-evaluator-config.ts100100100100 
   github-comment-config.ts100100100100 
   incentives.ts100100100100 
   permit-generation-configuration.ts100100100100 
   user-extractor-config.ts100100100100 
src/data-collection83.3365.3810082.85 
   collect-linked-pulls.ts83.3365.3810082.8510, 19, 60–64
src/parser78.8666.9181.4878.59 
   content-evaluator-module.ts62.6845.4558.336023–24, 56–57, 75–112, 141–145
   data-purge-module.ts81.8190.910081.8115–16
   formatting-evaluator-module.ts92.56010092.374–75, 87
   github-comment-module.ts84.746510084.7439–50, 58–59, 68, 119
   permit-generation-module.ts70.375042.8570.3748–49, 56–63, 104, 112–113
   processor.ts91.6683.3310091.6634–35, 72
   user-extractor-module.ts7676.1983.337616–17, 34, 47, 49–50
src/types83.335010083.33 
   env-type.ts100100100100 
   payout.ts80501008018

Please sign in to comment.