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

feat: waiting message is displayed at the beginning of the run #52

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
0533eba
feat: added ubiquibot logger
gentlementlegen Jul 9, 2024
a5f5a1d
Merge branch 'refs/heads/development' into meniole-main
gentlementlegen Jul 9, 2024
45b5abb
chore: test comment
gentlementlegen Jul 9, 2024
d43d96c
chore: test comment
gentlementlegen Jul 9, 2024
16c78e3
chore: test comment
gentlementlegen Jul 9, 2024
474c55e
chore: test comment
gentlementlegen Jul 9, 2024
d514d4a
chore: test comment
gentlementlegen Jul 9, 2024
32510dc
chore: test comment
gentlementlegen Jul 9, 2024
bb69c65
chore: test comment
gentlementlegen Jul 9, 2024
322b915
chore: test comment
gentlementlegen Jul 9, 2024
0993b96
chore: test comment
gentlementlegen Jul 9, 2024
e1437ae
chore: test comment
gentlementlegen Jul 9, 2024
d8e190c
chore: test comment
gentlementlegen Jul 9, 2024
0851f32
chore: test comment
gentlementlegen Jul 9, 2024
b92e254
chore: test comment
gentlementlegen Jul 9, 2024
8961e3d
chore: test comment
gentlementlegen Jul 9, 2024
995a4f5
chore: test comment
gentlementlegen Jul 9, 2024
1650647
chore: test comment
gentlementlegen Jul 9, 2024
44e98a0
chore: test comment
gentlementlegen Jul 9, 2024
352bd32
chore: test comment
gentlementlegen Jul 9, 2024
65519cb
chore: test comment
gentlementlegen Jul 9, 2024
9c89229
chore: test comment
gentlementlegen Jul 9, 2024
bd38e30
chore: test comment
gentlementlegen Jul 9, 2024
02ae80c
chore: test comment
gentlementlegen Jul 9, 2024
c47ba4d
chore: fixed CI
gentlementlegen Jul 9, 2024
8bb0dd6
chore: fixed CI
gentlementlegen Jul 9, 2024
c8bd3f3
chore: updated README.md to match the schema
gentlementlegen Jul 9, 2024
5800938
Merge branch 'ubiquibot:development' into development
gentlementlegen Jul 10, 2024
9318652
feat: added ubiquibot logger
gentlementlegen Jul 9, 2024
628db1c
chore: removed unused directive in tsconfig.json
gentlementlegen Jul 10, 2024
7a5ba72
chore: removed ts extensions on imports
gentlementlegen Jul 10, 2024
866f853
chore: added comment on COMMENT_ID
gentlementlegen Jul 11, 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
27 changes: 24 additions & 3 deletions .github/workflows/compute.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,30 @@ jobs:
NFT_CONTRACT_ADDRESS: ${{ secrets.NFT_CONTRACT_ADDRESS }}

steps:
- name: Post starting comment to issue
uses: actions/github-script@v7
id: post-comment
with:
github-token: ${{ inputs.authToken }}
script: |
const comment_body = '\`\`\`diff\n+ Evaluating results. Please wait...';
const obj = ${{ inputs.eventPayload }}
if (obj.issue && "${{ inputs.eventName }}" === "issues.closed") {
0x4007 marked this conversation as resolved.
Show resolved Hide resolved
const response = await github.rest.issues.createComment({
owner: obj.repository.owner.login,
repo: obj.repository.name,
issue_number: obj.issue.number,
body: comment_body,
});
core.setOutput('comment_id', response.data.id);
}

- name: Set environment variable
run: echo "COMMENT_ID=${{ steps.post-comment.outputs.comment_id }}" >> $GITHUB_ENV

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

- name: Checkout code
uses: actions/checkout@v4

Expand All @@ -38,8 +62,5 @@ jobs:
with:
node-version: "20.10.0"

- run: ${{ toJSON(inputs) }}
shell: cat {0}
gentlementlegen marked this conversation as resolved.
Show resolved Hide resolved

- name: Generate Rewards
uses: ./
1 change: 1 addition & 0 deletions .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ jobs:
- uses: googleapis/release-please-action@v4
with:
release-type: simple
target-branch: main
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"@supabase/supabase-js": "2.42.0",
"@ubiquibot/permit-generation": "1.3.1",
"@ubiquity-dao/rpc-handler": "1.1.0",
"@ubiquity-dao/ubiquibot-logger": "1.2.0",
"decimal.js": "10.4.3",
"dotenv": "16.4.5",
"ethers": "^6.13.0",
Expand Down
5 changes: 5 additions & 0 deletions src/helpers/github-comment-module-instance.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { GithubCommentModule } from "../parser/github-comment-module";

const githubCommentModule = new GithubCommentModule();

export default githubCommentModule;
2 changes: 1 addition & 1 deletion src/helpers/label-price-extractor.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { GitHubIssue } from "../github-types.ts";
import { GitHubIssue } from "../github-types";

export function getSortedPrices(labels: GitHubIssue["labels"] | undefined) {
if (!labels) return [];
Expand Down
5 changes: 5 additions & 0 deletions src/helpers/logger.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Logs } from "@ubiquity-dao/ubiquibot-logger";
rndquu marked this conversation as resolved.
Show resolved Hide resolved

const logger = new Logs("debug");

export default logger;
44 changes: 31 additions & 13 deletions src/parser/github-comment-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import { CommentType } from "../configuration/comment-types";
import configuration from "../configuration/config-reader";
import { GithubCommentConfiguration, githubCommentConfigurationType } from "../configuration/github-comment-config";
import { getOctokitInstance } from "../get-authentication-token";
import logger from "../helpers/logger";
import { getERC20TokenSymbol } from "../helpers/web3";
import { IssueActivity } from "../issue-activity";
import { parseGitHubUrl } from "../start";
import program from "./command-line";
import { GithubCommentScore, Module, Result } from "./processor";
import { getERC20TokenSymbol } from "../helpers/web3";

interface SortedTasks {
issues: { specification: GithubCommentScore | null; comments: GithubCommentScore[] };
Expand All @@ -23,6 +23,11 @@ interface SortedTasks {
export class GithubCommentModule implements Module {
private readonly _configuration: GithubCommentConfiguration = configuration.incentives.githubComment;
private readonly _debugFilePath = "./output.html";
/**
* COMMENT_ID can be set in the environment to reference the id of the last comment created during this workflow.
* See also compute.yml to understand how it is set.
*/
private _lastCommentId: number | null = process.env.COMMENT_ID ? Number(process.env.COMMENT_ID) : null;
rndquu marked this conversation as resolved.
Show resolved Hide resolved

async transform(data: Readonly<IssueActivity>, result: Result): Promise<Result> {
const bodyArray: (string | undefined)[] = [];
Expand All @@ -37,30 +42,43 @@ export class GithubCommentModule implements Module {
}
if (this._configuration.post) {
try {
const octokit = getOctokitInstance();
const { owner, repo, issue_number } = parseGitHubUrl(program.eventPayload.issue.html_url);

await octokit.issues.createComment({
body,
repo,
owner,
issue_number,
});
await this.postComment(body);
} catch (e) {
console.error(`Could not post GitHub comment: ${e}`);
logger.error(`Could not post GitHub comment: ${e}`);
}
}
return result;
}

get enabled(): boolean {
if (!Value.Check(githubCommentConfigurationType, this._configuration)) {
console.warn("Invalid configuration detected for GithubContentModule, disabling.");
logger.error("Invalid configuration detected for GithubContentModule, disabling.");
return false;
}
return true;
}

async postComment(body: string, updateLastComment = true) {
const { eventPayload } = program;
if (updateLastComment && this._lastCommentId !== null) {
await getOctokitInstance().issues.updateComment({
body,
repo: eventPayload.repository.name,
owner: eventPayload.repository.owner.login,
issue_number: eventPayload.issue.number,
comment_id: this._lastCommentId,
});
} else {
const comment = await getOctokitInstance().issues.createComment({
body,
repo: eventPayload.repository.name,
owner: eventPayload.repository.owner.login,
issue_number: eventPayload.issue.number,
});
this._lastCommentId = comment.data.id;
}
}

_createContributionRows(result: Result[0], sortedTasks: SortedTasks | undefined) {
const content: string[] = [];

Expand Down
9 changes: 5 additions & 4 deletions src/parser/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ import Decimal from "decimal.js";
import * as fs from "fs";
import { CommentType } from "../configuration/comment-types";
import configuration from "../configuration/config-reader";
import githubCommentModuleInstance from "../helpers/github-comment-module-instance";
import logger from "../helpers/logger";
import { IssueActivity } from "../issue-activity";
import { ContentEvaluatorModule } from "./content-evaluator-module";
import { DataPurgeModule } from "./data-purge-module";
import { FormattingEvaluatorModule } from "./formatting-evaluator-module";
import { GithubCommentModule } from "./github-comment-module";
import { PermitGenerationModule } from "./permit-generation-module";
import { UserExtractorModule } from "./user-extractor-module";

Expand All @@ -21,7 +22,7 @@ export class Processor {
.add(new FormattingEvaluatorModule())
.add(new ContentEvaluatorModule())
.add(new PermitGenerationModule())
.add(new GithubCommentModule());
.add(githubCommentModuleInstance);
}

add(transformer: Module) {
Expand All @@ -31,7 +32,7 @@ export class Processor {

async run(data: Readonly<IssueActivity>) {
if (!this._configuration.enabled) {
console.log("Module is disabled. Skipping...");
logger.debug("Module is disabled. Skipping...");
return;
}
for (const transformer of this._transformers) {
Expand Down Expand Up @@ -67,7 +68,7 @@ export class Processor {
2
);
if (!file) {
console.log(result);
logger.debug(result);
} else {
fs.writeFileSync(file, result);
}
Expand Down
2 changes: 1 addition & 1 deletion src/parser/user-extractor-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Decimal from "decimal.js";
import configuration from "../configuration/config-reader";
import { UserExtractorConfiguration, userExtractorConfigurationType } from "../configuration/user-extractor-config";
import { GitHubIssue } from "../github-types";
import { getSortedPrices } from "../helpers/label-price-extractor.ts";
import { getSortedPrices } from "../helpers/label-price-extractor";
import { IssueActivity } from "../issue-activity";
import { Module, Result } from "./processor";

Expand Down
33 changes: 11 additions & 22 deletions src/run.ts
Original file line number Diff line number Diff line change
@@ -1,43 +1,32 @@
import { getSortedPrices } from "./helpers/label-price-extractor.ts";
import configuration from "./configuration/config-reader";
import githubCommentModuleInstance from "./helpers/github-comment-module-instance";
import { getSortedPrices } from "./helpers/label-price-extractor";
import logger from "./helpers/logger";
import { IssueActivity } from "./issue-activity";
import program from "./parser/command-line";
import { Processor } from "./parser/processor";
import { parseGitHubUrl } from "./start";
import { getOctokitInstance } from "./get-authentication-token.ts";
import configuration from "./configuration/config-reader.ts";

export async function run() {
const { eventPayload, eventName } = program;
if (eventName === "issues.closed") {
if (eventPayload.issue.state_reason !== "completed") {
const result = "# Issue was not closed as completed. Skipping.";
await getOctokitInstance().issues.createComment({
body: `\`\`\`text\n${result}\n\`\`\``,
repo: eventPayload.repository.name,
owner: eventPayload.repository.owner.login,
issue_number: eventPayload.issue.number,
});
return result;
const result = logger.info("Issue was not closed as completed. Skipping.");
await githubCommentModuleInstance.postComment(result?.logMessage.diff || "");
return result?.logMessage.raw;
}
const issue = parseGitHubUrl(eventPayload.issue.html_url);
const activity = new IssueActivity(issue);
await activity.init();
if (configuration.incentives.requirePriceLabel && !getSortedPrices(activity.self?.labels).length) {
const result = "! No price label has been set. Skipping permit generation.";
await getOctokitInstance().issues.createComment({
body: `\`\`\`text\n${result}\n\`\`\``,
repo: eventPayload.repository.name,
owner: eventPayload.repository.owner.login,
issue_number: eventPayload.issue.number,
});
return result;
const result = logger.error("No price label has been set. Skipping permit generation.");
await githubCommentModuleInstance.postComment(result?.logMessage.diff || "");
return result?.logMessage.raw;
}
const processor = new Processor();
await processor.run(activity);
return processor.dump();
} else {
const result = `${eventName} is not supported, skipping.`;
console.warn(result);
return result;
return logger.error(`${eventName} is not supported, skipping.`)?.logMessage.raw;
}
}
1 change: 1 addition & 0 deletions src/types/env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ declare global {
SUPABASE_URL: string;
NFT_CONTRACT_ADDRESS: string;
NFT_MINTER_PRIVATE_KEY: string;
COMMENT_ID: string | undefined;
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/action.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint @typescript-eslint/no-var-requires: 0 */
import "../src/parser/command-line";
import { run } from "../src/run";
import { server } from "./__mocks__/node.ts";
import { server } from "./__mocks__/node";

beforeAll(() => server.listen());
afterEach(() => server.resetHandlers());
Expand Down Expand Up @@ -36,6 +36,6 @@ jest.mock("../src/parser/command-line", () => {
describe("Action tests", () => {
it("Should skip when the issue is closed without the completed status", async () => {
const result = await run();
expect(result).toEqual("# Issue was not closed as completed. Skipping.");
expect(result).toEqual("Issue was not closed as completed. Skipping.");
});
});
4 changes: 2 additions & 2 deletions tests/price-label.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint @typescript-eslint/no-var-requires: 0 */
import "../src/parser/command-line";
import { run } from "../src/run";
import { server } from "./__mocks__/node.ts";
import { server } from "./__mocks__/node";

beforeAll(() => server.listen());
afterEach(() => server.resetHandlers());
Expand Down Expand Up @@ -42,6 +42,6 @@ jest.mock("../src/parser/command-line", () => {
describe("Price tests", () => {
it("Should skip when no price label is set", async () => {
const result = await run();
expect(result).toEqual("! No price label has been set. Skipping permit generation.");
expect(result).toEqual("No price label has been set. Skipping permit generation.");
});
});
2 changes: 1 addition & 1 deletion tests/process.issue.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ describe("Modules tests", () => {
});

it("Should do a full run", async () => {
const module = (await import("../src/index.ts")) as unknown as { default: Promise<string> };
const module = (await import("../src/index")) as unknown as { default: Promise<string> };
const result = await module.default;
expect(result).toBeTruthy();
});
Expand Down
22 changes: 11 additions & 11 deletions tests/rewards.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ import { drop } from "@mswjs/data";
import Decimal from "decimal.js";
import fs from "fs";
import { http, HttpResponse } from "msw";
import { IssueActivity } from "../src/issue-activity.ts";
import { ContentEvaluatorModule } from "../src/parser/content-evaluator-module.ts";
import { DataPurgeModule } from "../src/parser/data-purge-module.ts";
import { FormattingEvaluatorModule } from "../src/parser/formatting-evaluator-module.ts";
import { GithubCommentModule } from "../src/parser/github-comment-module.ts";
import { PermitGenerationModule } from "../src/parser/permit-generation-module.ts";
import { Processor } from "../src/parser/processor.ts";
import { UserExtractorModule } from "../src/parser/user-extractor-module.ts";
import { parseGitHubUrl } from "../src/start.ts";
import { IssueActivity } from "../src/issue-activity";
import { ContentEvaluatorModule } from "../src/parser/content-evaluator-module";
import { DataPurgeModule } from "../src/parser/data-purge-module";
import { FormattingEvaluatorModule } from "../src/parser/formatting-evaluator-module";
import { GithubCommentModule } from "../src/parser/github-comment-module";
import { PermitGenerationModule } from "../src/parser/permit-generation-module";
import { Processor } from "../src/parser/processor";
import { UserExtractorModule } from "../src/parser/user-extractor-module";
import { parseGitHubUrl } from "../src/start";
import "../src/parser/command-line";
import { db, db as mockDb } from "./__mocks__/db.ts";
import { db, db as mockDb } from "./__mocks__/db";
import dbSeed from "./__mocks__/db-seed.json";
import { server } from "./__mocks__/node.ts";
import { server } from "./__mocks__/node";
import rewardSplitResult from "./__mocks__/results/reward-split.json";

const issueUrl = "https://github.com/ubiquity/work.ubq.fi/issues/69";
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
// "types": [], /* Specify type package names to be included without being referenced in a source file. */
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
// "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
"allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */
// "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */
// "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */
// "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */
// "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */
Expand Down
Loading