diff --git a/.cspell.json b/.cspell.json index 16bcc5be..002b1049 100644 --- a/.cspell.json +++ b/.cspell.json @@ -4,7 +4,7 @@ "ignorePaths": ["**/*.json", "**/*.css", "node_modules", "**/*.log"], "useGitignore": true, "language": "en", - "words": ["dataurl", "devpool", "outdir", "servedir", "ubiquibot"], + "words": ["dataurl", "devpool", "outdir", "servedir", "ubiquibot", "tiktoken", "typebox"], "dictionaries": ["typescript", "node", "software-terms"], "import": ["@cspell/dict-typescript/cspell-ext.json", "@cspell/dict-node/cspell-ext.json", "@cspell/dict-software-terms"], "ignoreRegExpList": ["[0-9a-fA-F]{6}"] diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml deleted file mode 100644 index e8e48ab6..00000000 --- a/.github/workflows/build.yml +++ /dev/null @@ -1,41 +0,0 @@ -name: Build & Deploy - -on: - push: - pull_request: - workflow_dispatch: - -jobs: - build: - runs-on: ubuntu-22.04 - permissions: - contents: read - steps: - - name: Check out repository - uses: actions/checkout@v4 - with: - submodules: "recursive" # Ensures submodules are checked out - - - name: Set up Node.js - uses: actions/setup-node@v4 - with: - node-version: 20.10.0 - - - name: Build - run: | - yarn - yarn build - - - name: Deploy to Cloudflare - if: env.skip != 'true' - uses: ubiquity/cloudflare-deploy-action@main - with: - repository: ${{ github.repository }} - production_branch: ${{ github.event.repository.default_branch }} - output_directory: "static" - current_branch: ${{ github.ref_name }} - pull_request_number: ${{ github.event.pull_request.number }} - commit_sha: ${{ github.sha }} - # Add any environment variables you need to pass along here - # SUPABASE_URL: ${{ secrets.SUPABASE_URL }} - # SUPABASE_KEY: ${{ secrets.SUPABASE_KEY }} diff --git a/.github/workflows/jest-testing.yml b/.github/workflows/jest-testing.yml index be12bce0..7706a406 100644 --- a/.github/workflows/jest-testing.yml +++ b/.github/workflows/jest-testing.yml @@ -2,9 +2,8 @@ name: Run Jest Tests on: workflow_dispatch: - push: - branches: - - development + pull_request: + jobs: test: permissions: write-all diff --git a/action.yml b/action.yml index 818c06ca..41fd62d2 100644 --- a/action.yml +++ b/action.yml @@ -1,18 +1,23 @@ name: "Conversation Rewards" description: "Compute rewards for contributors' discussion on issues that are closed as complete." inputs: - authentication_token: - description: "The GitHub authentication token" + issue_url: + description: "The URL the the issue needing to be parsed" required: true outputs: - result: # id of output - description: "The result of a event handler" - value: ${{ steps.main.outputs.result}} + result: + description: "The result containing all the rewards of the users" + value: ${{ steps.main.outputs.result }} runs: using: "composite" steps: - run: | yarn --cwd ${{ github.action_path }} --production=true - yarn --cwd ${{ github.action_path }} start --auth ${{ inputs.authentication_token }} + yarn --cwd ${{ github.action_path }} start --issue "${{ inputs.issue_url }}" --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 shell: bash diff --git a/package.json b/package.json index 271d64ae..2a998c13 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ }, "scripts": { "test": "jest --setupFiles dotenv/config --coverage", - "start": "tsx src/start.ts", + "start": "tsx src/index.ts", "format": "run-s format:lint format:prettier format:cspell", "format:lint": "eslint --fix .", "format:prettier": "prettier --write .", @@ -36,6 +36,7 @@ "jsdom": "24.0.0", "markdown-it": "14.1.0", "openai": "4.29.1", + "tsx": "4.7.1", "yaml": "2.4.1" }, "devDependencies": { @@ -68,7 +69,6 @@ "npm-run-all": "4.1.5", "prettier": "3.2.5", "ts-node": "^10.9.2", - "tsx": "4.7.1", "typescript": "5.3.3" }, "lint-staged": { diff --git a/src/index.ts b/src/index.ts new file mode 100644 index 00000000..f3179820 --- /dev/null +++ b/src/index.ts @@ -0,0 +1,16 @@ +import { IssueActivity } from "./issue-activity"; +import program from "./parser/command-line"; +import { Processor } from "./parser/processor"; +import { parseGitHubUrl } from "./start"; + +async function main() { + const issueUrl = program.opts().issue; + const issue = parseGitHubUrl(issueUrl); + const activity = new IssueActivity(issue); + await activity.init(); + const processor = new Processor(); + await processor.run(activity); + processor.dump(); +} + +main().catch((e) => console.error("Failed to run comment evaluation:", e)); diff --git a/src/parser/command-line.ts b/src/parser/command-line.ts index 5ffc24de..29d25c13 100644 --- a/src/parser/command-line.ts +++ b/src/parser/command-line.ts @@ -4,7 +4,15 @@ import packageJson from "../../package.json"; config(); +// On test mode pass the env value directly to the CLI +if (process.env.NODE_ENV === "test") { + process.argv.splice(2); + process.argv.push("-i"); + process.argv.push(`${process.env.TEST_ISSUE_URL}`); +} + const program = new Command() + .requiredOption("-i, --issue ", "The url of the issue to parse") .option("-c, --config ", "The path to the desired configuration to use", "rewards-configuration.default.yml") .option("-f, --file ", "The target file to store the results in") .version(packageJson.version) diff --git a/src/parser/content-evaluator-module.ts b/src/parser/content-evaluator-module.ts index 725b8cd4..c46c5c63 100644 --- a/src/parser/content-evaluator-module.ts +++ b/src/parser/content-evaluator-module.ts @@ -125,7 +125,7 @@ export class ContentEvaluatorModule implements Module { for (let j = 0; j < results[0].length; j++) { let sum = new Decimal(0); for (let i = 0; i < results.length; i++) { - sum = sum.plus(results[i][j]); + sum = sum.plus(results[i][j] || 0); } columnSums.push(sum); }