diff --git a/.github/workflows/jest-testing.yml b/.github/workflows/jest-testing.yml index 69af0ea..62a81b5 100644 --- a/.github/workflows/jest-testing.yml +++ b/.github/workflows/jest-testing.yml @@ -1,13 +1,12 @@ name: Run Jest testing suite on: workflow_dispatch: - workflow_run: - workflows: ["Knip"] - types: - - completed + pull_request: env: NODE_ENV: "test" + SUPABASE_URL: "http://127.0.0.1:3000" + SUPABASE_KEY: "supabase-key" jobs: testing: @@ -21,14 +20,13 @@ jobs: - uses: actions/checkout@master with: fetch-depth: 0 - + - name: Enable corepack run: corepack enable - - name: Jest With Coverage Comment - # Ensures this step is run even on previous step failure (e.g. test failed) + - name: Jest With Coverage + run: yarn install && yarn test + + - name: Add Jest Report to Summary if: always() - uses: ArtiomTr/jest-coverage-report-action@v2 - with: - package-manager: yarn - prnumber: ${{ github.event.pull_request.number || github.event.workflow_run.pull_requests[0].number }} + run: echo "$(cat test-dashboard.md)" >> $GITHUB_STEP_SUMMARY diff --git a/.github/workflows/knip-reporter.yml b/.github/workflows/knip-reporter.yml new file mode 100644 index 0000000..a396735 --- /dev/null +++ b/.github/workflows/knip-reporter.yml @@ -0,0 +1,40 @@ +name: Knip-reporter + +on: + workflow_run: + workflows: ["Knip"] + types: + - completed + +permissions: write-all + +jobs: + knip-reporter: + runs-on: ubuntu-latest + if: ${{ github.event.workflow_run.conclusion != 'success' }} + steps: + - uses: actions/download-artifact@v4 + with: + name: knip-results + run-id: ${{ github.event.workflow_run.id }} + github-token: ${{ secrets.GITHUB_TOKEN }} + + - name: Read pr number + id: pr-number + uses: juliangruber/read-file-action@v1 + with: + path: ./pr-number.txt + trim: true + + - name: Report knip results to pull request + uses: gitcoindev/knip-reporter@main + with: + verbose: true + comment_id: ${{ github.workflow }}-reporter + command_script_name: knip-ci + annotations: true + ignore_results: false + json_input: true + json_input_file_name: knip-results.json + pull_request_number: ${{ steps.pr-number.outputs.content }} + token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/knip.yml b/.github/workflows/knip.yml index 67837dc..2ff169d 100644 --- a/.github/workflows/knip.yml +++ b/.github/workflows/knip.yml @@ -1,11 +1,9 @@ name: Knip on: - pull_request_target: + pull_request: workflow_dispatch: -permissions: write-all - jobs: run-knip: runs-on: ubuntu-latest @@ -17,18 +15,24 @@ jobs: uses: actions/setup-node@v4 with: node-version: 20.10.0 - + - name: Enable corepack run: corepack enable - name: Install toolchain run: yarn install - - name: Report knip results to pull request - uses: Codex-/knip-reporter@v2 + - name: Store PR number + run: echo ${{ github.event.number }} > pr-number.txt + + - name: Run Knip + run: yarn knip || yarn knip --reporter json > knip-results.json + + - name: Upload knip result + if: failure() + uses: actions/upload-artifact@v4 with: - verbose: true - comment_id: ${{ github.workflow }}-reporter - command_script_name: knip-ci - annotations: true - ignore_results: false + name: knip-results + path: | + knip-results.json + pr-number.txt diff --git a/.github/workflows/release-please.yml b/.github/workflows/release-please.yml index a5b40f7..a38ccee 100644 --- a/.github/workflows/release-please.yml +++ b/.github/workflows/release-please.yml @@ -4,7 +4,7 @@ on: workflow_dispatch: push: branches: - - $default-branch + - main permissions: contents: write @@ -14,13 +14,7 @@ jobs: release-please: runs-on: ubuntu-latest steps: - - uses: google-github-actions/release-please-action@v3 + - uses: googleapis/release-please-action@v4 with: - release-type: node - - uses: actions/checkout@v3 - - uses: actions/setup-node@v4 - with: - node-version: "20.10.0" - registry-url: https://registry.npmjs.org/ - - run: | - yarn install --immutable --immutable-cache --check-cache + release-type: simple + target-branch: main diff --git a/manifest.json b/manifest.json new file mode 100644 index 0000000..2538fce --- /dev/null +++ b/manifest.json @@ -0,0 +1,15 @@ +{ + "name": "Start | Stop", + "description": "Assign or un-assign yourself from an issue.", + "ubiquity:listeners": [ "issue_comment.created" ], + "commands": { + "start": { + "ubiquity:example": "/start", + "description": "Assign yourself to the issue." + }, + "stop": { + "ubiquity:example": "/stop", + "description": "Unassign yourself from the issue." + } + } +} diff --git a/package.json b/package.json index 889c3cb..c0f7e65 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "@ubiquibot/command-start-stop", "version": "1.0.0", "description": "Enables the assignment and graceful unassignment of tasks to contributors.", - "main": "build/index.ts", + "main": "src/worker.ts", "author": "Ubiquity DAO", "license": "MIT", "engines": { @@ -29,8 +29,6 @@ "open-source" ], "dependencies": { - "@actions/core": "^1.10.1", - "@actions/github": "^6.0.0", "@octokit/rest": "^20.0.2", "@octokit/webhooks": "^13.1.0", "@sinclair/typebox": "^0.32.5", diff --git a/src/main.ts b/src/main.ts deleted file mode 100644 index 3131ced..0000000 --- a/src/main.ts +++ /dev/null @@ -1,48 +0,0 @@ -import * as core from "@actions/core"; -import * as github from "@actions/github"; -import { Octokit } from "@octokit/rest"; -import { Value } from "@sinclair/typebox/build/cjs/value"; -import { envSchema, startStopSchema, PluginInputs } from "./types"; -import { startStopTask } from "./plugin"; - -export async function run() { - const payload = github.context.payload.inputs; - - const env = Value.Decode(envSchema, process.env); - const settings = Value.Decode(startStopSchema, JSON.parse(payload.settings)); - - const inputs: PluginInputs = { - stateId: payload.stateId, - eventName: payload.eventName, - eventPayload: JSON.parse(payload.eventPayload), - settings, - authToken: payload.authToken, - ref: payload.ref, - }; - - await startStopTask(inputs, env); - - return toKernel(inputs.authToken, inputs.stateId, {}); -} - -async function toKernel(repoToken: string, stateId: string, output: object) { - const octokit = new Octokit({ auth: repoToken }); - await octokit.repos.createDispatchEvent({ - owner: github.context.repo.owner, - repo: github.context.repo.repo, - event_type: "return_data_to_ubiquibot_kernel", - client_payload: { - state_id: stateId, - output: JSON.stringify(output), - }, - }); -} - -run() - .then((result) => { - core.setOutput("result", result); - }) - .catch((error) => { - console.error(error); - core.setFailed(error); - }); diff --git a/src/plugin.ts b/src/plugin.ts index 918d5a1..ec2bf09 100644 --- a/src/plugin.ts +++ b/src/plugin.ts @@ -1,11 +1,9 @@ -import { Context } from "./types/context"; -import { userStartStop } from "./handlers/user-start-stop"; -import { Env, PluginInputs } from "./types"; - import { Octokit } from "@octokit/rest"; import { createClient } from "@supabase/supabase-js"; -import { createAdapters } from "./adapters"; import { Logs } from "@ubiquity-dao/ubiquibot-logger"; +import { createAdapters } from "./adapters"; +import { userStartStop } from "./handlers/user-start-stop"; +import { Context, Env, PluginInputs } from "./types"; export async function startStopTask(inputs: PluginInputs, env: Env) { const octokit = new Octokit({ auth: inputs.authToken }); diff --git a/src/worker.ts b/src/worker.ts index 542529b..6a024c3 100644 --- a/src/worker.ts +++ b/src/worker.ts @@ -1,7 +1,6 @@ import { Value } from "@sinclair/typebox/value"; import { startStopTask } from "./plugin"; -import { Env } from "./types/env"; -import { startStopSchema, startStopSettingsValidator } from "./types/plugin-input"; +import { Env, startStopSchema, startStopSettingsValidator } from "./types"; export default { async fetch(request: Request, env: Env): Promise { diff --git a/yarn.lock b/yarn.lock index 9b7c1bb..11208f7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5,38 +5,6 @@ __metadata: version: 8 cacheKey: 10c0 -"@actions/core@npm:^1.10.1": - version: 1.10.1 - resolution: "@actions/core@npm:1.10.1" - dependencies: - "@actions/http-client": "npm:^2.0.1" - uuid: "npm:^8.3.2" - checksum: 10c0/7a61446697a23dcad3545cf0634dedbdedf20ae9a0ee6ee977554589a15deb4a93593ee48a41258933d58ce0778f446b0d2c162b60750956fb75e0b9560fb832 - languageName: node - linkType: hard - -"@actions/github@npm:^6.0.0": - version: 6.0.0 - resolution: "@actions/github@npm:6.0.0" - dependencies: - "@actions/http-client": "npm:^2.2.0" - "@octokit/core": "npm:^5.0.1" - "@octokit/plugin-paginate-rest": "npm:^9.0.0" - "@octokit/plugin-rest-endpoint-methods": "npm:^10.0.0" - checksum: 10c0/6f86f564e6ec5873c69ff23bed308cef5f964dbdb559c5415c1ba479517bf18352713a2a757c27f8f67a3d675fdd78446cf142b27762489f697edf9c58e72378 - languageName: node - linkType: hard - -"@actions/http-client@npm:^2.0.1, @actions/http-client@npm:^2.2.0": - version: 2.2.1 - resolution: "@actions/http-client@npm:2.2.1" - dependencies: - tunnel: "npm:^0.0.6" - undici: "npm:^5.25.4" - checksum: 10c0/371771e68fcfe1383e59657eb5bc421aba5e1826f5e497efd826236b64fc1ff11f0bc91f936d7f1086f6bb3fd209736425a4d357b98fdfb7a8d054cbb84680e8 - languageName: node - linkType: hard - "@ampproject/remapping@npm:^2.2.0": version: 2.3.0 resolution: "@ampproject/remapping@npm:2.3.0" @@ -2145,7 +2113,7 @@ __metadata: languageName: node linkType: hard -"@octokit/core@npm:^5.0.1, @octokit/core@npm:^5.0.2": +"@octokit/core@npm:^5.0.2": version: 5.2.0 resolution: "@octokit/core@npm:5.2.0" dependencies: @@ -2181,13 +2149,6 @@ __metadata: languageName: node linkType: hard -"@octokit/openapi-types@npm:^20.0.0": - version: 20.0.0 - resolution: "@octokit/openapi-types@npm:20.0.0" - checksum: 10c0/5176dcc3b9d182ede3d446750cfa5cf31139624785a73fcf3511e3102a802b4d7cc45e999c27ed91d73fe8b7d718c8c406facb48688926921a71fe603b7db95d - languageName: node - linkType: hard - "@octokit/openapi-types@npm:^22.2.0": version: 22.2.0 resolution: "@octokit/openapi-types@npm:22.2.0" @@ -2213,17 +2174,6 @@ __metadata: languageName: node linkType: hard -"@octokit/plugin-paginate-rest@npm:^9.0.0": - version: 9.2.1 - resolution: "@octokit/plugin-paginate-rest@npm:9.2.1" - dependencies: - "@octokit/types": "npm:^12.6.0" - peerDependencies: - "@octokit/core": 5 - checksum: 10c0/1dc55032a9e0c3e6440080a319975c9e4f189913fbc8870a48048d0c712473ea3d902ba247a37a46d45d502859b2728731a0d285107e4b0fa628d380f87163b4 - languageName: node - linkType: hard - "@octokit/plugin-request-log@npm:^4.0.0": version: 4.0.1 resolution: "@octokit/plugin-request-log@npm:4.0.1" @@ -2244,17 +2194,6 @@ __metadata: languageName: node linkType: hard -"@octokit/plugin-rest-endpoint-methods@npm:^10.0.0": - version: 10.4.1 - resolution: "@octokit/plugin-rest-endpoint-methods@npm:10.4.1" - dependencies: - "@octokit/types": "npm:^12.6.0" - peerDependencies: - "@octokit/core": 5 - checksum: 10c0/4b8f64c0f7fa12464546ad312a5289c2a799967e01e90e2c4923ec6e9604cf212dcb50d9795c9a688867f973c9c529c5950368564c560406c652bcd298f090af - languageName: node - linkType: hard - "@octokit/request-error@npm:^5.1.0": version: 5.1.0 resolution: "@octokit/request-error@npm:5.1.0" @@ -2299,15 +2238,6 @@ __metadata: languageName: node linkType: hard -"@octokit/types@npm:^12.6.0": - version: 12.6.0 - resolution: "@octokit/types@npm:12.6.0" - dependencies: - "@octokit/openapi-types": "npm:^20.0.0" - checksum: 10c0/0bea58bda46c93287f5a80a0e52bc60e7dc7136b8a38c3569d63d073fb9df4a56acdb9d9bdba9978f37c374a4a6e3e52886ef5b08cace048adb0012cacef942c - languageName: node - linkType: hard - "@octokit/types@npm:^13.0.0, @octokit/types@npm:^13.1.0, @octokit/types@npm:^13.5.0": version: 13.5.0 resolution: "@octokit/types@npm:13.5.0" @@ -2833,8 +2763,6 @@ __metadata: version: 0.0.0-use.local resolution: "@ubiquibot/command-start-stop@workspace:." dependencies: - "@actions/core": "npm:^1.10.1" - "@actions/github": "npm:^6.0.0" "@commitlint/cli": "npm:^18.6.1" "@commitlint/config-conventional": "npm:^18.6.2" "@cspell/dict-node": "npm:^4.0.3" @@ -8910,13 +8838,6 @@ __metadata: languageName: node linkType: hard -"tunnel@npm:^0.0.6": - version: 0.0.6 - resolution: "tunnel@npm:0.0.6" - checksum: 10c0/e27e7e896f2426c1c747325b5f54efebc1a004647d853fad892b46d64e37591ccd0b97439470795e5262b5c0748d22beb4489a04a0a448029636670bfd801b75 - languageName: node - linkType: hard - "type-check@npm:^0.4.0, type-check@npm:~0.4.0": version: 0.4.0 resolution: "type-check@npm:0.4.0" @@ -9075,7 +8996,7 @@ __metadata: languageName: node linkType: hard -"undici@npm:^5.25.4, undici@npm:^5.28.2": +"undici@npm:^5.28.2": version: 5.28.4 resolution: "undici@npm:5.28.4" dependencies: