Skip to content

Commit

Permalink
Merge pull request #16 from gentlementlegen/feat/configuration
Browse files Browse the repository at this point in the history
chore: testing v2
  • Loading branch information
gentlementlegen authored Apr 26, 2024
2 parents a466667 + ff8f263 commit be846d5
Show file tree
Hide file tree
Showing 45 changed files with 2,907 additions and 298 deletions.
4 changes: 2 additions & 2 deletions .cspell.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"$schema": "https://raw.githubusercontent.com/streetsidesoftware/cspell/main/cspell.schema.json",
"version": "0.2",
"ignorePaths": ["**/*.json", "**/*.css", "node_modules", "**/*.log"],
"ignorePaths": ["**/*.json", "**/*.css", "node_modules", "**/*.log", "**/tests/__mocks__"],
"useGitignore": true,
"language": "en",
"words": ["dataurl", "devpool", "outdir", "servedir", "ubiquibot", "tiktoken", "typebox", "supabase", "wxdai", "noopener"],
"words": ["dataurl", "devpool", "outdir", "servedir", "ubiquibot", "tiktoken", "typebox", "supabase", "wxdai", "noopener", "knip", "hellip"],
"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}"]
Expand Down
49 changes: 49 additions & 0 deletions .github/workflows/compute.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Compute Rewards

on:
workflow_dispatch:
inputs:
stateId:
description: "State Id"
eventName:
description: "Event Name"
eventPayload:
description: "Event Payload"
settings:
description: "Settings"
authToken:
description: "Auth Token"
ref:
description: "Ref"

jobs:
compute:
name: Rewards
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
X25519_PRIVATE_KEY: ${{ secrets.X25519_PRIVATE_KEY }}
SUPABASE_URL: ${{ secrets.SUPABASE_URL }}
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
uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: "20.10.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 @@ -15,6 +15,9 @@ jobs:
SUPABASE_URL: ${{ secrets.SUPABASE_URL }}
SUPABASE_KEY: ${{ secrets.SUPABASE_KEY }}
X25519_PRIVATE_KEY: ${{ secrets.X25519_PRIVATE_KEY }}
NFT_MINTER_PRIVATE_KEY: ${{ secrets.NFT_MINTER_PRIVATE_KEY }}
NFT_CONTRACT_ADDRESS: ${{ secrets.NFT_CONTRACT_ADDRESS }}
EVM_PRIVATE_ENCRYPTED: ${{ secrets.EVM_PRIVATE_ENCRYPTED }}

steps:
- name: Checkout code
Expand Down
33 changes: 0 additions & 33 deletions .github/workflows/main.yml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -27,39 +27,39 @@ formattingEvaluator:
td: 1
hr: 0
multipliers:
- type: [ISSUE, ISSUER, TASK]:
- type: [ISSUE, ISSUER, SPECIFICATION]
formattingMultiplier: 1
wordValue: 0.1
- type: [ISSUE, ISSUER, COMMENTED]:
- type: [ISSUE, ISSUER, COMMENTED]
formattingMultiplier: 1
wordValue: 0.2
- type: [ISSUE, ASSIGNEE, COMMENTED]:
- type: [ISSUE, ASSIGNEE, COMMENTED]
formattingMultiplier: 0
wordValue: 0
- type: [ISSUE, COLLABORATOR, COMMENTED]:
- type: [ISSUE, COLLABORATOR, COMMENTED]
formattingMultiplier: 1
wordValue: 0.1
- type: [ISSUE, CONTRIBUTOR, COMMENTED]:
- type: [ISSUE, CONTRIBUTOR, COMMENTED]
formattingMultiplier: 0.25
wordValue: 0.1
- type: [REVIEW, ISSUER, SPECIFICATION]:
- type: [REVIEW, ISSUER, TASK]
formattingMultiplier: 0
wordValue: 0
- type: [REVIEW, ISSUER, COMMENTED]:
- type: [REVIEW, ISSUER, COMMENTED]
formattingMultiplier: 2
wordValue: 0.2
- type: [REVIEW, ASSIGNEE, COMMENTED]:
- type: [REVIEW, ASSIGNEE, COMMENTED]
formattingMultiplier: 1
wordValue: 0.1
- type: [REVIEW, COLLABORATOR, COMMENTED]:
- type: [REVIEW, COLLABORATOR, COMMENTED]
formattingMultiplier: 1
wordValue: 0.1
- type: [REVIEW, CONTRIBUTOR, COMMENTED]:
- type: [REVIEW, CONTRIBUTOR, COMMENTED]
formattingMultiplier: 0.25
wordValue: 0.1
permitGeneration:
enabled: true
githubComment:
enabled: true
post: false
post: true
debug: true
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ 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"
yarn --cwd ${{ github.action_path }} start --issue "${{ inputs.issueUrl }}" --file "${{ github.action_path }}/results.json" --evmNetworkId "${{ inputs.evmNetworkId }}" --evmPrivateEncrypted "${{ inputs.evmPrivateEncrypted }}"
output=$(cat ${{ github.action_path }}/results.json | tr -s ' ' | tr -d '\n')
echo "Output of calculations:"
echo "$output"
Expand Down
2 changes: 1 addition & 1 deletion knip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const config: KnipConfig = {
project: ["src/**/*.ts"],
ignore: ["src/data-collection/examples/*.ts", "src/configuration/common-config-type.ts"],
ignoreExportsUsedInFile: true,
ignoreDependencies: ["ts-node", "msw"],
ignoreDependencies: ["ts-node", "msw", "@mswjs/data"],
jest: {
config: ["jest.config.ts"],
entry: ["src/**/*.test.ts"],
Expand Down
11 changes: 9 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,22 @@
"dependencies": {
"@actions/github": "6.0.0",
"@commander-js/extra-typings": "12.0.1",
"@octokit/auth-app": "6.1.1",
"@octokit/rest": "20.1.0",
"@sinclair/typebox": "0.32.20",
"@sinclair/typebox": "0.32.23",
"@supabase/supabase-js": "2.42.0",
"@ubiquibot/permit-generation": "1.2.1",
"@ubiquibot/configuration": "2.0.3",
"@ubiquibot/permit-generation": "1.2.2",
"ajv": "8.12.0",
"ajv-formats": "3.0.1",
"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",
"ms": "2.1.3",
"openai": "4.29.1",
"tsx": "4.7.1",
"yaml": "2.4.1"
Expand All @@ -50,6 +56,7 @@
"@cspell/dict-node": "4.0.3",
"@cspell/dict-software-terms": "3.3.18",
"@cspell/dict-typescript": "3.1.2",
"@mswjs/data": "0.16.1",
"@types/jest": "29.5.12",
"@types/jsdom": "21.1.6",
"@types/markdown-it": "13.0.7",
Expand Down
9 changes: 0 additions & 9 deletions src/configuration/common-config-type.ts

This file was deleted.

22 changes: 20 additions & 2 deletions src/configuration/config-reader.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,26 @@
import { Value } from "@sinclair/typebox/value";
import { baseIncentiveConfiguration, BotConfig, generateConfiguration } from "@ubiquibot/configuration";
import * as fs from "fs";
import YAML from "yaml";
import program from "../parser/command-line";

const file = fs.readFileSync(program.opts().config, "utf8");
const configuration = YAML.parse(file);
let configuration: BotConfig;
let incentivesConfiguration: BotConfig["incentives"] | null = null;
try {
const file = fs.readFileSync(program.opts().config, "utf8");
incentivesConfiguration = YAML.parse(file);
} catch (e) {
console.error(e);
}

// Get the default configuration
configuration = generateConfiguration();

if (!Value.Check(baseIncentiveConfiguration, incentivesConfiguration)) {
console.warn("Invalid bot configuration detected, will use defaults.");
} else {
// Merge the default with our own
configuration = generateConfiguration({ ...configuration, incentives: incentivesConfiguration });
}

export default configuration;
4 changes: 3 additions & 1 deletion src/configuration/constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { config } from "dotenv";

config();
export const GITHUB_TOKEN = process.env.GITHUB_TOKEN;
export const OPENAI_API_KEY = process.env.OPENAI_API_KEY;
export const APP_ID = process.env.APP_ID;
export const UBIQUIBOT_APP_PRIVATE_KEY = process.env.UBIQUIBOT_APP_PRIVATE_KEY;
export const INSTALLATION_ID = process.env.INSTALLATION_ID;
9 changes: 0 additions & 9 deletions src/configuration/content-evaluator-config.ts

This file was deleted.

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

This file was deleted.

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

This file was deleted.

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

This file was deleted.

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

This file was deleted.

24 changes: 22 additions & 2 deletions src/data-collection/collect-linked-pulls.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,30 @@
import { GitHubLinkEvent, isGitHubLinkEvent } from "../github-types";
import { IssueParams, getAllTimelineEvents } from "../start";
import { IssueParams, getAllTimelineEvents, parseGitHubUrl } from "../start";

export async function collectLinkedMergedPulls(issue: IssueParams) {
// normally we should only use this one to calculate incentives, because this specifies that the pull requests are merged (accepted)
// and that are also related to the current issue, no just mentioned by
const onlyPullRequests = await collectLinkedPulls(issue);
return onlyPullRequests.filter((event) => isGitHubLinkEvent(event) && event.source.issue.pull_request?.merged_at);
return onlyPullRequests.filter((event) => {
if (!event.source.issue.body) {
return false;
}
const linkedPrUrl = /Resolves[\s:]*(https:\/\/\S+|#\d+)/gim.exec(event.source.issue.body)?.[1];
if (!linkedPrUrl) {
return false;
}
let isClosingPr: boolean;
if (linkedPrUrl[0] === "#") {
isClosingPr = Number(linkedPrUrl.slice(1)) === issue.issue_number;
} else {
const linkedRepo = parseGitHubUrl(linkedPrUrl);
isClosingPr =
linkedRepo.issue_number === issue.issue_number &&
linkedRepo.repo === issue.repo &&
linkedRepo.owner === issue.owner;
}
return isGitHubLinkEvent(event) && event.source.issue.pull_request?.merged_at && isClosingPr;
});
}
export async function collectLinkedPulls(issue: IssueParams) {
// this one was created to help with tests, but probably should not be used in the main code
Expand Down
30 changes: 22 additions & 8 deletions src/get-authentication-token.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,33 @@
import * as github from "@actions/github";
import { createAppAuth } from "@octokit/auth-app";
import { Octokit } from "@octokit/rest";
import { GITHUB_TOKEN } from "./configuration/constants";
import { APP_ID, INSTALLATION_ID, UBIQUIBOT_APP_PRIVATE_KEY } from "./configuration/constants";

let octokitInstance: Octokit | null = null;

function getAuthenticationToken(): string {
const auth = GITHUB_TOKEN;
if (!auth) {
throw new Error("No authentication token provided");
async function getAuthenticationToken() {
const appId = APP_ID;
const privateKey = UBIQUIBOT_APP_PRIVATE_KEY;
// Defaults to the ENV value in case we are not in a GitHub Action context
const inputs = {
installationId: INSTALLATION_ID,
};

if (github.context.payload.inputs) {
const eventPayload = JSON.parse(github.context.payload.inputs.eventPayload);
if (eventPayload?.installation) {
inputs.installationId = eventPayload.installation.id;
}
}
return auth;

const auth = createAppAuth({ appId, privateKey, installationId: inputs.installationId });
const authInstance = await auth({ type: "installation" });
return authInstance.token;
}

function getOctokitInstance(): Octokit {
async function getOctokitInstance(): Promise<Octokit> {
if (!octokitInstance) {
const auth = getAuthenticationToken();
const auth = await getAuthenticationToken();
octokitInstance = new Octokit({ auth });
}
return octokitInstance;
Expand Down
Loading

0 comments on commit be846d5

Please sign in to comment.