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: close only assignee PR #10

Merged
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
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
17 changes: 16 additions & 1 deletion .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,22 @@
"ignorePaths": ["**/*.json", "**/*.css", "node_modules", "**/*.log", "./src/adapters/supabase/**/**.ts"],
"useGitignore": true,
"language": "en",
"words": ["dataurl", "devpool", "outdir", "servedir", "Supabase", "supabase", "SUPABASE", "typebox", "ubiquibot", "signoff", "sonarjs", "mswjs"],
"words": [
"knip",
"mischeck",
"dataurl",
"devpool",
"outdir",
"servedir",
"Supabase",
"supabase",
"SUPABASE",
"typebox",
"ubiquibot",
"signoff",
"sonarjs",
"mswjs"
],
"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
59 changes: 0 additions & 59 deletions .eslintrc.js

This file was deleted.

4 changes: 2 additions & 2 deletions .github/knip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import type { KnipConfig } from "knip";
const config: KnipConfig = {
entry: ["build/index.ts"],
project: ["src/**/*.ts"],
ignore: ["src/types/config.ts", "**/__mocks__/**", "**/__fixtures__/**", "src/worker.ts", "src/types/plugin-input.ts", "src/main.ts", "src/plugin.ts"],
ignore: ["src/types/config.ts", "**/__mocks__/**", "**/__fixtures__/**", "src/worker.ts"],
ignoreExportsUsedInFile: true,
// eslint can also be safely ignored as per the docs: https://knip.dev/guides/handling-issues#eslint--jest
ignoreDependencies: ["eslint-config-prettier", "eslint-plugin-prettier", "@types/jest", "@actions/core", "@actions/github"],
ignoreDependencies: ["eslint-config-prettier", "eslint-plugin-prettier", "@types/jest"],
eslint: true,
};

Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ coverage
junit.xml
cypress/screenshots
script.ts
.wrangler
.wrangler
test-dashboard.md
126 changes: 126 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
// @ts-check
0x4007 marked this conversation as resolved.
Show resolved Hide resolved
import tsEslint from "typescript-eslint";
import eslint from "@eslint/js";
import sonarjs from "eslint-plugin-sonarjs";
import checkFile from "eslint-plugin-check-file";

export default tsEslint.config({
plugins: {
"@typescript-eslint": tsEslint.plugin,
"check-file": checkFile,
},
ignores: [".github/knip.ts", ".github/cspell.ts", ".wrangler/**/*.ts", ".wrangler/**/*.js"],
extends: [eslint.configs.recommended, ...tsEslint.configs.recommended, sonarjs.configs.recommended],
languageOptions: {
parser: tsEslint.parser,
parserOptions: {
project: ["./tsconfig.json"],
},
},
rules: {
"check-file/filename-naming-convention": [
"error",
{
"**/*.{js,ts}": "+([-._a-z0-9])",
},
],
"prefer-arrow-callback": [
"warn",
{
allowNamedFunctions: true,
},
],
"func-style": [
"warn",
"declaration",
{
allowArrowFunctions: false,
},
],
"@typescript-eslint/no-floating-promises": "error",
"@typescript-eslint/no-non-null-assertion": "error",
"constructor-super": "error",
"no-invalid-this": "off",
"@typescript-eslint/no-invalid-this": ["error"],
"no-restricted-syntax": ["error", "ForInStatement"],
"use-isnan": "error",
"no-unneeded-ternary": "error",
"no-nested-ternary": "error",
"@typescript-eslint/no-unused-vars": [
"error",
{
args: "after-used",
ignoreRestSiblings: true,
vars: "all",
varsIgnorePattern: "^_",
argsIgnorePattern: "^_",
},
],
"@typescript-eslint/await-thenable": "error",
"@typescript-eslint/no-misused-new": "error",
"@typescript-eslint/restrict-plus-operands": "error",
"sonarjs/no-all-duplicated-branches": "error",
"sonarjs/no-collection-size-mischeck": "error",
"sonarjs/no-duplicated-branches": "error",
"sonarjs/no-element-overwrite": "error",
"sonarjs/no-identical-conditions": "error",
"sonarjs/no-identical-expressions": "error",
"@typescript-eslint/naming-convention": [
"error",
{
selector: "interface",
format: ["StrictPascalCase"],
custom: {
regex: "^I[A-Z]",
match: false,
},
},
{
selector: "memberLike",
modifiers: ["private"],
format: ["strictCamelCase"],
leadingUnderscore: "require",
},
{
selector: "typeLike",
format: ["StrictPascalCase"],
},
{
selector: "typeParameter",
format: ["StrictPascalCase"],
prefix: ["T"],
},
{
selector: "variable",
format: ["strictCamelCase", "UPPER_CASE"],
leadingUnderscore: "allow",
trailingUnderscore: "allow",
},
{
selector: "variable",
format: ["strictCamelCase"],
leadingUnderscore: "allow",
trailingUnderscore: "allow",
},
{
selector: "variable",
modifiers: ["destructured"],
format: null,
},
{
selector: "variable",
types: ["boolean"],
format: ["StrictPascalCase"],
prefix: ["is", "should", "has", "can", "did", "will", "does"],
},
{
selector: "variableLike",
format: ["strictCamelCase"],
},
{
selector: ["function", "variable"],
format: ["strictCamelCase"],
},
],
},
});
2 changes: 1 addition & 1 deletion jest.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
"coveragePathIgnorePatterns": ["node_modules", "mocks"],
"collectCoverage": true,
"coverageReporters": ["json", "lcov", "text", "clover", "json-summary"],
"reporters": ["default", "jest-junit"],
"reporters": ["default", "jest-junit", "jest-md-dashboard"],
"coverageDirectory": "coverage"
}
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "Start | Stop",
"description": "Assign or un-assign yourself from an issue.",
"ubiquity:listeners": [ "issue_comment.created" ],
"ubiquity:listeners": ["issue_comment.created"],
"commands": {
"start": {
"ubiquity:example": "/start",
Expand Down
51 changes: 26 additions & 25 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
"open-source"
],
"dependencies": {
"@octokit/rest": "^20.0.2",
"@octokit/webhooks": "^13.1.0",
"@octokit/rest": "20.1.1",
"@octokit/webhooks": "13.2.7",
"@sinclair/typebox": "^0.32.5",
"@supabase/supabase-js": "2.42.0",
"@ubiquity-dao/ubiquibot-logger": "^1.3.0",
Expand All @@ -39,35 +39,36 @@
"typebox-validators": "^0.3.5"
},
"devDependencies": {
"@commitlint/cli": "^18.6.1",
"@commitlint/config-conventional": "^18.6.2",
"@cspell/dict-node": "^4.0.3",
"@cspell/dict-software-terms": "^3.3.18",
"@cspell/dict-typescript": "^3.1.2",
"@commitlint/cli": "19.3.0",
"@commitlint/config-conventional": "19.2.2",
"@cspell/dict-node": "5.0.1",
"@cspell/dict-software-terms": "3.4.6",
"@cspell/dict-typescript": "3.1.5",
"@eslint/js": "9.5.0",
"@jest/globals": "29.7.0",
"@mswjs/data": "0.16.1",
"@types/jest": "29.5.12",
"@types/ms": "^0.7.34",
"@types/node": "^20.11.19",
"@typescript-eslint/eslint-plugin": "^7.0.1",
"@typescript-eslint/parser": "^7.0.1",
"cspell": "^8.4.0",
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-filename-rules": "^1.3.1",
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-sonarjs": "^0.24.0",
"husky": "^9.0.11",
"@types/node": "20.14.5",
"cspell": "8.9.0",
"eslint": "9.5.0",
"eslint-config-prettier": "9.1.0",
"eslint-plugin-check-file": "2.8.0",
"eslint-plugin-prettier": "5.1.3",
"eslint-plugin-sonarjs": "1.0.3",
"husky": "9.0.11",
"jest": "29.7.0",
"jest-junit": "16.0.0",
"knip": "^5.0.1",
"lint-staged": "^15.2.2",
"npm-run-all": "^4.1.5",
"prettier": "^3.2.5",
"ts-jest": "29.1.2",
"tsx": "^4.7.1",
"typescript": "^5.5.2",
"wrangler": "3.57.0"
"jest-md-dashboard": "0.8.0",
"knip": "5.21.2",
"lint-staged": "15.2.7",
"npm-run-all": "4.1.5",
"prettier": "3.3.2",
"ts-jest": "29.1.5",
"tsx": "4.15.6",
"typescript": "5.4.5",
"typescript-eslint": "7.13.1",
"wrangler": "3.60.3"
},
"lint-staged": {
"*.ts": [
Expand Down
2 changes: 1 addition & 1 deletion src/adapters/supabase/helpers/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class User extends Super {
await addCommentToIssue(this.context, "```diff\n! Please set your wallet address with the /wallet command first and try again.\n```");
throw new Error("No wallet address found");
} else {
await addCommentToIssue(this.context, "```diff\n# Please set your wallet address with the /wallet command in order to receive a task reward.\n```");
await addCommentToIssue(this.context, "```diff\n# Please set your wallet address with the /wallet command in order to be eligible for rewards.\n```");
}
} else {
this.context.logger.info("Successfully fetched wallet", { userId, address: data.wallets?.address });
Expand Down
20 changes: 14 additions & 6 deletions src/handlers/shared/start.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Context, ISSUE_TYPE, Label } from "../../types";
import { Assignee, Context, ISSUE_TYPE, Label } from "../../types";
import { isParentIssue, getAvailableOpenedPullRequests, getAssignedIssues, addAssignees, addCommentToIssue } from "../../utils/issue";
import { calculateDurations } from "../../utils/shared";
import { checkTaskStale } from "./check-task-stale";
Expand Down Expand Up @@ -45,20 +45,27 @@ export async function start(context: Context, issue: Context["payload"]["issue"]
// check for max and enforce max

if (assignedIssues.length - openedPullRequests.length >= maxConcurrentTasks) {
await addCommentToIssue(context, "```diff\n! Too many assigned issues, you have reached your max limit.\n```");
const log = logger.error("Too many assigned issues, you have reached your max limit", {
assignedIssues: assignedIssues.length,
openedPullRequests: openedPullRequests.length,
maxConcurrentTasks,
});
await addCommentToIssue(context, log?.logMessage.diff as string);
throw new Error(`Too many assigned issues, you have reached your max limit of ${maxConcurrentTasks} issues.`);
}

// is it assignable?

if (issue.state === ISSUE_TYPE.CLOSED) {
await addCommentToIssue(context, "```diff\n! The issue is closed. Please choose another unassigned task.\n```");
const log = logger.error("This issue is closed, please choose another.", { issueNumber: issue.number });
await addCommentToIssue(context, log?.logMessage.diff as string);
throw new Error("Issue is closed");
}

const assignees = (issue?.assignees ?? []).filter(Boolean);
if (assignees.length !== 0) {
await addCommentToIssue(context, "```diff\n! The issue is already assigned. Please choose another unassigned task.\n```");
const log = logger.error("The issue is already assigned. Please choose another unassigned task.", { issueNumber: issue.number });
await addCommentToIssue(context, log?.logMessage.diff as string);
throw new Error("Issue is already assigned");
}

Expand All @@ -68,7 +75,8 @@ export async function start(context: Context, issue: Context["payload"]["issue"]
const priceLabel = labels.find((label: Label) => label.name.startsWith("Price: "));

if (!priceLabel) {
await addCommentToIssue(context, "```diff\n! No price label is set to calculate the duration.\n```");
const log = logger.error("No price label is set to calculate the duration", { issueNumber: issue.number });
await addCommentToIssue(context, log?.logMessage.diff as string);
throw new Error("No price label is set to calculate the duration");
}

Expand All @@ -81,7 +89,7 @@ export async function start(context: Context, issue: Context["payload"]["issue"]
const metadata = structuredMetadata.create("Assignment", logMessage);

// add assignee
if (!assignees.map((i) => i?.login).includes(login)) {
if (!assignees.map((i: Partial<Assignee>) => i?.login).includes(login)) {
await addAssignees(context, issue.number, [login]);
}

Expand Down
Loading