From 9956aaeb2b806d0bf8060d9f7403c44a894180bb Mon Sep 17 00:00:00 2001 From: NucleoFusion Date: Mon, 10 Mar 2025 20:55:26 +0530 Subject: [PATCH 1/2] Adding the project and project-list subcommands --- package-lock.json | 418 ++++++++++++++++++ package.json | 1 + src/commands/info/info.ts | 25 ++ src/commands/info/subcommands/project-list.ts | 56 +++ src/commands/info/subcommands/project.ts | 71 +++ src/commands/info/subcommands/subcommands.ts | 4 +- src/index.ts | 6 + 7 files changed, 580 insertions(+), 1 deletion(-) create mode 100644 src/commands/info/subcommands/project-list.ts create mode 100644 src/commands/info/subcommands/project.ts diff --git a/package-lock.json b/package-lock.json index 58ddbcb..023fb78 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,6 +16,7 @@ "dotenv": "^16.4.7", "drizzle-orm": "^0.39.3", "eslint-plugin-drizzle": "^0.2.3", + "octokit": "^4.1.2", "pg": "^8.13.1", "pg-hstore": "^2.3.4" }, @@ -939,6 +940,347 @@ "node": ">= 8" } }, + "node_modules/@octokit/app": { + "version": "15.1.5", + "resolved": "https://registry.npmjs.org/@octokit/app/-/app-15.1.5.tgz", + "integrity": "sha512-6cxLT9U8x7GGQ7lNWsKtFr4ccg9oLkGvowk373sX9HvX5U37kql5d55SzaQUxPE8PwgX2cqkzDm5NF5aPKevqg==", + "license": "MIT", + "dependencies": { + "@octokit/auth-app": "^7.1.5", + "@octokit/auth-unauthenticated": "^6.1.2", + "@octokit/core": "^6.1.4", + "@octokit/oauth-app": "^7.1.6", + "@octokit/plugin-paginate-rest": "^11.4.2", + "@octokit/types": "^13.8.0", + "@octokit/webhooks": "^13.6.1" + }, + "engines": { + "node": ">= 18" + } + }, + "node_modules/@octokit/auth-app": { + "version": "7.1.5", + "resolved": "https://registry.npmjs.org/@octokit/auth-app/-/auth-app-7.1.5.tgz", + "integrity": "sha512-boklS4E6LpbA3nRx+SU2fRKRGZJdOGoSZne/i3Y0B5rfHOcGwFgcXrwDLdtbv4igfDSnAkZaoNBv1GYjPDKRNw==", + "license": "MIT", + "dependencies": { + "@octokit/auth-oauth-app": "^8.1.3", + "@octokit/auth-oauth-user": "^5.1.3", + "@octokit/request": "^9.2.1", + "@octokit/request-error": "^6.1.7", + "@octokit/types": "^13.8.0", + "toad-cache": "^3.7.0", + "universal-github-app-jwt": "^2.2.0", + "universal-user-agent": "^7.0.0" + }, + "engines": { + "node": ">= 18" + } + }, + "node_modules/@octokit/auth-oauth-app": { + "version": "8.1.3", + "resolved": "https://registry.npmjs.org/@octokit/auth-oauth-app/-/auth-oauth-app-8.1.3.tgz", + "integrity": "sha512-4e6OjVe5rZ8yBe8w7byBjpKtSXFuro7gqeGAAZc7QYltOF8wB93rJl2FE0a4U1Mt88xxPv/mS+25/0DuLk0Ewg==", + "license": "MIT", + "dependencies": { + "@octokit/auth-oauth-device": "^7.1.3", + "@octokit/auth-oauth-user": "^5.1.3", + "@octokit/request": "^9.2.1", + "@octokit/types": "^13.6.2", + "universal-user-agent": "^7.0.0" + }, + "engines": { + "node": ">= 18" + } + }, + "node_modules/@octokit/auth-oauth-device": { + "version": "7.1.3", + "resolved": "https://registry.npmjs.org/@octokit/auth-oauth-device/-/auth-oauth-device-7.1.3.tgz", + "integrity": "sha512-BECO/N4B/Uikj0w3GCvjf/odMujtYTP3q82BJSjxC2J3rxTEiZIJ+z2xnRlDb0IE9dQSaTgRqUPVOieSbFcVzg==", + "license": "MIT", + "dependencies": { + "@octokit/oauth-methods": "^5.1.4", + "@octokit/request": "^9.2.1", + "@octokit/types": "^13.6.2", + "universal-user-agent": "^7.0.0" + }, + "engines": { + "node": ">= 18" + } + }, + "node_modules/@octokit/auth-oauth-user": { + "version": "5.1.3", + "resolved": "https://registry.npmjs.org/@octokit/auth-oauth-user/-/auth-oauth-user-5.1.3.tgz", + "integrity": "sha512-zNPByPn9K7TC+OOHKGxU+MxrE9SZAN11UHYEFLsK2NRn3akJN2LHRl85q+Eypr3tuB2GrKx3rfj2phJdkYCvzw==", + "license": "MIT", + "dependencies": { + "@octokit/auth-oauth-device": "^7.1.3", + "@octokit/oauth-methods": "^5.1.3", + "@octokit/request": "^9.2.1", + "@octokit/types": "^13.6.2", + "universal-user-agent": "^7.0.0" + }, + "engines": { + "node": ">= 18" + } + }, + "node_modules/@octokit/auth-token": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/@octokit/auth-token/-/auth-token-5.1.2.tgz", + "integrity": "sha512-JcQDsBdg49Yky2w2ld20IHAlwr8d/d8N6NiOXbtuoPCqzbsiJgF633mVUw3x4mo0H5ypataQIX7SFu3yy44Mpw==", + "license": "MIT", + "engines": { + "node": ">= 18" + } + }, + "node_modules/@octokit/auth-unauthenticated": { + "version": "6.1.2", + "resolved": "https://registry.npmjs.org/@octokit/auth-unauthenticated/-/auth-unauthenticated-6.1.2.tgz", + "integrity": "sha512-07DlUGcz/AAVdzu3EYfi/dOyMSHp9YsOxPl/MPmtlVXWiD//GlV8HgZsPhud94DEyx+RfrW0wSl46Lx+AWbOlg==", + "license": "MIT", + "dependencies": { + "@octokit/request-error": "^6.1.7", + "@octokit/types": "^13.6.2" + }, + "engines": { + "node": ">= 18" + } + }, + "node_modules/@octokit/core": { + "version": "6.1.4", + "resolved": "https://registry.npmjs.org/@octokit/core/-/core-6.1.4.tgz", + "integrity": "sha512-lAS9k7d6I0MPN+gb9bKDt7X8SdxknYqAMh44S5L+lNqIN2NuV8nvv3g8rPp7MuRxcOpxpUIATWprO0C34a8Qmg==", + "license": "MIT", + "dependencies": { + "@octokit/auth-token": "^5.0.0", + "@octokit/graphql": "^8.1.2", + "@octokit/request": "^9.2.1", + "@octokit/request-error": "^6.1.7", + "@octokit/types": "^13.6.2", + "before-after-hook": "^3.0.2", + "universal-user-agent": "^7.0.0" + }, + "engines": { + "node": ">= 18" + } + }, + "node_modules/@octokit/endpoint": { + "version": "10.1.3", + "resolved": "https://registry.npmjs.org/@octokit/endpoint/-/endpoint-10.1.3.tgz", + "integrity": "sha512-nBRBMpKPhQUxCsQQeW+rCJ/OPSMcj3g0nfHn01zGYZXuNDvvXudF/TYY6APj5THlurerpFN4a/dQAIAaM6BYhA==", + "license": "MIT", + "dependencies": { + "@octokit/types": "^13.6.2", + "universal-user-agent": "^7.0.2" + }, + "engines": { + "node": ">= 18" + } + }, + "node_modules/@octokit/graphql": { + "version": "8.2.1", + "resolved": "https://registry.npmjs.org/@octokit/graphql/-/graphql-8.2.1.tgz", + "integrity": "sha512-n57hXtOoHrhwTWdvhVkdJHdhTv0JstjDbDRhJfwIRNfFqmSo1DaK/mD2syoNUoLCyqSjBpGAKOG0BuwF392slw==", + "license": "MIT", + "dependencies": { + "@octokit/request": "^9.2.2", + "@octokit/types": "^13.8.0", + "universal-user-agent": "^7.0.0" + }, + "engines": { + "node": ">= 18" + } + }, + "node_modules/@octokit/oauth-app": { + "version": "7.1.6", + "resolved": "https://registry.npmjs.org/@octokit/oauth-app/-/oauth-app-7.1.6.tgz", + "integrity": "sha512-OMcMzY2WFARg80oJNFwWbY51TBUfLH4JGTy119cqiDawSFXSIBujxmpXiKbGWQlvfn0CxE6f7/+c6+Kr5hI2YA==", + "license": "MIT", + "dependencies": { + "@octokit/auth-oauth-app": "^8.1.3", + "@octokit/auth-oauth-user": "^5.1.3", + "@octokit/auth-unauthenticated": "^6.1.2", + "@octokit/core": "^6.1.4", + "@octokit/oauth-authorization-url": "^7.1.1", + "@octokit/oauth-methods": "^5.1.4", + "@types/aws-lambda": "^8.10.83", + "universal-user-agent": "^7.0.0" + }, + "engines": { + "node": ">= 18" + } + }, + "node_modules/@octokit/oauth-authorization-url": { + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/@octokit/oauth-authorization-url/-/oauth-authorization-url-7.1.1.tgz", + "integrity": "sha512-ooXV8GBSabSWyhLUowlMIVd9l1s2nsOGQdlP2SQ4LnkEsGXzeCvbSbCPdZThXhEFzleGPwbapT0Sb+YhXRyjCA==", + "license": "MIT", + "engines": { + "node": ">= 18" + } + }, + "node_modules/@octokit/oauth-methods": { + "version": "5.1.4", + "resolved": "https://registry.npmjs.org/@octokit/oauth-methods/-/oauth-methods-5.1.4.tgz", + "integrity": "sha512-Jc/ycnePClOvO1WL7tlC+TRxOFtyJBGuTDsL4dzXNiVZvzZdrPuNw7zHI3qJSUX2n6RLXE5L0SkFmYyNaVUFoQ==", + "license": "MIT", + "dependencies": { + "@octokit/oauth-authorization-url": "^7.0.0", + "@octokit/request": "^9.2.1", + "@octokit/request-error": "^6.1.7", + "@octokit/types": "^13.6.2" + }, + "engines": { + "node": ">= 18" + } + }, + "node_modules/@octokit/openapi-types": { + "version": "23.0.1", + "resolved": "https://registry.npmjs.org/@octokit/openapi-types/-/openapi-types-23.0.1.tgz", + "integrity": "sha512-izFjMJ1sir0jn0ldEKhZ7xegCTj/ObmEDlEfpFrx4k/JyZSMRHbO3/rBwgE7f3m2DHt+RrNGIVw4wSmwnm3t/g==", + "license": "MIT" + }, + "node_modules/@octokit/openapi-webhooks-types": { + "version": "10.1.1", + "resolved": "https://registry.npmjs.org/@octokit/openapi-webhooks-types/-/openapi-webhooks-types-10.1.1.tgz", + "integrity": "sha512-qBfqQVIDQaCFeGCofXieJDwvXcGgDn17+UwZ6WW6lfEvGYGreLFzTiaz9xjet9Us4zDf8iasoW3ixUj/R5lMhA==", + "license": "MIT" + }, + "node_modules/@octokit/plugin-paginate-graphql": { + "version": "5.2.4", + "resolved": "https://registry.npmjs.org/@octokit/plugin-paginate-graphql/-/plugin-paginate-graphql-5.2.4.tgz", + "integrity": "sha512-pLZES1jWaOynXKHOqdnwZ5ULeVR6tVVCMm+AUbp0htdcyXDU95WbkYdU4R2ej1wKj5Tu94Mee2Ne0PjPO9cCyA==", + "license": "MIT", + "engines": { + "node": ">= 18" + }, + "peerDependencies": { + "@octokit/core": ">=6" + } + }, + "node_modules/@octokit/plugin-paginate-rest": { + "version": "11.4.3", + "resolved": "https://registry.npmjs.org/@octokit/plugin-paginate-rest/-/plugin-paginate-rest-11.4.3.tgz", + "integrity": "sha512-tBXaAbXkqVJlRoA/zQVe9mUdb8rScmivqtpv3ovsC5xhje/a+NOCivs7eUhWBwCApJVsR4G5HMeaLbq7PxqZGA==", + "license": "MIT", + "dependencies": { + "@octokit/types": "^13.7.0" + }, + "engines": { + "node": ">= 18" + }, + "peerDependencies": { + "@octokit/core": ">=6" + } + }, + "node_modules/@octokit/plugin-rest-endpoint-methods": { + "version": "13.3.1", + "resolved": "https://registry.npmjs.org/@octokit/plugin-rest-endpoint-methods/-/plugin-rest-endpoint-methods-13.3.1.tgz", + "integrity": "sha512-o8uOBdsyR+WR8MK9Cco8dCgvG13H1RlM1nWnK/W7TEACQBFux/vPREgKucxUfuDQ5yi1T3hGf4C5ZmZXAERgwQ==", + "license": "MIT", + "dependencies": { + "@octokit/types": "^13.8.0" + }, + "engines": { + "node": ">= 18" + }, + "peerDependencies": { + "@octokit/core": ">=6" + } + }, + "node_modules/@octokit/plugin-retry": { + "version": "7.1.4", + "resolved": "https://registry.npmjs.org/@octokit/plugin-retry/-/plugin-retry-7.1.4.tgz", + "integrity": "sha512-7AIP4p9TttKN7ctygG4BtR7rrB0anZqoU9ThXFk8nETqIfvgPUANTSYHqWYknK7W3isw59LpZeLI8pcEwiJdRg==", + "license": "MIT", + "dependencies": { + "@octokit/request-error": "^6.1.7", + "@octokit/types": "^13.6.2", + "bottleneck": "^2.15.3" + }, + "engines": { + "node": ">= 18" + }, + "peerDependencies": { + "@octokit/core": ">=6" + } + }, + "node_modules/@octokit/plugin-throttling": { + "version": "9.4.0", + "resolved": "https://registry.npmjs.org/@octokit/plugin-throttling/-/plugin-throttling-9.4.0.tgz", + "integrity": "sha512-IOlXxXhZA4Z3m0EEYtrrACkuHiArHLZ3CvqWwOez/pURNqRuwfoFlTPbN5Muf28pzFuztxPyiUiNwz8KctdZaQ==", + "license": "MIT", + "dependencies": { + "@octokit/types": "^13.7.0", + "bottleneck": "^2.15.3" + }, + "engines": { + "node": ">= 18" + }, + "peerDependencies": { + "@octokit/core": "^6.1.3" + } + }, + "node_modules/@octokit/request": { + "version": "9.2.2", + "resolved": "https://registry.npmjs.org/@octokit/request/-/request-9.2.2.tgz", + "integrity": "sha512-dZl0ZHx6gOQGcffgm1/Sf6JfEpmh34v3Af2Uci02vzUYz6qEN6zepoRtmybWXIGXFIK8K9ylE3b+duCWqhArtg==", + "license": "MIT", + "dependencies": { + "@octokit/endpoint": "^10.1.3", + "@octokit/request-error": "^6.1.7", + "@octokit/types": "^13.6.2", + "fast-content-type-parse": "^2.0.0", + "universal-user-agent": "^7.0.2" + }, + "engines": { + "node": ">= 18" + } + }, + "node_modules/@octokit/request-error": { + "version": "6.1.7", + "resolved": "https://registry.npmjs.org/@octokit/request-error/-/request-error-6.1.7.tgz", + "integrity": "sha512-69NIppAwaauwZv6aOzb+VVLwt+0havz9GT5YplkeJv7fG7a40qpLt/yZKyiDxAhgz0EtgNdNcb96Z0u+Zyuy2g==", + "license": "MIT", + "dependencies": { + "@octokit/types": "^13.6.2" + }, + "engines": { + "node": ">= 18" + } + }, + "node_modules/@octokit/types": { + "version": "13.8.0", + "resolved": "https://registry.npmjs.org/@octokit/types/-/types-13.8.0.tgz", + "integrity": "sha512-x7DjTIbEpEWXK99DMd01QfWy0hd5h4EN+Q7shkdKds3otGQP+oWE/y0A76i1OvH9fygo4ddvNf7ZvF0t78P98A==", + "license": "MIT", + "dependencies": { + "@octokit/openapi-types": "^23.0.1" + } + }, + "node_modules/@octokit/webhooks": { + "version": "13.7.4", + "resolved": "https://registry.npmjs.org/@octokit/webhooks/-/webhooks-13.7.4.tgz", + "integrity": "sha512-f386XyLTieQbgKPKS6ZMlH4dq8eLsxNddwofiKRZCq0bZ2gikoFwMD99K6l1oAwqe/KZNzrEziGicRgnzplplQ==", + "license": "MIT", + "dependencies": { + "@octokit/openapi-webhooks-types": "10.1.1", + "@octokit/request-error": "^6.1.7", + "@octokit/webhooks-methods": "^5.1.1" + }, + "engines": { + "node": ">= 18" + } + }, + "node_modules/@octokit/webhooks-methods": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/@octokit/webhooks-methods/-/webhooks-methods-5.1.1.tgz", + "integrity": "sha512-NGlEHZDseJTCj8TMMFehzwa9g7On4KJMPVHDSrHxCQumL6uSQR8wIkP/qesv52fXqV1BPf4pTxwtS31ldAt9Xg==", + "license": "MIT", + "engines": { + "node": ">= 18" + } + }, "node_modules/@sapphire/async-queue": { "version": "1.5.5", "resolved": "https://registry.npmjs.org/@sapphire/async-queue/-/async-queue-1.5.5.tgz", @@ -972,6 +1314,12 @@ "npm": ">=7.0.0" } }, + "node_modules/@types/aws-lambda": { + "version": "8.10.147", + "resolved": "https://registry.npmjs.org/@types/aws-lambda/-/aws-lambda-8.10.147.tgz", + "integrity": "sha512-nD0Z9fNIZcxYX5Mai2CTmFD7wX7UldCkW2ezCF8D1T5hdiLsnTWDGRpfRYntU6VjTdLQjOvyszru7I1c1oCQew==", + "license": "MIT" + }, "node_modules/@types/estree": { "version": "1.0.6", "license": "MIT" @@ -1681,6 +2029,12 @@ "version": "1.0.2", "license": "MIT" }, + "node_modules/before-after-hook": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/before-after-hook/-/before-after-hook-3.0.2.tgz", + "integrity": "sha512-Nik3Sc0ncrMK4UUdXQmAnRtzmNQTAAXmXIopizwZ1W1t8QmfJj+zL4OA2I7XPTPW5z5TDqv4hRo/JzouDJnX3A==", + "license": "Apache-2.0" + }, "node_modules/binary-extensions": { "version": "2.3.0", "dev": true, @@ -1692,6 +2046,12 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/bottleneck": { + "version": "2.19.5", + "resolved": "https://registry.npmjs.org/bottleneck/-/bottleneck-2.19.5.tgz", + "integrity": "sha512-VHiNCbI1lKdl44tGrhNfU3lup0Tj/ZBMJB5/2ZbNXRCPuRCO7ed2mgcK4r17y+KB2EfuYuRaVlwNbAeaWGSpbw==", + "license": "MIT" + }, "node_modules/brace-expansion": { "version": "1.1.11", "license": "MIT", @@ -3032,6 +3392,22 @@ "node": ">=0.10.0" } }, + "node_modules/fast-content-type-parse": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/fast-content-type-parse/-/fast-content-type-parse-2.0.1.tgz", + "integrity": "sha512-nGqtvLrj5w0naR6tDPfB4cUmYCqouzyQiz6C5y/LtcDllJdrcc6WaWW6iXyIIOErTa/XRybj28aasdn4LkVk6Q==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/fastify" + }, + { + "type": "opencollective", + "url": "https://opencollective.com/fastify" + } + ], + "license": "MIT" + }, "node_modules/fast-deep-equal": { "version": "3.1.3", "license": "MIT" @@ -3477,6 +3853,27 @@ "devOptional": true, "license": "MIT" }, + "node_modules/octokit": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/octokit/-/octokit-4.1.2.tgz", + "integrity": "sha512-0kcTxJOK3yQrJsRb8wKa28hlTze4QOz4sLuUnfXXnhboDhFKgv8LxS86tFwbsafDW9JZ08ByuVAE8kQbYJIZkA==", + "license": "MIT", + "dependencies": { + "@octokit/app": "^15.1.4", + "@octokit/core": "^6.1.4", + "@octokit/oauth-app": "^7.1.6", + "@octokit/plugin-paginate-graphql": "^5.2.4", + "@octokit/plugin-paginate-rest": "^11.4.2", + "@octokit/plugin-rest-endpoint-methods": "^13.3.1", + "@octokit/plugin-retry": "^7.1.4", + "@octokit/plugin-throttling": "^9.4.0", + "@octokit/request-error": "^6.1.7", + "@octokit/types": "^13.7.0" + }, + "engines": { + "node": ">= 18" + } + }, "node_modules/optionator": { "version": "0.9.4", "license": "MIT", @@ -4087,6 +4484,15 @@ "node": ">=8.0" } }, + "node_modules/toad-cache": { + "version": "3.7.0", + "resolved": "https://registry.npmjs.org/toad-cache/-/toad-cache-3.7.0.tgz", + "integrity": "sha512-/m8M+2BJUpoJdgAHoG+baCwBT+tf2VraSfkBgl0Y00qIWt41DJ8R5B8nsEw0I58YwF5IZH6z24/2TobDKnqSWw==", + "license": "MIT", + "engines": { + "node": ">=12" + } + }, "node_modules/touch": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/touch/-/touch-3.1.1.tgz", @@ -4302,6 +4708,18 @@ "version": "6.20.0", "license": "MIT" }, + "node_modules/universal-github-app-jwt": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/universal-github-app-jwt/-/universal-github-app-jwt-2.2.0.tgz", + "integrity": "sha512-G5o6f95b5BggDGuUfKDApKaCgNYy2x7OdHY0zSMF081O0EJobw+1130VONhrA7ezGSV2FNOGyM+KQpQZAr9bIQ==", + "license": "MIT" + }, + "node_modules/universal-user-agent": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/universal-user-agent/-/universal-user-agent-7.0.2.tgz", + "integrity": "sha512-0JCqzSKnStlRRQfCdowvqy3cy0Dvtlb8xecj/H8JFZuCze4rwjPZQOgvFvn0Ws/usCHQFGpyr+pB9adaGwXn4Q==", + "license": "ISC" + }, "node_modules/uri-js": { "version": "4.4.1", "license": "BSD-2-Clause", diff --git a/package.json b/package.json index 9408162..7b1ab64 100644 --- a/package.json +++ b/package.json @@ -30,6 +30,7 @@ "dotenv": "^16.4.7", "drizzle-orm": "^0.39.3", "eslint-plugin-drizzle": "^0.2.3", + "octokit": "^4.1.2", "pg": "^8.13.1", "pg-hstore": "^2.3.4" }, diff --git a/src/commands/info/info.ts b/src/commands/info/info.ts index 33dd8c8..1eee5b2 100644 --- a/src/commands/info/info.ts +++ b/src/commands/info/info.ts @@ -3,6 +3,8 @@ import { printServerRoles, printServerInfo, printUserInfo, + printProjectInfo, + printProjectList } from "./subcommands/subcommands.js"; export const command = { @@ -29,7 +31,24 @@ export const command = { .setDescription("The username to search for") .setRequired(false), ), + ) + .addSubcommand((subcommand) => + subcommand + .setName("project") + .setDescription("Provides information about a project.") + .addStringOption((option) => + option + .setName("project") + .setDescription("The project to view details for.") + .setRequired(true), + ), + ) + .addSubcommand((subcommand) => + subcommand + .setName("project-list") + .setDescription("Provides a list of all project."), ), + async execute(interaction: ChatInputCommandInteraction) { const subcommand = interaction.options.getSubcommand(); @@ -43,6 +62,12 @@ export const command = { case "user": await printUserInfo(interaction); break; + case "project": + await printProjectInfo(interaction); + break; + case "project-list": + await printProjectList(interaction); + break; } }, }; diff --git a/src/commands/info/subcommands/project-list.ts b/src/commands/info/subcommands/project-list.ts new file mode 100644 index 0000000..f091872 --- /dev/null +++ b/src/commands/info/subcommands/project-list.ts @@ -0,0 +1,56 @@ +import { AppClient } from "@/index.js"; +import { ChatInputCommandInteraction, Client, EmbedBuilder, MessageFlags } from "discord.js"; +import { RequestError } from "octokit"; + +export async function printProjectList(interaction: ChatInputCommandInteraction) { + // Ensure the command is executed in a guild + if (!interaction.guild) { + await interaction.reply({ + content: "This command can only be used within a server.", + flags: MessageFlags.Ephemeral, + }); + return; + } + + const client = interaction.client as AppClient & Client; + + try { //Octokit throws an error when not found + + const reqBody = { + org: "SourcewareLab", + }; + + const resp = await client.octokit.rest.repos.listForOrg(reqBody) + + let message = ''; + + resp.data.forEach((repo) => { + message += `**•** [${repo.name}](${repo.html_url})` + '\n' + }) + + const embed = new EmbedBuilder() + .setColor(0x2f3136) + .setTitle("Community Projects") + .setDescription(message) + .setThumbnail(resp.data[0].owner.avatar_url) + + await interaction.reply({ + embeds: [embed], + flags: [MessageFlags.Ephemeral] + }) + + } catch (err) { + if (err instanceof RequestError && err.status === 404) { // Checks if Repo was not found ,ie, 404 error. + await interaction.reply({ + content: `Could not find repository make sure the name was correct. `, + flags: MessageFlags.Ephemeral + }) + return; + } + + await interaction.reply({ + content: `Error while trying to query the Github API -> ${err} `, + flags: MessageFlags.Ephemeral + }) + } +} diff --git a/src/commands/info/subcommands/project.ts b/src/commands/info/subcommands/project.ts new file mode 100644 index 0000000..1a4e862 --- /dev/null +++ b/src/commands/info/subcommands/project.ts @@ -0,0 +1,71 @@ +import { AppClient } from "@/index.js"; +import { ChatInputCommandInteraction, Client, EmbedBuilder, MessageFlags } from "discord.js"; +import { RequestError } from "octokit"; + +// After DB is figured out +//TODO: Add a Project Leads section +//TODO: Add a Description + +export async function printProjectInfo(interaction: ChatInputCommandInteraction) { + // Ensure the command is executed in a guild + if (!interaction.guild) { + await interaction.reply({ + content: "This command can only be used within a server.", + flags: MessageFlags.Ephemeral, + }); + return; + } + + const client = interaction.client as AppClient & Client; + + const project = interaction.options.getString("project"); + + try { //Octokit throws an error when not found + + const reqBody = { + owner: "SourcewareLab", + repo: project as string, + }; + + const resp = await client.octokit.rest.repos.get(reqBody) + + const languages = await client.octokit.rest.repos.listLanguages(reqBody) + + let languageString = ''; + + for (const lang of Object.keys(languages.data)) { + languageString += lang + ', ' + } + + const message = ` + **Languages**: ${languageString.slice(0, -2)}\n + **Issues**: There are [**${resp.data.open_issues}**](${resp.data.html_url + "/issues"}) Open Issues that you can work on. + `.trimStart(); // to allow formatting here, but ignore the tabs in Response + + const embed = new EmbedBuilder() + .setColor(0x2f3136) + .setTitle(resp.data.name) + .setURL(resp.data.html_url) + .setDescription(message) + .setThumbnail(resp.data.owner.avatar_url) + + await interaction.reply({ + embeds: [embed], + flags: MessageFlags.Ephemeral + }) + + } catch (err) { + if (err instanceof RequestError && err.status === 404) { // Checks if Repo was not found ,ie, 404 error. + await interaction.reply({ + content: `Could not find repository make sure the name was correct. `, + flags: MessageFlags.Ephemeral + }) + return; + } + + await interaction.reply({ + content: `Error while trying to query the Github API -> ${err} `, + flags: MessageFlags.Ephemeral + }) + } +} diff --git a/src/commands/info/subcommands/subcommands.ts b/src/commands/info/subcommands/subcommands.ts index d833c82..759b441 100644 --- a/src/commands/info/subcommands/subcommands.ts +++ b/src/commands/info/subcommands/subcommands.ts @@ -1,5 +1,7 @@ import { printServerRoles } from "./roles.js"; import { printServerInfo } from "./server.js"; import { printUserInfo } from "./user.js"; +import { printProjectInfo } from "./project.js"; +import { printProjectList } from "./project-list.js"; -export { printServerRoles, printServerInfo, printUserInfo }; +export { printServerRoles, printServerInfo, printUserInfo, printProjectInfo, printProjectList }; diff --git a/src/index.ts b/src/index.ts index bd810c5..5f8cc6e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -10,6 +10,7 @@ import path from "path"; import { fileURLToPath, pathToFileURL } from "url"; import { AppDatabase } from "./data/database.js"; import { runMigrations } from "./data/migrate.js"; +import { Octokit } from "octokit"; interface Command { execute(interaction: ChatInputCommandInteraction): Promise; @@ -18,6 +19,7 @@ interface Command { export class AppClient extends Client { commands: Collection; db: AppDatabase; + octokit: Octokit; constructor() { super({ @@ -30,6 +32,10 @@ export class AppClient extends Client { }); this.commands = new Collection(); this.db = AppDatabase.getInstance(); + + this.octokit = new Octokit({ + auth: process.env.GITHUB_AUTH_TOKEN as string, + }) } destroy() { From ed31e33c96f23ffd57d222063f50f9b2530b91d5 Mon Sep 17 00:00:00 2001 From: NucleoFusion Date: Mon, 10 Mar 2025 21:28:51 +0530 Subject: [PATCH 2/2] Sample.env fix --- SAMPLE.env | 1 + 1 file changed, 1 insertion(+) diff --git a/SAMPLE.env b/SAMPLE.env index 47e1549..eca6710 100644 --- a/SAMPLE.env +++ b/SAMPLE.env @@ -6,3 +6,4 @@ WELCOME_CHANNEL_ID=welcome_channel_id NEWCOMER_ROLE_ID=newcomer_role_id ADMIN_ROLE_ID=admin_role_id +GITHUB_AUTH_TOKEN=get_your_own_token