From e4f9c65d614d7037551e5fe04e793982d2057e32 Mon Sep 17 00:00:00 2001 From: rayan Date: Sat, 11 Jul 2026 19:41:25 +0200 Subject: [PATCH 01/59] ci: det-21 init architecture of ci to add comment to pr --- .github/workflows/debtlint.yml | 16 +++ action/.gitignore | 1 + action/README.md | 10 ++ action/action.yml | 24 ++++ action/index.js | 4 + action/package-lock.json | 254 +++++++++++++++++++++++++++++++++ action/package.json | 17 +++ action/src/.gitkeep | 0 8 files changed, 326 insertions(+) create mode 100644 .github/workflows/debtlint.yml create mode 100644 action/.gitignore create mode 100644 action/README.md create mode 100644 action/action.yml create mode 100644 action/index.js create mode 100644 action/package-lock.json create mode 100644 action/package.json create mode 100644 action/src/.gitkeep diff --git a/.github/workflows/debtlint.yml b/.github/workflows/debtlint.yml new file mode 100644 index 0000000..bd67bff --- /dev/null +++ b/.github/workflows/debtlint.yml @@ -0,0 +1,16 @@ +name: Check duplication + +on: + push: + +jobs: + debtlint: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v6 + + - name: Run debtlint + uses: ./action + with: + files: "src" \ No newline at end of file diff --git a/action/.gitignore b/action/.gitignore new file mode 100644 index 0000000..b512c09 --- /dev/null +++ b/action/.gitignore @@ -0,0 +1 @@ +node_modules \ No newline at end of file diff --git a/action/README.md b/action/README.md new file mode 100644 index 0000000..750219d --- /dev/null +++ b/action/README.md @@ -0,0 +1,10 @@ +# Debtlint action + +This action download and run the [debtlint tools](https://github.com/PoCInnovation/Debtlint). + + +## Inputs + +**Required** + +## Outputs \ No newline at end of file diff --git a/action/action.yml b/action/action.yml new file mode 100644 index 0000000..1cf65bf --- /dev/null +++ b/action/action.yml @@ -0,0 +1,24 @@ +name: debtlint +description: Identifies repeated or near-duplicate code segments across a codebase. +author: poc-innovation +branding: + icon: "check-circle" + color: "green" + +inputs: + files: + required: false + +runs: + using: composite + steps: + + - name: Install debtlint + shell: nu {0} + run: cargo install debtlint + + - name: Run debtlint + shell: nu {0} + env: + GITHUB_TOKEN: ${{ github.token }} + run: node ${{ github.action_path }}/index.js \ No newline at end of file diff --git a/action/index.js b/action/index.js new file mode 100644 index 0000000..045aa4c --- /dev/null +++ b/action/index.js @@ -0,0 +1,4 @@ +import * as core from "@actions/core"; +import * as github from "@actions/github"; + +console.log("Test") \ No newline at end of file diff --git a/action/package-lock.json b/action/package-lock.json new file mode 100644 index 0000000..bc162a7 --- /dev/null +++ b/action/package-lock.json @@ -0,0 +1,254 @@ +{ + "name": "action", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "action", + "version": "1.0.0", + "license": "ISC", + "dependencies": { + "@actions/core": "^3.0.1", + "@actions/github": "^9.1.1" + } + }, + "node_modules/@actions/core": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/@actions/core/-/core-3.0.1.tgz", + "integrity": "sha512-a6d/Nwahm9fliVGRhdhofo40HjHQasUPusmc7vBfyky+7Z+P2A1J68zyFVaNcEclc/Se+eO595oAr5nwEIoIUA==", + "license": "MIT", + "dependencies": { + "@actions/exec": "^3.0.0", + "@actions/http-client": "^4.0.0" + } + }, + "node_modules/@actions/exec": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/@actions/exec/-/exec-3.0.0.tgz", + "integrity": "sha512-6xH/puSoNBXb72VPlZVm7vQ+svQpFyA96qdDBvhB8eNZOE8LtPf9L4oAsfzK/crCL8YZ+19fKYVnM63Sl+Xzlw==", + "license": "MIT", + "dependencies": { + "@actions/io": "^3.0.2" + } + }, + "node_modules/@actions/github": { + "version": "9.1.1", + "resolved": "https://registry.npmjs.org/@actions/github/-/github-9.1.1.tgz", + "integrity": "sha512-tL5JbYOBZHc0ngEnCsaDcryUizIUIlQyIMwy1Wkx93H5HzbBJ7TbiPx2PnFjBwZW0Vh05JmfFZhecE6gglYegA==", + "license": "MIT", + "dependencies": { + "@actions/http-client": "^3.0.2", + "@octokit/core": "^7.0.6", + "@octokit/plugin-paginate-rest": "^14.0.0", + "@octokit/plugin-rest-endpoint-methods": "^17.0.0", + "@octokit/request": "^10.0.7", + "@octokit/request-error": "^7.1.0", + "undici": "^6.23.0" + } + }, + "node_modules/@actions/github/node_modules/@actions/http-client": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-3.0.2.tgz", + "integrity": "sha512-JP38FYYpyqvUsz+Igqlc/JG6YO9PaKuvqjM3iGvaLqFnJ7TFmcLyy2IDrY0bI0qCQug8E9K+elv5ZNfw62ZJzA==", + "license": "MIT", + "dependencies": { + "tunnel": "^0.0.6", + "undici": "^6.23.0" + } + }, + "node_modules/@actions/http-client": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-4.0.1.tgz", + "integrity": "sha512-+Nvd1ImaOZBSoPbsUtEhv+1z99H12xzncCkz0a3RuehINE81FZSe2QTj3uvAPTcJX/SCzUQHQ0D1GrPMbrPitg==", + "license": "MIT", + "dependencies": { + "tunnel": "^0.0.6", + "undici": "^6.23.0" + } + }, + "node_modules/@actions/io": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/@actions/io/-/io-3.0.2.tgz", + "integrity": "sha512-nRBchcMM+QK1pdjO7/idu86rbJI5YHUKCvKs0KxnSYbVe3F51UfGxuZX4Qy/fWlp6l7gWFwIkrOzN+oUK03kfw==", + "license": "MIT" + }, + "node_modules/@octokit/auth-token": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/@octokit/auth-token/-/auth-token-6.0.0.tgz", + "integrity": "sha512-P4YJBPdPSpWTQ1NU4XYdvHvXJJDxM6YwpS0FZHRgP7YFkdVxsWcpWGy/NVqlAA7PcPCnMacXlRm1y2PFZRWL/w==", + "license": "MIT", + "engines": { + "node": ">= 20" + } + }, + "node_modules/@octokit/core": { + "version": "7.0.6", + "resolved": "https://registry.npmjs.org/@octokit/core/-/core-7.0.6.tgz", + "integrity": "sha512-DhGl4xMVFGVIyMwswXeyzdL4uXD5OGILGX5N8Y+f6W7LhC1Ze2poSNrkF/fedpVDHEEZ+PHFW0vL14I+mm8K3Q==", + "license": "MIT", + "dependencies": { + "@octokit/auth-token": "^6.0.0", + "@octokit/graphql": "^9.0.3", + "@octokit/request": "^10.0.6", + "@octokit/request-error": "^7.0.2", + "@octokit/types": "^16.0.0", + "before-after-hook": "^4.0.0", + "universal-user-agent": "^7.0.0" + }, + "engines": { + "node": ">= 20" + } + }, + "node_modules/@octokit/endpoint": { + "version": "11.0.3", + "resolved": "https://registry.npmjs.org/@octokit/endpoint/-/endpoint-11.0.3.tgz", + "integrity": "sha512-FWFlNxghg4HrXkD3ifYbS/IdL/mDHjh9QcsNyhQjN8dplUoZbejsdpmuqdA76nxj2xoWPs7p8uX2SNr9rYu0Ag==", + "license": "MIT", + "dependencies": { + "@octokit/types": "^16.0.0", + "universal-user-agent": "^7.0.2" + }, + "engines": { + "node": ">= 20" + } + }, + "node_modules/@octokit/graphql": { + "version": "9.0.3", + "resolved": "https://registry.npmjs.org/@octokit/graphql/-/graphql-9.0.3.tgz", + "integrity": "sha512-grAEuupr/C1rALFnXTv6ZQhFuL1D8G5y8CN04RgrO4FIPMrtm+mcZzFG7dcBm+nq+1ppNixu+Jd78aeJOYxlGA==", + "license": "MIT", + "dependencies": { + "@octokit/request": "^10.0.6", + "@octokit/types": "^16.0.0", + "universal-user-agent": "^7.0.0" + }, + "engines": { + "node": ">= 20" + } + }, + "node_modules/@octokit/openapi-types": { + "version": "27.0.0", + "resolved": "https://registry.npmjs.org/@octokit/openapi-types/-/openapi-types-27.0.0.tgz", + "integrity": "sha512-whrdktVs1h6gtR+09+QsNk2+FO+49j6ga1c55YZudfEG+oKJVvJLQi3zkOm5JjiUXAagWK2tI2kTGKJ2Ys7MGA==", + "license": "MIT" + }, + "node_modules/@octokit/plugin-paginate-rest": { + "version": "14.0.0", + "resolved": "https://registry.npmjs.org/@octokit/plugin-paginate-rest/-/plugin-paginate-rest-14.0.0.tgz", + "integrity": "sha512-fNVRE7ufJiAA3XUrha2omTA39M6IXIc6GIZLvlbsm8QOQCYvpq/LkMNGyFlB1d8hTDzsAXa3OKtybdMAYsV/fw==", + "license": "MIT", + "dependencies": { + "@octokit/types": "^16.0.0" + }, + "engines": { + "node": ">= 20" + }, + "peerDependencies": { + "@octokit/core": ">=6" + } + }, + "node_modules/@octokit/plugin-rest-endpoint-methods": { + "version": "17.0.0", + "resolved": "https://registry.npmjs.org/@octokit/plugin-rest-endpoint-methods/-/plugin-rest-endpoint-methods-17.0.0.tgz", + "integrity": "sha512-B5yCyIlOJFPqUUeiD0cnBJwWJO8lkJs5d8+ze9QDP6SvfiXSz1BF+91+0MeI1d2yxgOhU/O+CvtiZ9jSkHhFAw==", + "license": "MIT", + "dependencies": { + "@octokit/types": "^16.0.0" + }, + "engines": { + "node": ">= 20" + }, + "peerDependencies": { + "@octokit/core": ">=6" + } + }, + "node_modules/@octokit/request": { + "version": "10.0.11", + "resolved": "https://registry.npmjs.org/@octokit/request/-/request-10.0.11.tgz", + "integrity": "sha512-+s7HUxjfFqOMS9VlIwDffq0MikjSAK0gSpG73W+meAvVAvX4MBrHYTK5Bj3Uot55qFT4gzUtfzE4mGWY4Br8/Q==", + "license": "MIT", + "dependencies": { + "@octokit/endpoint": "^11.0.3", + "@octokit/request-error": "^7.0.2", + "@octokit/types": "^16.0.0", + "content-type": "^2.0.0", + "json-with-bigint": "^3.5.3", + "universal-user-agent": "^7.0.2" + }, + "engines": { + "node": ">= 20" + } + }, + "node_modules/@octokit/request-error": { + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/@octokit/request-error/-/request-error-7.1.0.tgz", + "integrity": "sha512-KMQIfq5sOPpkQYajXHwnhjCC0slzCNScLHs9JafXc4RAJI+9f+jNDlBNaIMTvazOPLgb4BnlhGJOTbnN0wIjPw==", + "license": "MIT", + "dependencies": { + "@octokit/types": "^16.0.0" + }, + "engines": { + "node": ">= 20" + } + }, + "node_modules/@octokit/types": { + "version": "16.0.0", + "resolved": "https://registry.npmjs.org/@octokit/types/-/types-16.0.0.tgz", + "integrity": "sha512-sKq+9r1Mm4efXW1FCk7hFSeJo4QKreL/tTbR0rz/qx/r1Oa2VV83LTA/H/MuCOX7uCIJmQVRKBcbmWoySjAnSg==", + "license": "MIT", + "dependencies": { + "@octokit/openapi-types": "^27.0.0" + } + }, + "node_modules/before-after-hook": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/before-after-hook/-/before-after-hook-4.0.0.tgz", + "integrity": "sha512-q6tR3RPqIB1pMiTRMFcZwuG5T8vwp+vUvEG0vuI6B+Rikh5BfPp2fQ82c925FOs+b0lcFQ8CFrL+KbilfZFhOQ==", + "license": "Apache-2.0" + }, + "node_modules/content-type": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/content-type/-/content-type-2.0.0.tgz", + "integrity": "sha512-j/O/d7GcZCyNl7/hwZAb606rzqkyvaDctLmckbxLzHvFBzTJHuGEdodATcP3yIRoDrLHkIATJuvzbFlp/ki2cQ==", + "license": "MIT", + "engines": { + "node": ">=18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/json-with-bigint": { + "version": "3.5.10", + "resolved": "https://registry.npmjs.org/json-with-bigint/-/json-with-bigint-3.5.10.tgz", + "integrity": "sha512-Vcx+JVNEBts/xfcoCS69sKrOhOk/3TVlvlT+XzUOefVKnnrbYSCKpDCm10pohsJFtsJVYnwa/cXRZ4eElzaM6w==", + "license": "MIT" + }, + "node_modules/tunnel": { + "version": "0.0.6", + "resolved": "https://registry.npmjs.org/tunnel/-/tunnel-0.0.6.tgz", + "integrity": "sha512-1h/Lnq9yajKY2PEbBadPXj3VxsDDu844OnaAo52UVmIzIvwwtBPIuNvkjuzBlTWpfJyUbG3ez0KSBibQkj4ojg==", + "license": "MIT", + "engines": { + "node": ">=0.6.11 <=0.7.0 || >=0.7.3" + } + }, + "node_modules/undici": { + "version": "6.27.0", + "resolved": "https://registry.npmjs.org/undici/-/undici-6.27.0.tgz", + "integrity": "sha512-YmfV3YnEDzXRC5lZ2jWtWWHKGUm1zIt8AhesR1tens+HTNv+YZlN/dp6G727LOvMJ8xjP9Be7Y2Sdr96LDm+pg==", + "license": "MIT", + "engines": { + "node": ">=18.17" + } + }, + "node_modules/universal-user-agent": { + "version": "7.0.3", + "resolved": "https://registry.npmjs.org/universal-user-agent/-/universal-user-agent-7.0.3.tgz", + "integrity": "sha512-TmnEAEAsBJVZM/AADELsK76llnwcf9vMKuPz8JflO1frO8Lchitr0fNaN9d+Ap0BjKtqWqd/J17qeDnXh8CL2A==", + "license": "ISC" + } + } +} diff --git a/action/package.json b/action/package.json new file mode 100644 index 0000000..d736c2a --- /dev/null +++ b/action/package.json @@ -0,0 +1,17 @@ +{ + "name": "action", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [], + "author": "", + "license": "ISC", + "type": "commonjs", + "dependencies": { + "@actions/core": "^3.0.1", + "@actions/github": "^9.1.1" + } +} diff --git a/action/src/.gitkeep b/action/src/.gitkeep new file mode 100644 index 0000000..e69de29 From c5ca409c505edd50d1bb30b866004afaa1fcad03 Mon Sep 17 00:00:00 2001 From: rayan Date: Sat, 11 Jul 2026 19:49:44 +0200 Subject: [PATCH 02/59] ci: det-21 change shell nu -> sh --- action/action.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/action/action.yml b/action/action.yml index 1cf65bf..c8a18ef 100644 --- a/action/action.yml +++ b/action/action.yml @@ -14,11 +14,11 @@ runs: steps: - name: Install debtlint - shell: nu {0} + shell: sh run: cargo install debtlint - name: Run debtlint - shell: nu {0} + shell: sh env: GITHUB_TOKEN: ${{ github.token }} run: node ${{ github.action_path }}/index.js \ No newline at end of file From d81e5dae85ce5a0df38a263625578bdd172cf5d9 Mon Sep 17 00:00:00 2001 From: rayan Date: Sat, 11 Jul 2026 19:52:44 +0200 Subject: [PATCH 03/59] feat: det-21 change import to action.js --- action/index.js | 3 --- action/src/action.js | 3 +++ 2 files changed, 3 insertions(+), 3 deletions(-) create mode 100644 action/src/action.js diff --git a/action/index.js b/action/index.js index 045aa4c..7841ce0 100644 --- a/action/index.js +++ b/action/index.js @@ -1,4 +1 @@ -import * as core from "@actions/core"; -import * as github from "@actions/github"; - console.log("Test") \ No newline at end of file diff --git a/action/src/action.js b/action/src/action.js new file mode 100644 index 0000000..19e143e --- /dev/null +++ b/action/src/action.js @@ -0,0 +1,3 @@ +import * as core from "@actions/core"; +import * as github from "@actions/github"; + From 602095e32376bc102f32756f01fa1dcb2a5a06ba Mon Sep 17 00:00:00 2001 From: rayan Date: Sun, 12 Jul 2026 13:38:17 +0200 Subject: [PATCH 04/59] feat: det-21 execute command in a child processs --- action/index.js | 1 - action/package-lock.json | 20 ++++++++++++++++++++ action/package.json | 7 +++++-- action/src/action.js | 3 --- action/src/debtlint.js | 15 +++++++++++++++ action/src/{.gitkeep => index.js} | 0 6 files changed, 40 insertions(+), 6 deletions(-) delete mode 100644 action/index.js delete mode 100644 action/src/action.js create mode 100644 action/src/debtlint.js rename action/src/{.gitkeep => index.js} (100%) diff --git a/action/index.js b/action/index.js deleted file mode 100644 index 7841ce0..0000000 --- a/action/index.js +++ /dev/null @@ -1 +0,0 @@ -console.log("Test") \ No newline at end of file diff --git a/action/package-lock.json b/action/package-lock.json index bc162a7..8635370 100644 --- a/action/package-lock.json +++ b/action/package-lock.json @@ -11,6 +11,9 @@ "dependencies": { "@actions/core": "^3.0.1", "@actions/github": "^9.1.1" + }, + "devDependencies": { + "@types/node": "^26.1.1" } }, "node_modules/@actions/core": { @@ -201,6 +204,16 @@ "@octokit/openapi-types": "^27.0.0" } }, + "node_modules/@types/node": { + "version": "26.1.1", + "resolved": "https://registry.npmjs.org/@types/node/-/node-26.1.1.tgz", + "integrity": "sha512-nxAkRSVkN1Y0JC1W8ky/fTfkGsMmcrRsbx+3XoZE+rMOX71kLYTV7fLXpqud1GpbpP5TuffXFqfX7fH2GgZREw==", + "dev": true, + "license": "MIT", + "dependencies": { + "undici-types": "~8.3.0" + } + }, "node_modules/before-after-hook": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/before-after-hook/-/before-after-hook-4.0.0.tgz", @@ -244,6 +257,13 @@ "node": ">=18.17" } }, + "node_modules/undici-types": { + "version": "8.3.0", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-8.3.0.tgz", + "integrity": "sha512-j375ScV60dom+YkPFIfTLcOiPxkN/buHz5GobjLhixFuANaNs3C9l4GmrWqejgXWJ7BbJcFYpTEUkS1Ge8bpZQ==", + "dev": true, + "license": "MIT" + }, "node_modules/universal-user-agent": { "version": "7.0.3", "resolved": "https://registry.npmjs.org/universal-user-agent/-/universal-user-agent-7.0.3.tgz", diff --git a/action/package.json b/action/package.json index d736c2a..e76f792 100644 --- a/action/package.json +++ b/action/package.json @@ -1,7 +1,7 @@ { "name": "action", "version": "1.0.0", - "description": "", + "description": "This action download and run the [debtlint tools](https://github.com/PoCInnovation/Debtlint).", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" @@ -9,9 +9,12 @@ "keywords": [], "author": "", "license": "ISC", - "type": "commonjs", + "type": "module", "dependencies": { "@actions/core": "^3.0.1", "@actions/github": "^9.1.1" + }, + "devDependencies": { + "@types/node": "^26.1.1" } } diff --git a/action/src/action.js b/action/src/action.js deleted file mode 100644 index 19e143e..0000000 --- a/action/src/action.js +++ /dev/null @@ -1,3 +0,0 @@ -import * as core from "@actions/core"; -import * as github from "@actions/github"; - diff --git a/action/src/debtlint.js b/action/src/debtlint.js new file mode 100644 index 0000000..a55d1df --- /dev/null +++ b/action/src/debtlint.js @@ -0,0 +1,15 @@ +import { ChildProcess, spawn } from 'child_process'; + + +/** + * Execute a command asynchronously. + * @param {string} cmd + * @param {array} arguments + */ +export const execCommand = (cmd, arg = []) => { + return spawn(cmd, arg) +}; + +// convert object to json +// parse list of duplicate element +// send element with the api github \ No newline at end of file diff --git a/action/src/.gitkeep b/action/src/index.js similarity index 100% rename from action/src/.gitkeep rename to action/src/index.js From 2019a9fb5cc0d61337b5c81838a9f83df6fe91b1 Mon Sep 17 00:00:00 2001 From: rayan Date: Tue, 21 Jul 2026 02:24:47 +0200 Subject: [PATCH 05/59] feat: det-21 test first version of CI and call API of github --- Cargo.lock | 63 +++++++++++++++++++++++----------------- action/src/debtlint.js | 61 +++++++++++++++++++++++++++++++++----- action/src/schemas.js | 19 ++++++++++++ src/debug_run.rs | 10 +++++++ src/lib.rs | 1 + src/linter/diagnostic.rs | 20 +++++++++++++ src/linter/linter.rs | 14 +++++++++ src/linter/mod.rs | 5 ++++ src/main.rs | 4 +-- src/pipeline.rs | 1 + 10 files changed, 162 insertions(+), 36 deletions(-) create mode 100644 action/src/schemas.js create mode 100644 src/linter/diagnostic.rs create mode 100644 src/linter/linter.rs create mode 100644 src/linter/mod.rs diff --git a/Cargo.lock b/Cargo.lock index c0e2156..37893b0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -54,9 +54,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.6.1" +version = "4.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ddb117e43bbf7dacf0a4190fef4d345b9bad68dfc649cb349e7d17d28428e51" +checksum = "0fb99565819980999fb7b4a1796046a5c949e6d4ff132cf5fadf5a641e20d776" dependencies = [ "clap_builder", "clap_derive", @@ -64,9 +64,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.6.0" +version = "4.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "714a53001bf66416adb0e2ef5ac857140e7dc3a0c48fb28b2f10762fc4b5069f" +checksum = "f09628afdcc538b57f3c6341e9c8e9970f18e4a481690a64974d7023bd33548b" dependencies = [ "anstream", "anstyle", @@ -76,14 +76,14 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.6.1" +version = "4.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2ce8604710f6733aa641a2b3731eaa1e8b3d9973d5e3565da11800813f997a9" +checksum = "32f2392eae7f16557a3d727ef3a12e57b2b2ca6f98566a5f4fb41ffe305df077" dependencies = [ "heck", "proc-macro2", "quote", - "syn", + "syn 2.0.119", ] [[package]] @@ -127,9 +127,9 @@ checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682" [[package]] name = "memchr" -version = "2.8.2" +version = "2.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88904434abc2901f197fe8cc55f0445e7ded921dba5911dad2e2b39b48e663c4" +checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98" [[package]] name = "once_cell_polyfill" @@ -139,27 +139,27 @@ checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe" [[package]] name = "proc-macro2" -version = "1.0.106" +version = "1.0.107" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934" +checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.45" +version = "1.0.47" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41f2619966050689382d2b44f664f4bc593e129785a36d6ee376ddf37259b924" +checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001" dependencies = [ "proc-macro2", ] [[package]] name = "serde" -version = "1.0.228" +version = "1.0.229" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e" +checksum = "4148590afebada386688f18773da617792bf2ef03ffc1e4cbd2b1d45b023e0ba" dependencies = [ "serde_core", "serde_derive", @@ -167,29 +167,29 @@ dependencies = [ [[package]] name = "serde_core" -version = "1.0.228" +version = "1.0.229" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad" +checksum = "67dca2c9c51e58a4791a4b1ed58308b39c64224d349a935ab5039aa360942a48" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.228" +version = "1.0.229" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" +checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 3.0.2", ] [[package]] name = "serde_json" -version = "1.0.150" +version = "1.0.151" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8014e44b4736ed0538adeecded0fce2a272f22dc9578a7eb6b2d9993c74cfb9" +checksum = "c841b55ecdae098c80dcae9cf767f6f8a0c2cdb3416bbef72181df4d0fe73f14" dependencies = [ "itoa", "memchr", @@ -206,9 +206,20 @@ checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" [[package]] name = "syn" -version = "2.0.117" +version = "2.0.119" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e665b8803e7b1d2a727f4023456bbbbe74da67099c585258af0ad9c5013b9b99" +checksum = "872831b642d1a07999a962a351ed35b955ea2cfc8f3862091e2a240a84f17297" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "3.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a207d6d6a2b7fc470b80443726053f18a2481b7e1eee970597051596567987a3" dependencies = [ "proc-macro2", "quote", @@ -244,6 +255,6 @@ dependencies = [ [[package]] name = "zmij" -version = "1.0.21" +version = "1.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8848ee67ecc8aedbaf3e4122217aff892639231befc6a1b58d29fff4c2cabaa" +checksum = "29666d0abbfad1e3dc4dcf6144730dd3a3ab225bbbdac83319345b1b44ccfc1b" diff --git a/action/src/debtlint.js b/action/src/debtlint.js index a55d1df..37a82ed 100644 --- a/action/src/debtlint.js +++ b/action/src/debtlint.js @@ -1,15 +1,60 @@ -import { ChildProcess, spawn } from 'child_process'; +import * as core from '@actions/core'; +import * as github from '@actions/github'; +import { Octokit } from '@octokit/action'; +import { spawn } from 'child_process'; +import { diagnosticSchema } from './schemas.js'; + +const octokit = new Octokit(); /** - * Execute a command asynchronously. + * Execute a command in a child process * @param {string} cmd - * @param {array} arguments + * @param {string[]} args + * @returns {Promise} */ -export const execCommand = (cmd, arg = []) => { - return spawn(cmd, arg) +const execCommand = (cmd, args = []) => { + return new Promise((resolve, reject) => { + const process = spawn(cmd, args); + let output; + let errorOutput; + + process.stdout.on('data', (data) => { + output += data.toString(); + }); + + process.stderr.on('data', (data) => { + errorOutput += data.toString(); + }); + + process.on('close', (code) => { + if (code !== 0) { + return reject(new Error(`Process exited with code ${code}: ${errorOutput}`)); + } + resolve(output); + }); + + process.on('error', reject); + }); }; -// convert object to json -// parse list of duplicate element -// send element with the api github \ No newline at end of file +const rawOutput = await runCommand('cargo', ['run', 'main.rs']); +const diagnostic = diagnosticSchema.parse(JSON.parse(rawOutput)); + +const range = diagnostic.ranges[0]; + +await octokit.request('POST /repos/{owner}/{repo}/pulls/{pull_number}/comments', { + owner: github.context.repo.owner, + repo: github.context.repo.repo, + pull_number: github.context.payload.pull_request.number, + body: diagnostic.code_description, + commit_id: github.context.payload.pull_request.head.sha, + path: diagnostic.source, + start_line: range.start.line, + start_side: 'RIGHT', + line: range.end.line, + side: 'RIGHT', + headers: { + 'X-GitHub-Api-Version': '2026-03-10', + }, +}); \ No newline at end of file diff --git a/action/src/schemas.js b/action/src/schemas.js new file mode 100644 index 0000000..af12006 --- /dev/null +++ b/action/src/schemas.js @@ -0,0 +1,19 @@ +import { z } from "zod"; + +const positionSchema = z.object({ + line: z.number().min(0), + character: z.number().min(0), +}); + +const rangeSchema = z.object({ + start: positionSchema, + end: positionSchema, +}); + +export const diagnosticSchema = z.object({ + source: z.string(), + severity: z.string(), + code: z.number().min(0) , + ranges: z.array(rangeSchema), + codeDescription: z.string().optional(), +}) diff --git a/src/debug_run.rs b/src/debug_run.rs index 945b69a..38b93b4 100644 --- a/src/debug_run.rs +++ b/src/debug_run.rs @@ -1,9 +1,17 @@ use debtlint::in_out::{read_corpus, save_vocabulary, write_encoded_sequence_json}; use debtlint::pipeline::{BpeConfig, run_bpe}; use debtlint::tokenizer::{BASE_VOCAB_SIZE, SourceFile, decode_sequence}; +use debtlint::linter::{get_duplicated}; use crate::cli::Args; + +pub fn run_linter() -> std::io::Result<()> { + println!("{:?}", get_duplicated()); + Ok(()) +} + +#[allow(dead_code)] pub fn run(args: &Args) -> std::io::Result<()> { let content = read_corpus(&args.file)?; let files = vec![SourceFile { @@ -30,6 +38,7 @@ pub fn run(args: &Args) -> std::io::Result<()> { Ok(()) } +#[allow(dead_code)] fn print_stats(result: &debtlint::tokenizer::BpeTrainingResult, content: &str, args: &Args) { let initial_tokens = result.initial_token_count; let encoded_tokens = result.encoded_token_count(); @@ -59,6 +68,7 @@ fn print_stats(result: &debtlint::tokenizer::BpeTrainingResult, content: &str, a ); } +#[allow(dead_code)] fn verify_decode_roundtrip( args: &Args, files: &[SourceFile], diff --git a/src/lib.rs b/src/lib.rs index 7d0b318..584e63b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,4 @@ pub mod in_out; pub mod pipeline; pub mod tokenizer; +pub mod linter; \ No newline at end of file diff --git a/src/linter/diagnostic.rs b/src/linter/diagnostic.rs new file mode 100644 index 0000000..f01b535 --- /dev/null +++ b/src/linter/diagnostic.rs @@ -0,0 +1,20 @@ +#[derive(Debug)] +pub struct Position { + pub line: u32, + pub character: u32 +} + +#[derive(Debug)] +pub struct Range { + pub start: Position, + pub end: Position +} + +#[derive(Debug)] +pub struct Diagnostic { + pub source: String, + pub severity: String, + pub code: u16, + pub ranges: Vec, + pub code_description: String +} \ No newline at end of file diff --git a/src/linter/linter.rs b/src/linter/linter.rs new file mode 100644 index 0000000..677a1aa --- /dev/null +++ b/src/linter/linter.rs @@ -0,0 +1,14 @@ +use super::diagnostic::{Diagnostic, Range, Position}; + +pub fn get_duplicated() -> Diagnostic { + Diagnostic { + source: String::from("src/main.rs"), + severity: String::from("low"), + code: 1, + ranges: vec![Range { + start: Position { line: 8, character: 8 }, + end: Position { line: 8, character: 12 }, + }], + code_description: String::from("No typing"), + } +} \ No newline at end of file diff --git a/src/linter/mod.rs b/src/linter/mod.rs new file mode 100644 index 0000000..68415a0 --- /dev/null +++ b/src/linter/mod.rs @@ -0,0 +1,5 @@ +mod diagnostic; +mod linter; + +pub use diagnostic::{Diagnostic}; +pub use linter::get_duplicated; \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 50df667..ee58a09 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,8 +5,8 @@ use clap::Parser; use cli::Args; fn main() { - let args = Args::parse(); - if let Err(err) = debug_run::run(&args) { + let _ = Args::parse(); + if let Err(err) = debug_run::run_linter() { eprintln!("{err}"); std::process::exit(1); } diff --git a/src/pipeline.rs b/src/pipeline.rs index c3fd0d1..6187b5b 100644 --- a/src/pipeline.rs +++ b/src/pipeline.rs @@ -1,5 +1,6 @@ use crate::in_out::load_vocabulary; use crate::tokenizer::{BpeTrainingResult, SourceFile, encode_corpus, train_corpus}; + use std::path::Path; pub struct BpeConfig { From b855680a1004d8c8607cfd97487f9cf23009e0b9 Mon Sep 17 00:00:00 2001 From: rayan Date: Tue, 21 Jul 2026 02:30:53 +0200 Subject: [PATCH 06/59] fix: det-21 move index.js out src directory --- action/index.js | 1 + action/src/index.js | 0 2 files changed, 1 insertion(+) create mode 100644 action/index.js delete mode 100644 action/src/index.js diff --git a/action/index.js b/action/index.js new file mode 100644 index 0000000..ebb2c48 --- /dev/null +++ b/action/index.js @@ -0,0 +1 @@ +import './src/debtlint.js'; \ No newline at end of file diff --git a/action/src/index.js b/action/src/index.js deleted file mode 100644 index e69de29..0000000 From 1cd6d8ce441d8145b29b2e9ad9867068a5113874 Mon Sep 17 00:00:00 2001 From: rayan Date: Tue, 21 Jul 2026 02:34:26 +0200 Subject: [PATCH 07/59] fix: det-21 install dependecies --- action/action.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/action/action.yml b/action/action.yml index c8a18ef..6df3bbe 100644 --- a/action/action.yml +++ b/action/action.yml @@ -17,6 +17,10 @@ runs: shell: sh run: cargo install debtlint + - name: Install dependencies + shell: sh + run: npm install + - name: Run debtlint shell: sh env: From 6240542f2ce6f1e95e362d1a8ea34466fe61a27f Mon Sep 17 00:00:00 2001 From: rayan Date: Tue, 21 Jul 2026 02:36:01 +0200 Subject: [PATCH 08/59] refactor: det-21 specify working directory --- action/action.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/action/action.yml b/action/action.yml index 6df3bbe..db6b0d5 100644 --- a/action/action.yml +++ b/action/action.yml @@ -20,6 +20,8 @@ runs: - name: Install dependencies shell: sh run: npm install + working-directory: ./action + - name: Run debtlint shell: sh From c4ecc3d619580dd55cd276605ee1c57da8c7622d Mon Sep 17 00:00:00 2001 From: rayan Date: Tue, 21 Jul 2026 02:38:43 +0200 Subject: [PATCH 09/59] refactor: det-21 update packagejson --- action/package-lock.json | 52 +++++++++++++++++++++++++++++++++++++++- action/package.json | 4 +++- 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/action/package-lock.json b/action/package-lock.json index 8635370..add6874 100644 --- a/action/package-lock.json +++ b/action/package-lock.json @@ -10,7 +10,9 @@ "license": "ISC", "dependencies": { "@actions/core": "^3.0.1", - "@actions/github": "^9.1.1" + "@actions/github": "^9.1.1", + "@octokit/action": "^8.0.4", + "zod": "^4.4.3" }, "devDependencies": { "@types/node": "^26.1.1" @@ -76,6 +78,45 @@ "integrity": "sha512-nRBchcMM+QK1pdjO7/idu86rbJI5YHUKCvKs0KxnSYbVe3F51UfGxuZX4Qy/fWlp6l7gWFwIkrOzN+oUK03kfw==", "license": "MIT" }, + "node_modules/@octokit/action": { + "version": "8.0.4", + "resolved": "https://registry.npmjs.org/@octokit/action/-/action-8.0.4.tgz", + "integrity": "sha512-1qFYTCrShafc5fQaEbLNUo4xIi/nf98R8iAcJ0ITTCfoRnei9g5Ss9kGkN2tOA7gBlI4HB08Seub4navWXSSbg==", + "license": "MIT", + "dependencies": { + "@octokit/auth-action": "^6.0.2", + "@octokit/core": "^7.0.6", + "@octokit/plugin-paginate-rest": "^14.0.0", + "@octokit/plugin-rest-endpoint-methods": "^17.0.0", + "@octokit/types": "^16.0.0", + "undici": "^7.0.0" + }, + "engines": { + "node": ">= 20" + } + }, + "node_modules/@octokit/action/node_modules/undici": { + "version": "7.28.0", + "resolved": "https://registry.npmjs.org/undici/-/undici-7.28.0.tgz", + "integrity": "sha512-cRZYrTDwWznlnRiPjggAGxZXanty6M8RV1ff8Wm4LWXBp7/IG8v5DnOm74DtUBp9OONpK75YlPnIjQqX0dBDtA==", + "license": "MIT", + "engines": { + "node": ">=20.18.1" + } + }, + "node_modules/@octokit/auth-action": { + "version": "6.0.2", + "resolved": "https://registry.npmjs.org/@octokit/auth-action/-/auth-action-6.0.2.tgz", + "integrity": "sha512-gEBsz0QioHOMoEU7u2VMr2FfOvfJCrGc42K9rliS7LnlZJLcEMFccIiCiPpPNH+yXs7YYNKQ7lOX67ZTWn6Ysg==", + "license": "MIT", + "dependencies": { + "@octokit/auth-token": "^6.0.0", + "@octokit/types": "^16.0.0" + }, + "engines": { + "node": ">= 20" + } + }, "node_modules/@octokit/auth-token": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/@octokit/auth-token/-/auth-token-6.0.0.tgz", @@ -269,6 +310,15 @@ "resolved": "https://registry.npmjs.org/universal-user-agent/-/universal-user-agent-7.0.3.tgz", "integrity": "sha512-TmnEAEAsBJVZM/AADELsK76llnwcf9vMKuPz8JflO1frO8Lchitr0fNaN9d+Ap0BjKtqWqd/J17qeDnXh8CL2A==", "license": "ISC" + }, + "node_modules/zod": { + "version": "4.4.3", + "resolved": "https://registry.npmjs.org/zod/-/zod-4.4.3.tgz", + "integrity": "sha512-ytENFjIJFl2UwYglde2jchW2Hwm4GJFLDiSXWdTrJQBIN9Fcyp7n4DhxJEiWNAJMV1/BqWfW/kkg71UDcHJyTQ==", + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/colinhacks" + } } } } diff --git a/action/package.json b/action/package.json index e76f792..2c5876d 100644 --- a/action/package.json +++ b/action/package.json @@ -12,7 +12,9 @@ "type": "module", "dependencies": { "@actions/core": "^3.0.1", - "@actions/github": "^9.1.1" + "@actions/github": "^9.1.1", + "@octokit/action": "^8.0.4", + "zod": "^4.4.3" }, "devDependencies": { "@types/node": "^26.1.1" From 62541ff37170b3ec2d7f2070102f63b3e7543a86 Mon Sep 17 00:00:00 2001 From: rayan Date: Tue, 21 Jul 2026 02:40:01 +0200 Subject: [PATCH 10/59] fix: det-21 name of execCommand function --- action/src/debtlint.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action/src/debtlint.js b/action/src/debtlint.js index 37a82ed..e2fd4a6 100644 --- a/action/src/debtlint.js +++ b/action/src/debtlint.js @@ -38,7 +38,7 @@ const execCommand = (cmd, args = []) => { }); }; -const rawOutput = await runCommand('cargo', ['run', 'main.rs']); +const rawOutput = await execCommand('cargo', ['run', 'main.rs']); const diagnostic = diagnosticSchema.parse(JSON.parse(rawOutput)); const range = diagnostic.ranges[0]; From 9f7964ff65ee19507f4e292670bf0e27d98eb3ba Mon Sep 17 00:00:00 2001 From: rayan Date: Tue, 21 Jul 2026 02:53:54 +0200 Subject: [PATCH 11/59] fix: det-21 seralise instead of debug in test object --- action/src/debtlint.js | 4 ++-- src/debug_run.rs | 8 ++++++-- src/linter/diagnostic.rs | 10 +++++++--- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/action/src/debtlint.js b/action/src/debtlint.js index e2fd4a6..22db4a5 100644 --- a/action/src/debtlint.js +++ b/action/src/debtlint.js @@ -16,8 +16,8 @@ const octokit = new Octokit(); const execCommand = (cmd, args = []) => { return new Promise((resolve, reject) => { const process = spawn(cmd, args); - let output; - let errorOutput; + let output = "" + let errorOutput = "" process.stdout.on('data', (data) => { output += data.toString(); diff --git a/src/debug_run.rs b/src/debug_run.rs index 38b93b4..777ba71 100644 --- a/src/debug_run.rs +++ b/src/debug_run.rs @@ -4,11 +4,15 @@ use debtlint::tokenizer::{BASE_VOCAB_SIZE, SourceFile, decode_sequence}; use debtlint::linter::{get_duplicated}; use crate::cli::Args; +use serde_json; pub fn run_linter() -> std::io::Result<()> { - println!("{:?}", get_duplicated()); - Ok(()) + let diagnostic = get_duplicated(); + match serde_json::to_string(&diagnostic) { + Ok(data) => { println!("{}", data); Ok(()) }, + Err(err) => { println!("Error: {}", err); Err(std::io::Error::new(std::io::ErrorKind::Other, err)) } + } } #[allow(dead_code)] diff --git a/src/linter/diagnostic.rs b/src/linter/diagnostic.rs index f01b535..2edee5e 100644 --- a/src/linter/diagnostic.rs +++ b/src/linter/diagnostic.rs @@ -1,16 +1,20 @@ -#[derive(Debug)] +use serde::Serialize; + + + +#[derive(Serialize, Debug)] pub struct Position { pub line: u32, pub character: u32 } -#[derive(Debug)] +#[derive(Serialize, Debug)] pub struct Range { pub start: Position, pub end: Position } -#[derive(Debug)] +#[derive(Serialize, Debug)] pub struct Diagnostic { pub source: String, pub severity: String, From 8bbd2ec1fd6fcbd35f12c166a1d2ca1cfd320f28 Mon Sep 17 00:00:00 2001 From: rayan Date: Tue, 21 Jul 2026 02:56:38 +0200 Subject: [PATCH 12/59] refactor: det-21 change trigger event push -> pull_request --- .github/workflows/debtlint.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/debtlint.yml b/.github/workflows/debtlint.yml index bd67bff..107b444 100644 --- a/.github/workflows/debtlint.yml +++ b/.github/workflows/debtlint.yml @@ -1,7 +1,7 @@ name: Check duplication on: - push: + pull_request: jobs: debtlint: From 00e07946a6af75ee26c4eae03c4f5466e4675c77 Mon Sep 17 00:00:00 2001 From: rayan Date: Tue, 21 Jul 2026 03:03:39 +0200 Subject: [PATCH 13/59] refactor: det-21 specify branch --- .github/workflows/debtlint.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/debtlint.yml b/.github/workflows/debtlint.yml index 107b444..9aadf9a 100644 --- a/.github/workflows/debtlint.yml +++ b/.github/workflows/debtlint.yml @@ -1,7 +1,8 @@ name: Check duplication on: - pull_request: + pull_request: + branches: [ "main" ] jobs: debtlint: From 0085c0fa2212c1e879fef5e37b3717466dcb47ad Mon Sep 17 00:00:00 2001 From: rayan Date: Tue, 21 Jul 2026 03:13:14 +0200 Subject: [PATCH 14/59] test: det-21 test to trigger ci on push event* --- .github/workflows/debtlint.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/debtlint.yml b/.github/workflows/debtlint.yml index 9aadf9a..6e39a9d 100644 --- a/.github/workflows/debtlint.yml +++ b/.github/workflows/debtlint.yml @@ -1,8 +1,7 @@ name: Check duplication on: - pull_request: - branches: [ "main" ] + push: jobs: debtlint: From 77af5e55b59e77a436f820beaba8aa593a8843c8 Mon Sep 17 00:00:00 2001 From: rayan Date: Tue, 21 Jul 2026 03:14:04 +0200 Subject: [PATCH 15/59] ci: det-21 trigger ci on pr --- .github/workflows/debtlint.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/debtlint.yml b/.github/workflows/debtlint.yml index 6e39a9d..9aadf9a 100644 --- a/.github/workflows/debtlint.yml +++ b/.github/workflows/debtlint.yml @@ -1,7 +1,8 @@ name: Check duplication on: - push: + pull_request: + branches: [ "main" ] jobs: debtlint: From dac4ac9e7b844678fc22540f7bc8d36ca0982c10 Mon Sep 17 00:00:00 2001 From: rayan Date: Tue, 21 Jul 2026 03:16:20 +0200 Subject: [PATCH 16/59] test: det-21 test to trigger ci --- action/src/debtlint.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action/src/debtlint.js b/action/src/debtlint.js index 22db4a5..95b0888 100644 --- a/action/src/debtlint.js +++ b/action/src/debtlint.js @@ -8,7 +8,7 @@ import { diagnosticSchema } from './schemas.js'; const octokit = new Octokit(); /** - * Execute a command in a child process + * Execute a command in a child process te * @param {string} cmd * @param {string[]} args * @returns {Promise} From 97651f1d939e248d661e4f3c9daadeb3fae0fa3e Mon Sep 17 00:00:00 2001 From: rayan Date: Tue, 21 Jul 2026 03:19:57 +0200 Subject: [PATCH 17/59] ci: det-21 just to test --- .github/workflows/quality.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/quality.yml b/.github/workflows/quality.yml index 60577bf..24e35f7 100644 --- a/.github/workflows/quality.yml +++ b/.github/workflows/quality.yml @@ -2,7 +2,7 @@ name: Quality on: pull_request: - branches: [ "main" ] + branches: [ "test" ] jobs: check_quality: From 72c974dd0564b9848ee01519962e2f750e9d67fe Mon Sep 17 00:00:00 2001 From: rayan Date: Tue, 21 Jul 2026 03:24:54 +0200 Subject: [PATCH 18/59] test(app): det-21 debug run import --- src/main.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index 708cd2b..590ac46 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,12 +1,10 @@ mod cli; mod config; mod ingestion; +mod debug_run; use clap::Parser; use cli::Args; -use config::get_config; -use debtlint::pipeline::{BpeConfig, run_bpe}; -use ingestion::ingest_codebase; fn main() { let _ = Args::parse(); From 1b79c36cac1f0c7a95eb4e77e8b3aa76612aafe9 Mon Sep 17 00:00:00 2001 From: rayan Date: Sat, 25 Jul 2026 18:54:26 +0200 Subject: [PATCH 19/59] refactor: det-21 come back to 9f7964ff65ee commit --- .github/workflows/debtlint.yml | 2 +- action/src/debtlint.js | 41 +++++++++++++++++----------------- 2 files changed, 21 insertions(+), 22 deletions(-) diff --git a/.github/workflows/debtlint.yml b/.github/workflows/debtlint.yml index bd67bff..107b444 100644 --- a/.github/workflows/debtlint.yml +++ b/.github/workflows/debtlint.yml @@ -1,7 +1,7 @@ name: Check duplication on: - push: + pull_request: jobs: debtlint: diff --git a/action/src/debtlint.js b/action/src/debtlint.js index 22db4a5..818bd93 100644 --- a/action/src/debtlint.js +++ b/action/src/debtlint.js @@ -14,28 +14,27 @@ const octokit = new Octokit(); * @returns {Promise} */ const execCommand = (cmd, args = []) => { - return new Promise((resolve, reject) => { - const process = spawn(cmd, args); - let output = "" - let errorOutput = "" - - process.stdout.on('data', (data) => { - output += data.toString(); - }); - - process.stderr.on('data', (data) => { - errorOutput += data.toString(); + return new Promise((resolve, reject) => { + const process = spawn(cmd, args); + let output = "" + let errorOutput = "" + + process.stdout.on('data', (data) => { + output += data.toString(); + }); + + process.stderr.on('data', (data) => { + errorOutput += data.toString(); + }); + + process.on('close', (code) => { + if (code !== 0) { + return reject(new Error(`Process exited with code ${code}: ${errorOutput}`)); + } + resolve(output); + }); + process.on('error', reject); }); - - process.on('close', (code) => { - if (code !== 0) { - return reject(new Error(`Process exited with code ${code}: ${errorOutput}`)); - } - resolve(output); - }); - - process.on('error', reject); - }); }; const rawOutput = await execCommand('cargo', ['run', 'main.rs']); From 504476b47c0bc091d844bbf640e9aa50486ec54d Mon Sep 17 00:00:00 2001 From: rayan Date: Sat, 25 Jul 2026 18:56:49 +0200 Subject: [PATCH 20/59] ci(app): det-21 put back main branch in ci --- .github/workflows/quality.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/quality.yml b/.github/workflows/quality.yml index 24e35f7..60577bf 100644 --- a/.github/workflows/quality.yml +++ b/.github/workflows/quality.yml @@ -2,7 +2,7 @@ name: Quality on: pull_request: - branches: [ "test" ] + branches: [ "main" ] jobs: check_quality: From 453de6cbcc21d77b8e535bd971fd06196a5d119e Mon Sep 17 00:00:00 2001 From: rayan Date: Mon, 27 Jul 2026 00:04:17 +0200 Subject: [PATCH 21/59] ci: det-21 add function run --- action/index.js | 4 ++- action/src/api.js | 37 ++++++++++++++++++++++++ action/src/debtlint.js | 64 ++++++++---------------------------------- action/src/executor.js | 33 ++++++++++++++++++++++ action/src/schemas.js | 9 ++++++ 5 files changed, 94 insertions(+), 53 deletions(-) create mode 100644 action/src/api.js create mode 100644 action/src/executor.js diff --git a/action/index.js b/action/index.js index ebb2c48..8e6ca19 100644 --- a/action/index.js +++ b/action/index.js @@ -1 +1,3 @@ -import './src/debtlint.js'; \ No newline at end of file +import { run } from './src/debtlint.js'; + +run() \ No newline at end of file diff --git a/action/src/api.js b/action/src/api.js new file mode 100644 index 0000000..364bc11 --- /dev/null +++ b/action/src/api.js @@ -0,0 +1,37 @@ +import { spawn } from 'child_process'; +import { Octokit } from '@octokit/action'; + +import { diagnosticSchema } from './schemas.js'; + + + +/** + * Create a comment on a pull request + * @param { Octokit } octokit + * @param { Diagnostic } diagnostic + * @param { Object } context + */ +export async function createComment(octokit, diagnostic, context) +{ + await octokit.issues.createComment({ + ...context.repo, + issue_number: context.pull_request.number, + body: "Comment created." + }) +} + +//await octokit.request('POST /repos/{owner}/{repo}/pulls/{pull_number}/comments', { +// owner: github.context.repo.owner, +// repo: github.context.repo.repo, +// pull_number: github.context.payload.pull_request.number, +// body: diagnostic.code_description, +// commit_id: github.context.payload.pull_request.head.sha, +// path: diagnostic.source, +// start_line: range.start.line, +// start_side: 'RIGHT', +// line: range.end.line, +// side: 'RIGHT', +// headers: { +// 'X-GitHub-Api-Version': '2026-03-10', +// }, +//}); \ No newline at end of file diff --git a/action/src/debtlint.js b/action/src/debtlint.js index 8be06fa..a758825 100644 --- a/action/src/debtlint.js +++ b/action/src/debtlint.js @@ -1,59 +1,19 @@ import * as core from '@actions/core'; import * as github from '@actions/github'; import { Octokit } from '@octokit/action'; -import { spawn } from 'child_process'; -import { diagnosticSchema } from './schemas.js'; +import { execCommand } from "./executor.js" +import { createComment } from "./api.js"; -const octokit = new Octokit(); -/** - * Execute a command in a child process te - * @param {string} cmd - * @param {string[]} args - * @returns {Promise} - */ -const execCommand = (cmd, args = []) => { - return new Promise((resolve, reject) => { - const process = spawn(cmd, args); - let output = "" - let errorOutput = "" - - process.stdout.on('data', (data) => { - output += data.toString(); - }); +async function run() { + const GITHUB_TOKEN = core.getInput('GITHUB_TOKEN'); + const octokit = github.getOctokit(GITHUB_TOKEN); + const { context = {} } = github; + const { pull_request } = context.payload; - process.stderr.on('data', (data) => { - errorOutput += data.toString(); - }); - - process.on('close', (code) => { - if (code !== 0) { - return reject(new Error(`Process exited with code ${code}: ${errorOutput}`)); - } - resolve(output); - }); - process.on('error', reject); - }); -}; - -const rawOutput = await execCommand('cargo', ['run', 'main.rs']); -const diagnostic = diagnosticSchema.parse(JSON.parse(rawOutput)); - -const range = diagnostic.ranges[0]; - -await octokit.request('POST /repos/{owner}/{repo}/pulls/{pull_number}/comments', { - owner: github.context.repo.owner, - repo: github.context.repo.repo, - pull_number: github.context.payload.pull_request.number, - body: diagnostic.code_description, - commit_id: github.context.payload.pull_request.head.sha, - path: diagnostic.source, - start_line: range.start.line, - start_side: 'RIGHT', - line: range.end.line, - side: 'RIGHT', - headers: { - 'X-GitHub-Api-Version': '2026-03-10', - }, -}); \ No newline at end of file + const rawOutput = await execCommand('cargo', ['run', 'main.rs']); + console.log(rawOutput) + const diagnostic = diagnosticSchema.parse(JSON.parse(rawOutput)); + await createComment(octokit, diagnostic, context) +} diff --git a/action/src/executor.js b/action/src/executor.js new file mode 100644 index 0000000..7e21a71 --- /dev/null +++ b/action/src/executor.js @@ -0,0 +1,33 @@ +import { spawn } from 'child_process'; + +import { diagnosticSchema } from './schemas.js'; + +/** + * Execute a command in a child process + * @param {string} cmd + * @param {string[]} args + * @returns {Promise} + */ +const execCommand = (cmd, args = []) => { + return new Promise((resolve, reject) => { + const process = spawn(cmd, args); + let output = "" + let errorOutput = "" + + process.stdout.on('data', (data) => { + output += data.toString(); + }); + + process.stderr.on('data', (data) => { + errorOutput += data.toString(); + }); + + process.on('close', (code) => { + if (code !== 0) { + return reject(new Error(`Process exited with code ${code}: ${errorOutput}`)); + } + resolve(output); + }); + process.on('error', reject); + }); +}; diff --git a/action/src/schemas.js b/action/src/schemas.js index af12006..b8102a0 100644 --- a/action/src/schemas.js +++ b/action/src/schemas.js @@ -1,15 +1,24 @@ import { z } from "zod"; +/** +* @typedef {z.infer} Position +*/ const positionSchema = z.object({ line: z.number().min(0), character: z.number().min(0), }); +/** +* @typedef {z.infer} Range +*/ const rangeSchema = z.object({ start: positionSchema, end: positionSchema, }); +/** +* @typedef {z.infer} Diagnostic +*/ export const diagnosticSchema = z.object({ source: z.string(), severity: z.string(), From 8cc94f07782fd00e1c5ad9548c8e7bb29f98b145 Mon Sep 17 00:00:00 2001 From: rayan Date: Mon, 27 Jul 2026 00:06:30 +0200 Subject: [PATCH 22/59] refactor: det-21 export execCommand --- action/src/executor.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action/src/executor.js b/action/src/executor.js index 7e21a71..288aa56 100644 --- a/action/src/executor.js +++ b/action/src/executor.js @@ -8,7 +8,7 @@ import { diagnosticSchema } from './schemas.js'; * @param {string[]} args * @returns {Promise} */ -const execCommand = (cmd, args = []) => { +export const execCommand = (cmd, args = []) => { return new Promise((resolve, reject) => { const process = spawn(cmd, args); let output = "" From 8f8cde1f6ea1c81dc82c89614c226e6df3d2efd4 Mon Sep 17 00:00:00 2001 From: rayan Date: Mon, 27 Jul 2026 00:13:44 +0200 Subject: [PATCH 23/59] ci: det-21 delete debtlint and move logic in index.js --- action/index.js | 20 ++++++++++++++++++-- action/src/debtlint.js | 19 ------------------- 2 files changed, 18 insertions(+), 21 deletions(-) delete mode 100644 action/src/debtlint.js diff --git a/action/index.js b/action/index.js index 8e6ca19..1e1872b 100644 --- a/action/index.js +++ b/action/index.js @@ -1,3 +1,19 @@ -import { run } from './src/debtlint.js'; +import * as core from '@actions/core'; +import * as github from '@actions/github'; +import { Octokit } from '@octokit/action'; -run() \ No newline at end of file +import { execCommand } from "./src/executor.js" +import { createComment } from "./src/api.js"; + +async function run() { + const GITHUB_TOKEN = core.getInput('GITHUB_TOKEN'); + const octokit = github.getOctokit(GITHUB_TOKEN); + const { context = {} } = github; + + const rawOutput = await execCommand('cargo', ['run', 'main.rs']); + console.log(rawOutput) + const diagnostic = diagnosticSchema.parse(JSON.parse(rawOutput)); + await createComment(octokit, diagnostic, context) +} + +run().catch(console.error); \ No newline at end of file diff --git a/action/src/debtlint.js b/action/src/debtlint.js deleted file mode 100644 index a758825..0000000 --- a/action/src/debtlint.js +++ /dev/null @@ -1,19 +0,0 @@ -import * as core from '@actions/core'; -import * as github from '@actions/github'; -import { Octokit } from '@octokit/action'; - -import { execCommand } from "./executor.js" -import { createComment } from "./api.js"; - - -async function run() { - const GITHUB_TOKEN = core.getInput('GITHUB_TOKEN'); - const octokit = github.getOctokit(GITHUB_TOKEN); - const { context = {} } = github; - const { pull_request } = context.payload; - - const rawOutput = await execCommand('cargo', ['run', 'main.rs']); - console.log(rawOutput) - const diagnostic = diagnosticSchema.parse(JSON.parse(rawOutput)); - await createComment(octokit, diagnostic, context) -} From cdc9448ae9bef58713782d6fd306793a7ba17858 Mon Sep 17 00:00:00 2001 From: rayan Date: Mon, 27 Jul 2026 00:15:36 +0200 Subject: [PATCH 24/59] refactor: det-21 remove catch to see erros --- action/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action/index.js b/action/index.js index 1e1872b..b8fea35 100644 --- a/action/index.js +++ b/action/index.js @@ -16,4 +16,4 @@ async function run() { await createComment(octokit, diagnostic, context) } -run().catch(console.error); \ No newline at end of file +run() \ No newline at end of file From 762876b3620a234978c5cda84b1ade69dc852aee Mon Sep 17 00:00:00 2001 From: rayan Date: Mon, 27 Jul 2026 00:27:34 +0200 Subject: [PATCH 25/59] refactor: det-21 get github tokens from env --- action/action.yml | 1 + action/index.js | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/action/action.yml b/action/action.yml index db6b0d5..e4d8c67 100644 --- a/action/action.yml +++ b/action/action.yml @@ -7,6 +7,7 @@ branding: inputs: files: + description: "File passed to the program." required: false runs: diff --git a/action/index.js b/action/index.js index b8fea35..82a6dee 100644 --- a/action/index.js +++ b/action/index.js @@ -6,7 +6,7 @@ import { execCommand } from "./src/executor.js" import { createComment } from "./src/api.js"; async function run() { - const GITHUB_TOKEN = core.getInput('GITHUB_TOKEN'); + const GITHUB_TOKEN = process.env.GITHUB_TOKEN; const octokit = github.getOctokit(GITHUB_TOKEN); const { context = {} } = github; From 36e8a1f58e0912b804af53d79dfc0c59ca29759e Mon Sep 17 00:00:00 2001 From: rayan Date: Mon, 27 Jul 2026 00:33:48 +0200 Subject: [PATCH 26/59] fix: det-21 add forgotten import --- action/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/action/index.js b/action/index.js index 82a6dee..627ac38 100644 --- a/action/index.js +++ b/action/index.js @@ -4,6 +4,7 @@ import { Octokit } from '@octokit/action'; import { execCommand } from "./src/executor.js" import { createComment } from "./src/api.js"; +import { diagnosticSchema } from './src/schemas.js'; async function run() { const GITHUB_TOKEN = process.env.GITHUB_TOKEN; From fd253fe5d1a8a2d834c38d65f9d56a5fa8708f61 Mon Sep 17 00:00:00 2001 From: rayan Date: Mon, 27 Jul 2026 01:10:23 +0200 Subject: [PATCH 27/59] =?UTF-8?q?refactor:=20det-21=20use=20octokit=20requ?= =?UTF-8?q?est=20directly=C3=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- action/src/api.js | 33 ++++++++++++--------------------- 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/action/src/api.js b/action/src/api.js index 364bc11..95e9222 100644 --- a/action/src/api.js +++ b/action/src/api.js @@ -13,25 +13,16 @@ import { diagnosticSchema } from './schemas.js'; */ export async function createComment(octokit, diagnostic, context) { - await octokit.issues.createComment({ - ...context.repo, - issue_number: context.pull_request.number, - body: "Comment created." + await octokit.request('POST /repos/{owner}/{repo}/pulls/{pull_number}/comments', { + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: context.payload.pull_request.number, + body: diagnostic.code_description, + commit_id: context.payload.pull_request.head.sha, + path: diagnostic.source, + start_line: range.start.line, + start_side: 'RIGHT', + line: range.end.line, + side: 'RIGHT', }) -} - -//await octokit.request('POST /repos/{owner}/{repo}/pulls/{pull_number}/comments', { -// owner: github.context.repo.owner, -// repo: github.context.repo.repo, -// pull_number: github.context.payload.pull_request.number, -// body: diagnostic.code_description, -// commit_id: github.context.payload.pull_request.head.sha, -// path: diagnostic.source, -// start_line: range.start.line, -// start_side: 'RIGHT', -// line: range.end.line, -// side: 'RIGHT', -// headers: { -// 'X-GitHub-Api-Version': '2026-03-10', -// }, -//}); \ No newline at end of file +} \ No newline at end of file From 6f967b4f254f18ee652765909e69c7b8d793260f Mon Sep 17 00:00:00 2001 From: rayan Date: Mon, 27 Jul 2026 01:18:56 +0200 Subject: [PATCH 28/59] refactor: det-21 test for loop in js --- action/src/api.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/action/src/api.js b/action/src/api.js index 95e9222..6637c3d 100644 --- a/action/src/api.js +++ b/action/src/api.js @@ -13,6 +13,9 @@ import { diagnosticSchema } from './schemas.js'; */ export async function createComment(octokit, diagnostic, context) { + for (const range of diagnostic.ranges) { + console.log(range.start.line); + } await octokit.request('POST /repos/{owner}/{repo}/pulls/{pull_number}/comments', { owner: context.repo.owner, repo: context.repo.repo, From c816c65ea44b0b11a2d6ddcab2f70c03006d4a1b Mon Sep 17 00:00:00 2001 From: rayan Date: Mon, 27 Jul 2026 01:20:55 +0200 Subject: [PATCH 29/59] feat: det-21 post for every element in the rang loop --- action/src/api.js | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/action/src/api.js b/action/src/api.js index 6637c3d..9cb187b 100644 --- a/action/src/api.js +++ b/action/src/api.js @@ -14,18 +14,17 @@ import { diagnosticSchema } from './schemas.js'; export async function createComment(octokit, diagnostic, context) { for (const range of diagnostic.ranges) { - console.log(range.start.line); + await octokit.request('POST /repos/{owner}/{repo}/pulls/{pull_number}/comments', { + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: context.payload.pull_request.number, + body: diagnostic.code_description, + commit_id: context.payload.pull_request.head.sha, + path: diagnostic.source, + start_line: range.start.line, + start_side: 'RIGHT', + line: range.end.line, + side: 'RIGHT', + }) } - await octokit.request('POST /repos/{owner}/{repo}/pulls/{pull_number}/comments', { - owner: context.repo.owner, - repo: context.repo.repo, - pull_number: context.payload.pull_request.number, - body: diagnostic.code_description, - commit_id: context.payload.pull_request.head.sha, - path: diagnostic.source, - start_line: range.start.line, - start_side: 'RIGHT', - line: range.end.line, - side: 'RIGHT', - }) } \ No newline at end of file From 6854720a4a6cce62dd98e01294796ad4e863cda0 Mon Sep 17 00:00:00 2001 From: rayan Date: Mon, 27 Jul 2026 01:25:29 +0200 Subject: [PATCH 30/59] fix: det-21 specify header in post request --- action/src/api.js | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/action/src/api.js b/action/src/api.js index 9cb187b..73287f2 100644 --- a/action/src/api.js +++ b/action/src/api.js @@ -15,16 +15,17 @@ export async function createComment(octokit, diagnostic, context) { for (const range of diagnostic.ranges) { await octokit.request('POST /repos/{owner}/{repo}/pulls/{pull_number}/comments', { - owner: context.repo.owner, - repo: context.repo.repo, - pull_number: context.payload.pull_request.number, - body: diagnostic.code_description, - commit_id: context.payload.pull_request.head.sha, - path: diagnostic.source, - start_line: range.start.line, - start_side: 'RIGHT', - line: range.end.line, - side: 'RIGHT', + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: context.payload.pull_request.number, + body: diagnostic.code_description, + commit_id: context.payload.pull_request.head.sha, + path: diagnostic.source, + start_line: range.start.line, + start_side: 'RIGHT', + line: range.end.line, + side: 'RIGHT', + headers: { 'X-GitHub-Api-Version': '2026-03-10'} }) } } \ No newline at end of file From 5038e671215d92879fff2ac83cdf2b817c9b3d6b Mon Sep 17 00:00:00 2001 From: rayan Date: Mon, 27 Jul 2026 01:28:47 +0200 Subject: [PATCH 31/59] fix: det-21 remove optional on codeDescritption --- action/index.js | 2 +- action/src/schemas.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/action/index.js b/action/index.js index 627ac38..33afb79 100644 --- a/action/index.js +++ b/action/index.js @@ -10,8 +10,8 @@ async function run() { const GITHUB_TOKEN = process.env.GITHUB_TOKEN; const octokit = github.getOctokit(GITHUB_TOKEN); const { context = {} } = github; - const rawOutput = await execCommand('cargo', ['run', 'main.rs']); + console.log(rawOutput) const diagnostic = diagnosticSchema.parse(JSON.parse(rawOutput)); await createComment(octokit, diagnostic, context) diff --git a/action/src/schemas.js b/action/src/schemas.js index b8102a0..8334cdf 100644 --- a/action/src/schemas.js +++ b/action/src/schemas.js @@ -24,5 +24,5 @@ export const diagnosticSchema = z.object({ severity: z.string(), code: z.number().min(0) , ranges: z.array(rangeSchema), - codeDescription: z.string().optional(), + codeDescription: z.string(), }) From 1696c15632719af53716367f789592d201533da6 Mon Sep 17 00:00:00 2001 From: rayan Date: Mon, 27 Jul 2026 01:31:40 +0200 Subject: [PATCH 32/59] refactor: det-21 rename code descripton to match with struct rust --- action/src/schemas.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action/src/schemas.js b/action/src/schemas.js index 8334cdf..b2c2d4d 100644 --- a/action/src/schemas.js +++ b/action/src/schemas.js @@ -24,5 +24,5 @@ export const diagnosticSchema = z.object({ severity: z.string(), code: z.number().min(0) , ranges: z.array(rangeSchema), - codeDescription: z.string(), + code_description: z.string(), }) From ea22ebef3177511a634d9116b4b3fa89ef125485 Mon Sep 17 00:00:00 2001 From: rayan Date: Mon, 27 Jul 2026 02:00:18 +0200 Subject: [PATCH 33/59] refactor: det-21 create comment for each range of code --- action/src/api.js | 2 +- action/src/schemas.js | 2 +- src/linter/diagnostic.rs | 2 +- src/linter/linter.rs | 19 ++++++++++++------- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/action/src/api.js b/action/src/api.js index 73287f2..4ad2fa2 100644 --- a/action/src/api.js +++ b/action/src/api.js @@ -20,7 +20,7 @@ export async function createComment(octokit, diagnostic, context) pull_number: context.payload.pull_request.number, body: diagnostic.code_description, commit_id: context.payload.pull_request.head.sha, - path: diagnostic.source, + path: range.start.source, start_line: range.start.line, start_side: 'RIGHT', line: range.end.line, diff --git a/action/src/schemas.js b/action/src/schemas.js index b2c2d4d..1d188d1 100644 --- a/action/src/schemas.js +++ b/action/src/schemas.js @@ -4,6 +4,7 @@ import { z } from "zod"; * @typedef {z.infer} Position */ const positionSchema = z.object({ + source: z.string(), line: z.number().min(0), character: z.number().min(0), }); @@ -20,7 +21,6 @@ const rangeSchema = z.object({ * @typedef {z.infer} Diagnostic */ export const diagnosticSchema = z.object({ - source: z.string(), severity: z.string(), code: z.number().min(0) , ranges: z.array(rangeSchema), diff --git a/src/linter/diagnostic.rs b/src/linter/diagnostic.rs index 2edee5e..0879a09 100644 --- a/src/linter/diagnostic.rs +++ b/src/linter/diagnostic.rs @@ -4,6 +4,7 @@ use serde::Serialize; #[derive(Serialize, Debug)] pub struct Position { + pub source: String, pub line: u32, pub character: u32 } @@ -16,7 +17,6 @@ pub struct Range { #[derive(Serialize, Debug)] pub struct Diagnostic { - pub source: String, pub severity: String, pub code: u16, pub ranges: Vec, diff --git a/src/linter/linter.rs b/src/linter/linter.rs index 677a1aa..e3d6f04 100644 --- a/src/linter/linter.rs +++ b/src/linter/linter.rs @@ -2,13 +2,18 @@ use super::diagnostic::{Diagnostic, Range, Position}; pub fn get_duplicated() -> Diagnostic { Diagnostic { - source: String::from("src/main.rs"), severity: String::from("low"), code: 1, - ranges: vec![Range { - start: Position { line: 8, character: 8 }, - end: Position { line: 8, character: 12 }, - }], - code_description: String::from("No typing"), + ranges: vec![ + Range { + start: Position { source: "src/ingestion.rs".to_string(), line: 10, character: 1 }, + end: Position { source: "src/ingestion.rs".to_string(), line: 26, character: 1 }, + }, + Range { + start: Position { source: "src/pipeline.rs".to_string(), line: 12, character: 1 }, + end: Position { source: "src/pipeline.rs".to_string(), line: 23, character: 1 } + } + ], + code_description: String::from("Duplicate"), } -} \ No newline at end of file +} From f6c54b4cbaa67f50dfe616099167a466184e1943 Mon Sep 17 00:00:00 2001 From: rayan Date: Mon, 27 Jul 2026 02:05:33 +0200 Subject: [PATCH 34/59] refactor: det-21 put code abode severity --- action/src/schemas.js | 2 +- src/linter/linter.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/action/src/schemas.js b/action/src/schemas.js index 1d188d1..a225165 100644 --- a/action/src/schemas.js +++ b/action/src/schemas.js @@ -21,8 +21,8 @@ const rangeSchema = z.object({ * @typedef {z.infer} Diagnostic */ export const diagnosticSchema = z.object({ - severity: z.string(), code: z.number().min(0) , + severity: z.string(), ranges: z.array(rangeSchema), code_description: z.string(), }) diff --git a/src/linter/linter.rs b/src/linter/linter.rs index e3d6f04..3c5876b 100644 --- a/src/linter/linter.rs +++ b/src/linter/linter.rs @@ -2,8 +2,8 @@ use super::diagnostic::{Diagnostic, Range, Position}; pub fn get_duplicated() -> Diagnostic { Diagnostic { - severity: String::from("low"), code: 1, + severity: String::from("low"), ranges: vec![ Range { start: Position { source: "src/ingestion.rs".to_string(), line: 10, character: 1 }, From 4906cf403ea92dc9c8450f93ce0efbda68e28cb4 Mon Sep 17 00:00:00 2001 From: rayan Date: Mon, 27 Jul 2026 02:14:57 +0200 Subject: [PATCH 35/59] test: det-21 try with a file in the git diff --- src/linter/linter.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/linter/linter.rs b/src/linter/linter.rs index 3c5876b..bfe838a 100644 --- a/src/linter/linter.rs +++ b/src/linter/linter.rs @@ -6,12 +6,12 @@ pub fn get_duplicated() -> Diagnostic { severity: String::from("low"), ranges: vec![ Range { - start: Position { source: "src/ingestion.rs".to_string(), line: 10, character: 1 }, - end: Position { source: "src/ingestion.rs".to_string(), line: 26, character: 1 }, + start: Position { source: "src/linter/linter.rs".to_string(), line: 10, character: 1 }, + end: Position { source: "src/linter/linter.rs".to_string(), line: 19, character: 1 }, }, Range { - start: Position { source: "src/pipeline.rs".to_string(), line: 12, character: 1 }, - end: Position { source: "src/pipeline.rs".to_string(), line: 23, character: 1 } + start: Position { source: "src/debug_run.rs".to_string(), line: 10, character: 1 }, + end: Position { source: "src/debug_run.rs".to_string(), line: 16, character: 1 } } ], code_description: String::from("Duplicate"), From c2a5538f9ff25e912a53a75bfeedd1b90cea9529 Mon Sep 17 00:00:00 2001 From: rayan Date: Mon, 3 Aug 2026 15:29:19 +0200 Subject: [PATCH 36/59] refactor: det-21 format code with rustfmt --- src/debug_run.rs | 13 +++++++++---- src/lib.rs | 2 +- src/linter/diagnostic.rs | 10 ++++------ src/linter/linter.rs | 28 ++++++++++++++++++++++------ src/linter/mod.rs | 4 ++-- src/main.rs | 2 +- 6 files changed, 39 insertions(+), 20 deletions(-) diff --git a/src/debug_run.rs b/src/debug_run.rs index 777ba71..7cb984a 100644 --- a/src/debug_run.rs +++ b/src/debug_run.rs @@ -1,17 +1,22 @@ use debtlint::in_out::{read_corpus, save_vocabulary, write_encoded_sequence_json}; +use debtlint::linter::get_duplicated; use debtlint::pipeline::{BpeConfig, run_bpe}; use debtlint::tokenizer::{BASE_VOCAB_SIZE, SourceFile, decode_sequence}; -use debtlint::linter::{get_duplicated}; use crate::cli::Args; use serde_json; - pub fn run_linter() -> std::io::Result<()> { let diagnostic = get_duplicated(); match serde_json::to_string(&diagnostic) { - Ok(data) => { println!("{}", data); Ok(()) }, - Err(err) => { println!("Error: {}", err); Err(std::io::Error::new(std::io::ErrorKind::Other, err)) } + Ok(data) => { + println!("{}", data); + Ok(()) + } + Err(err) => { + println!("Error: {}", err); + Err(std::io::Error::new(std::io::ErrorKind::Other, err)) + } } } diff --git a/src/lib.rs b/src/lib.rs index 584e63b..b5ecc03 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,4 @@ pub mod in_out; +pub mod linter; pub mod pipeline; pub mod tokenizer; -pub mod linter; \ No newline at end of file diff --git a/src/linter/diagnostic.rs b/src/linter/diagnostic.rs index 0879a09..2a19a8e 100644 --- a/src/linter/diagnostic.rs +++ b/src/linter/diagnostic.rs @@ -1,18 +1,16 @@ use serde::Serialize; - - #[derive(Serialize, Debug)] pub struct Position { pub source: String, pub line: u32, - pub character: u32 + pub character: u32, } #[derive(Serialize, Debug)] pub struct Range { pub start: Position, - pub end: Position + pub end: Position, } #[derive(Serialize, Debug)] @@ -20,5 +18,5 @@ pub struct Diagnostic { pub severity: String, pub code: u16, pub ranges: Vec, - pub code_description: String -} \ No newline at end of file + pub code_description: String, +} diff --git a/src/linter/linter.rs b/src/linter/linter.rs index bfe838a..4931a61 100644 --- a/src/linter/linter.rs +++ b/src/linter/linter.rs @@ -1,4 +1,4 @@ -use super::diagnostic::{Diagnostic, Range, Position}; +use super::diagnostic::{Diagnostic, Position, Range}; pub fn get_duplicated() -> Diagnostic { Diagnostic { @@ -6,13 +6,29 @@ pub fn get_duplicated() -> Diagnostic { severity: String::from("low"), ranges: vec![ Range { - start: Position { source: "src/linter/linter.rs".to_string(), line: 10, character: 1 }, - end: Position { source: "src/linter/linter.rs".to_string(), line: 19, character: 1 }, + start: Position { + source: "src/linter/linter.rs".to_string(), + line: 10, + character: 1, + }, + end: Position { + source: "src/linter/linter.rs".to_string(), + line: 19, + character: 1, + }, }, Range { - start: Position { source: "src/debug_run.rs".to_string(), line: 10, character: 1 }, - end: Position { source: "src/debug_run.rs".to_string(), line: 16, character: 1 } - } + start: Position { + source: "src/debug_run.rs".to_string(), + line: 10, + character: 1, + }, + end: Position { + source: "src/debug_run.rs".to_string(), + line: 16, + character: 1, + }, + }, ], code_description: String::from("Duplicate"), } diff --git a/src/linter/mod.rs b/src/linter/mod.rs index 68415a0..1d92150 100644 --- a/src/linter/mod.rs +++ b/src/linter/mod.rs @@ -1,5 +1,5 @@ mod diagnostic; mod linter; -pub use diagnostic::{Diagnostic}; -pub use linter::get_duplicated; \ No newline at end of file +pub use diagnostic::Diagnostic; +pub use linter::get_duplicated; diff --git a/src/main.rs b/src/main.rs index 590ac46..432dda7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,7 @@ mod cli; mod config; -mod ingestion; mod debug_run; +mod ingestion; use clap::Parser; use cli::Args; From be1394b58c1b1f11b73e74b64d397d2e792beb09 Mon Sep 17 00:00:00 2001 From: rayan Date: Mon, 3 Aug 2026 15:55:58 +0200 Subject: [PATCH 37/59] refactor: det-21 rename linter mod, and format with clippy --- debtlint.config.json | 4 ++++ src/debug_run.rs | 17 ----------------- src/linter/mod.rs | 4 ++-- src/linter/{linter.rs => runner.rs} | 14 ++++++++++++++ src/main.rs | 26 +++++++++++++++++++------- 5 files changed, 39 insertions(+), 26 deletions(-) create mode 100644 debtlint.config.json rename src/linter/{linter.rs => runner.rs} (75%) diff --git a/debtlint.config.json b/debtlint.config.json new file mode 100644 index 0000000..09b046a --- /dev/null +++ b/debtlint.config.json @@ -0,0 +1,4 @@ +{ + "src": ".", + "excludes": ["action", "target", "doc"] +} \ No newline at end of file diff --git a/src/debug_run.rs b/src/debug_run.rs index 7cb984a..e81553a 100644 --- a/src/debug_run.rs +++ b/src/debug_run.rs @@ -6,21 +6,6 @@ use debtlint::tokenizer::{BASE_VOCAB_SIZE, SourceFile, decode_sequence}; use crate::cli::Args; use serde_json; -pub fn run_linter() -> std::io::Result<()> { - let diagnostic = get_duplicated(); - match serde_json::to_string(&diagnostic) { - Ok(data) => { - println!("{}", data); - Ok(()) - } - Err(err) => { - println!("Error: {}", err); - Err(std::io::Error::new(std::io::ErrorKind::Other, err)) - } - } -} - -#[allow(dead_code)] pub fn run(args: &Args) -> std::io::Result<()> { let content = read_corpus(&args.file)?; let files = vec![SourceFile { @@ -47,7 +32,6 @@ pub fn run(args: &Args) -> std::io::Result<()> { Ok(()) } -#[allow(dead_code)] fn print_stats(result: &debtlint::tokenizer::BpeTrainingResult, content: &str, args: &Args) { let initial_tokens = result.initial_token_count; let encoded_tokens = result.encoded_token_count(); @@ -77,7 +61,6 @@ fn print_stats(result: &debtlint::tokenizer::BpeTrainingResult, content: &str, a ); } -#[allow(dead_code)] fn verify_decode_roundtrip( args: &Args, files: &[SourceFile], diff --git a/src/linter/mod.rs b/src/linter/mod.rs index 1d92150..253cdac 100644 --- a/src/linter/mod.rs +++ b/src/linter/mod.rs @@ -1,5 +1,5 @@ mod diagnostic; -mod linter; +mod runner; pub use diagnostic::Diagnostic; -pub use linter::get_duplicated; +pub use runner::run_linter; diff --git a/src/linter/linter.rs b/src/linter/runner.rs similarity index 75% rename from src/linter/linter.rs rename to src/linter/runner.rs index 4931a61..fc5674f 100644 --- a/src/linter/linter.rs +++ b/src/linter/runner.rs @@ -33,3 +33,17 @@ pub fn get_duplicated() -> Diagnostic { code_description: String::from("Duplicate"), } } + +pub fn run_linter() -> std::io::Result<()> { + let diagnostic = get_duplicated(); + match serde_json::to_string(&diagnostic) { + Ok(data) => { + println!("{}", data); + Ok(()) + } + Err(err) => { + println!("Error: {}", err); + Err(std::io::Error::other(err)) + } + } +} diff --git a/src/main.rs b/src/main.rs index 432dda7..142e47b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,15 +1,27 @@ mod cli; mod config; -mod debug_run; mod ingestion; use clap::Parser; use cli::Args; +use config::get_config; +use debtlint::linter::run_linter; +use debtlint::pipeline::{BpeConfig, run_bpe}; +use ingestion::ingest_codebase; -fn main() { - let _ = Args::parse(); - if let Err(err) = debug_run::run_linter() { - eprintln!("{err}"); - std::process::exit(1); - } +fn main() -> std::io::Result<()> { + let args = Args::parse(); + let cfg = get_config(); + let files = ingest_codebase(cfg); + + let _result = run_bpe( + &files, + BpeConfig { + vocab_size: args.vocab_size, + min_frequency: args.min_frequency, + }, + args.load_vocab.as_deref(), + )?; + let _ = run_linter(); + Ok(()) } From aad8ef15736777af7f934cc1ce57dcfffb1252a2 Mon Sep 17 00:00:00 2001 From: rayan Date: Tue, 4 Aug 2026 00:43:17 +0200 Subject: [PATCH 38/59] fix: det-21 fix test path --- src/linter/runner.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/linter/runner.rs b/src/linter/runner.rs index fc5674f..6e8c72f 100644 --- a/src/linter/runner.rs +++ b/src/linter/runner.rs @@ -7,12 +7,12 @@ pub fn get_duplicated() -> Diagnostic { ranges: vec![ Range { start: Position { - source: "src/linter/linter.rs".to_string(), + source: "src/linter/runner.rs".to_string(), line: 10, character: 1, }, end: Position { - source: "src/linter/linter.rs".to_string(), + source: "src/linter/runner.rs".to_string(), line: 19, character: 1, }, From 8b4ef035f431a62ba6bd03f3ac7e5b2b4de49ba6 Mon Sep 17 00:00:00 2001 From: rayan Date: Tue, 4 Aug 2026 00:59:25 +0200 Subject: [PATCH 39/59] refactor: det-21 try to create an issue comment to avoid git diff problem --- action/src/api.js | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/action/src/api.js b/action/src/api.js index 4ad2fa2..16faafd 100644 --- a/action/src/api.js +++ b/action/src/api.js @@ -14,17 +14,11 @@ import { diagnosticSchema } from './schemas.js'; export async function createComment(octokit, diagnostic, context) { for (const range of diagnostic.ranges) { - await octokit.request('POST /repos/{owner}/{repo}/pulls/{pull_number}/comments', { + await octokit.request('POST /repos/{owner}/{repo}/issues/{issue_number}/comments', { owner: context.repo.owner, repo: context.repo.repo, - pull_number: context.payload.pull_request.number, + issue_number: context.payload.pull_request.number, body: diagnostic.code_description, - commit_id: context.payload.pull_request.head.sha, - path: range.start.source, - start_line: range.start.line, - start_side: 'RIGHT', - line: range.end.line, - side: 'RIGHT', headers: { 'X-GitHub-Api-Version': '2026-03-10'} }) } From c0dd1d2b9cb48a7241e129616d1b9bcc622fcfdd Mon Sep 17 00:00:00 2001 From: rayan Date: Tue, 4 Aug 2026 01:36:54 +0200 Subject: [PATCH 40/59] refactor: det-21 try to add markdown code to comment --- action/src/api.js | 15 ++++++++++++++- action/src/converter.js | 0 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 action/src/converter.js diff --git a/action/src/api.js b/action/src/api.js index 16faafd..202b4ce 100644 --- a/action/src/api.js +++ b/action/src/api.js @@ -13,12 +13,25 @@ import { diagnosticSchema } from './schemas.js'; */ export async function createComment(octokit, diagnostic, context) { + let str = + " " + + " ### clang-format suggestion " + + " ```suggestion " + + " raylib::Vector3 alignToWorldPlane(raylib::Vector3 vector) const; " + + " ``` " + " ### clang-tidy diagnostics " + + " - function 'alignToWorldPlane' should be marked [[nodiscard]] [[modernize-use-nodiscard](https://clang.llvm.org/extra/clang-tidy/checks/modernize/use-nodiscard.html)]" + + " ```suggestion " + + " [[nodiscard]] raylib::Vector3 alignToWorldPlane( " + + " raylib::Vector3 vector) const; " + + " ``` " + for (const range of diagnostic.ranges) { await octokit.request('POST /repos/{owner}/{repo}/issues/{issue_number}/comments', { owner: context.repo.owner, repo: context.repo.repo, issue_number: context.payload.pull_request.number, - body: diagnostic.code_description, + body: str, headers: { 'X-GitHub-Api-Version': '2026-03-10'} }) } diff --git a/action/src/converter.js b/action/src/converter.js new file mode 100644 index 0000000..e69de29 From 00974195c2d33040943b65da70ba6bd1a99dac97 Mon Sep 17 00:00:00 2001 From: rayan Date: Tue, 4 Aug 2026 01:49:49 +0200 Subject: [PATCH 41/59] fix: det-21 add an + after the backstick --- action/src/api.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action/src/api.js b/action/src/api.js index 202b4ce..4aa1945 100644 --- a/action/src/api.js +++ b/action/src/api.js @@ -18,7 +18,7 @@ export async function createComment(octokit, diagnostic, context) " ### clang-format suggestion " + " ```suggestion " + " raylib::Vector3 alignToWorldPlane(raylib::Vector3 vector) const; " + - " ``` " + " ``` " + " ### clang-tidy diagnostics " + " - function 'alignToWorldPlane' should be marked [[nodiscard]] [[modernize-use-nodiscard](https://clang.llvm.org/extra/clang-tidy/checks/modernize/use-nodiscard.html)]" + " ```suggestion " + From 17b912b6415aa5ac37379b0c2ee08012ba666f80 Mon Sep 17 00:00:00 2001 From: rayan Date: Tue, 4 Aug 2026 01:53:12 +0200 Subject: [PATCH 42/59] fix: det-21 use slash instead of + --- action/src/api.js | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/action/src/api.js b/action/src/api.js index 4aa1945..9eebfa3 100644 --- a/action/src/api.js +++ b/action/src/api.js @@ -13,19 +13,19 @@ import { diagnosticSchema } from './schemas.js'; */ export async function createComment(octokit, diagnostic, context) { - let str = - " " + - " ### clang-format suggestion " + - " ```suggestion " + - " raylib::Vector3 alignToWorldPlane(raylib::Vector3 vector) const; " + - " ``` " + - " ### clang-tidy diagnostics " + - " - function 'alignToWorldPlane' should be marked [[nodiscard]] [[modernize-use-nodiscard](https://clang.llvm.org/extra/clang-tidy/checks/modernize/use-nodiscard.html)]" + - " ```suggestion " + - " [[nodiscard]] raylib::Vector3 alignToWorldPlane( " + - " raylib::Vector3 vector) const; " + - " ``` " - + const str = ` + +### clang-format suggestion +\`\`\`suggestion + raylib::Vector3 alignToWorldPlane(raylib::Vector3 vector) const; +\`\`\` +### clang-tidy diagnostics +- function 'alignToWorldPlane' should be marked [[nodiscard]] [[modernize-use-nodiscard](https://clang.llvm.org/extra/clang-tidy/checks/modernize/use-nodiscard.html)] +\`\`\`suggestion + [[nodiscard]] raylib::Vector3 alignToWorldPlane( + raylib::Vector3 vector) const; +\`\`\` +`; for (const range of diagnostic.ranges) { await octokit.request('POST /repos/{owner}/{repo}/issues/{issue_number}/comments', { owner: context.repo.owner, From d95e4d27753134ea4c00cfc5f41c992a81253b22 Mon Sep 17 00:00:00 2001 From: rayan Date: Fri, 7 Aug 2026 17:21:12 +0200 Subject: [PATCH 43/59] feat: det-21 handle return of debtlint like an list of object --- action/index.js | 19 ++++++++++--------- src/linter/runner.rs | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 44 insertions(+), 10 deletions(-) diff --git a/action/index.js b/action/index.js index 33afb79..5b7f6dc 100644 --- a/action/index.js +++ b/action/index.js @@ -1,20 +1,21 @@ -import * as core from '@actions/core'; -import * as github from '@actions/github'; +//import * as core from '@actions/core'; +//import * as github from '@actions/github'; import { Octokit } from '@octokit/action'; +import { z } from "zod"; + import { execCommand } from "./src/executor.js" import { createComment } from "./src/api.js"; import { diagnosticSchema } from './src/schemas.js'; async function run() { - const GITHUB_TOKEN = process.env.GITHUB_TOKEN; - const octokit = github.getOctokit(GITHUB_TOKEN); - const { context = {} } = github; + //const GITHUB_TOKEN = process.env.GITHUB_TOKEN; + //const octokit = github.getOctokit(GITHUB_TOKEN); + //const { context = {} } = github; const rawOutput = await execCommand('cargo', ['run', 'main.rs']); - - console.log(rawOutput) - const diagnostic = diagnosticSchema.parse(JSON.parse(rawOutput)); - await createComment(octokit, diagnostic, context) + console.log(JSON.parse(rawOutput)) + let diagnostic = z.array(diagnosticSchema).parse(JSON.parse(rawOutput)); + //await createComment(octokit, diagnostic, context) } run() \ No newline at end of file diff --git a/src/linter/runner.rs b/src/linter/runner.rs index 6e8c72f..6eb34b7 100644 --- a/src/linter/runner.rs +++ b/src/linter/runner.rs @@ -1,6 +1,7 @@ use super::diagnostic::{Diagnostic, Position, Range}; -pub fn get_duplicated() -> Diagnostic { +pub fn get_duplicated() -> Vec { + vec![ Diagnostic { code: 1, severity: String::from("low"), @@ -31,7 +32,39 @@ pub fn get_duplicated() -> Diagnostic { }, ], code_description: String::from("Duplicate"), + }, + Diagnostic { + code: 2, + severity: String::from("high"), + ranges: vec![ + Range { + start: Position { + source: "src/tokenizer/decode.rs".to_string(), + line: 10, + character: 1, + }, + end: Position { + source: "src/tokenizer/decode.rs".to_string(), + line: 19, + character: 1, + }, + }, + Range { + start: Position { + source: "src/debug_run.rs".to_string(), + line: 10, + character: 1, + }, + end: Position { + source: "src/debug_run.rs".to_string(), + line: 16, + character: 1, + }, + }, + ], + code_description: String::from("Duplicate code"), } + ] } pub fn run_linter() -> std::io::Result<()> { From 326577ab6a812987b0da93d3c7763b6b6b5f97a5 Mon Sep 17 00:00:00 2001 From: rayan Date: Fri, 7 Aug 2026 23:27:55 +0200 Subject: [PATCH 44/59] refactor: det-21 rewrite project in typescript, and start architecture --- action/action.yml | 4 +- action/index.js | 21 - action/main.ts | 22 + action/package-lock.json | 915 +++++++++++++++++- action/package.json | 4 +- action/src/api.js | 38 - action/src/api/routes.ts | 22 + action/src/converter.js | 0 .../src/{schemas.js => typings/diagnostic.ts} | 11 +- action/src/typings/github.ts | 13 + action/src/utils/convert.ts | 15 + action/src/{executor.js => utils/executor.ts} | 20 +- action/tsconfig.json | 112 +++ 13 files changed, 1102 insertions(+), 95 deletions(-) delete mode 100644 action/index.js create mode 100644 action/main.ts delete mode 100644 action/src/api.js create mode 100644 action/src/api/routes.ts delete mode 100644 action/src/converter.js rename action/src/{schemas.js => typings/diagnostic.ts} (68%) create mode 100644 action/src/typings/github.ts create mode 100644 action/src/utils/convert.ts rename action/src/{executor.js => utils/executor.ts} (53%) create mode 100644 action/tsconfig.json diff --git a/action/action.yml b/action/action.yml index e4d8c67..94fb815 100644 --- a/action/action.yml +++ b/action/action.yml @@ -20,7 +20,7 @@ runs: - name: Install dependencies shell: sh - run: npm install + run: npm install tsx working-directory: ./action @@ -28,4 +28,4 @@ runs: shell: sh env: GITHUB_TOKEN: ${{ github.token }} - run: node ${{ github.action_path }}/index.js \ No newline at end of file + run: tsx ${{ github.action_path }}/index.ts \ No newline at end of file diff --git a/action/index.js b/action/index.js deleted file mode 100644 index 5b7f6dc..0000000 --- a/action/index.js +++ /dev/null @@ -1,21 +0,0 @@ -//import * as core from '@actions/core'; -//import * as github from '@actions/github'; -import { Octokit } from '@octokit/action'; - -import { z } from "zod"; - -import { execCommand } from "./src/executor.js" -import { createComment } from "./src/api.js"; -import { diagnosticSchema } from './src/schemas.js'; - -async function run() { - //const GITHUB_TOKEN = process.env.GITHUB_TOKEN; - //const octokit = github.getOctokit(GITHUB_TOKEN); - //const { context = {} } = github; - const rawOutput = await execCommand('cargo', ['run', 'main.rs']); - console.log(JSON.parse(rawOutput)) - let diagnostic = z.array(diagnosticSchema).parse(JSON.parse(rawOutput)); - //await createComment(octokit, diagnostic, context) -} - -run() \ No newline at end of file diff --git a/action/main.ts b/action/main.ts new file mode 100644 index 0000000..350e223 --- /dev/null +++ b/action/main.ts @@ -0,0 +1,22 @@ +import { z } from "zod"; +import { Diagnostic, diagnosticSchema } from '@/typings/diagnostic'; + +import { getOctokit, context } from '@actions/github'; + +import { execCommand } from "@/utils/executor" +import { parsePullRequestContext } from "@/utils/convert" +import { createPullRequestComments } from "@/api/routes"; + +async function run() { + const GITHUB_TOKEN: string = process.env.GITHUB_TOKEN!; + const octokit = getOctokit(GITHUB_TOKEN); + const eventContext = parsePullRequestContext(context) + + const rawOutput = await execCommand('cargo', ['run', 'main.rs']); + const diagnostic: Diagnostic[] = z.array(diagnosticSchema).parse(JSON.parse(rawOutput)); + + console.log(diagnostic) + await createPullRequestComments(octokit, diagnostic, eventContext) +} + +run() \ No newline at end of file diff --git a/action/package-lock.json b/action/package-lock.json index add6874..9494702 100644 --- a/action/package-lock.json +++ b/action/package-lock.json @@ -15,7 +15,9 @@ "zod": "^4.4.3" }, "devDependencies": { - "@types/node": "^26.1.1" + "@types/node": "^26.2.0", + "tsx": "^4.23.11", + "typescript": "^7.0.2" } }, "node_modules/@actions/core": { @@ -78,6 +80,448 @@ "integrity": "sha512-nRBchcMM+QK1pdjO7/idu86rbJI5YHUKCvKs0KxnSYbVe3F51UfGxuZX4Qy/fWlp6l7gWFwIkrOzN+oUK03kfw==", "license": "MIT" }, + "node_modules/@esbuild/aix-ppc64": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.28.1.tgz", + "integrity": "sha512-Svl7tq8k/08+p6CXPpRjQ1fKX+1odH/BQbb48fV6fj3CWHhsoIOoY87w1oHXm0qEpkIK3ZfVgp0hed3XBXzXMQ==", + "cpu": [ + "ppc64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "aix" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/android-arm": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.28.1.tgz", + "integrity": "sha512-0k2F129Xdio1TdJfzJ8sy1Q47vUD2NnwdhiAf7drUN1EBTfPf4hsFCtmMgu/6m8JSzsBrlmVjudMBQqOfG8usQ==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/android-arm64": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.28.1.tgz", + "integrity": "sha512-34EGEbCIAgosYz6goLcopX6Mo7NyGv9tfwEM2/7Ce2VcVRk568iSvniGWcUXIy7wEDR1wzolcxcriFVrWYcwBg==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/android-x64": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.28.1.tgz", + "integrity": "sha512-dbwY7ltSMDWsRatcRpCnES4F+im88OCUgGZjy52shC7GqHRE/cYlxNbB4Z4UpJswpcc4Qxd2oE/ufM0p61IKng==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/darwin-arm64": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.28.1.tgz", + "integrity": "sha512-TZbWkQY7kvTAXbXUT7uVACR5cMHsDiSz9z7ZKAX/RTq/WJEk3QyRr0wZpNhBDX+/0CtdqUIJlOiodQcta6tY3Q==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/darwin-x64": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.28.1.tgz", + "integrity": "sha512-zfdzgK9ACBNZLI/CyHTOx81SyNbM6YXn7rxSgX97VjyiPl9W1i4Ka4fgKECEoFCKGpvBj5qArWIGgQjOwkgskQ==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/freebsd-arm64": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.28.1.tgz", + "integrity": "sha512-wG2EA8ENdEI0qhkSZMjfqrdY+ziCYCPMmtZjjIwOmXFjmyzEHn+UUxk5of+SYsjtfs3VpnlC7QLzSI5hY/rOAw==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/freebsd-x64": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.28.1.tgz", + "integrity": "sha512-i7dZ9vQgnvSCzi/rYCXNgtF/U+eKZNJBzu3eTQbRgHnM7tNSizLOkRFAl3qzVc/Op/u5YkHHa4pf/3DOYHthLQ==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-arm": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.28.1.tgz", + "integrity": "sha512-qVXBOHQS+d5Y722GwJzJUtOLlX7km3CraOaGormF1pDtPd2C/l1SHRPgjLunLGe51Sh5YYWKMFDyV4SxgMQYTQ==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-arm64": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.28.1.tgz", + "integrity": "sha512-yHs+0uc8+nvEAfAfxrWQKK5peSNzBc4PegcMO0EJ2hT71uA7vB8Ihg2e77R2P7SG5uYjPbHlLLmve4LLLRCf0g==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-ia32": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.28.1.tgz", + "integrity": "sha512-d1z4ZuP0ajrfz/FhGT4vv278rX8KnPPJx8i5+AtK7TYbx9Le9F1hyzurZpkEyjkGa9dUGhQow4C1NmeGvqxN2w==", + "cpu": [ + "ia32" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-loong64": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.28.1.tgz", + "integrity": "sha512-M5sRjUVZrkm1OAPR3dlOYzNmN+loZKGVi1VUQGrwuqLcbR6qeAz+famMhjASeH3YVKvZz+zT1jlh/keC3Rj/lg==", + "cpu": [ + "loong64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-mips64el": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.28.1.tgz", + "integrity": "sha512-mRObBZeHh2OxcBFPWE/FjylkRgZdYuiTR3vaTozquCGOH14iP9oN4x4Ge81CoIDYQrXmIxpFumJBu5MtZpnQJQ==", + "cpu": [ + "mips64el" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-ppc64": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.28.1.tgz", + "integrity": "sha512-slScBsMAb3GFDcdrCgLwZtPYRoH2H/youv10QiZyRjmsP48fznoveWytSgCI/R0ZcUgpc0ZhIUEx6LHts8yrfQ==", + "cpu": [ + "ppc64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-riscv64": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.28.1.tgz", + "integrity": "sha512-kw0owk1o0GFETUJyW0jc0G4Yzs0BHZn0JDZ8JRT088vjJYX777BAs1fDGxAC+q831qOs2DTC96mNsG2opdfyyQ==", + "cpu": [ + "riscv64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-s390x": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.28.1.tgz", + "integrity": "sha512-/lAIjX8aYFRByhh6L5rYtPEDRqa9de/4V/juOXcta5frjvzXO4/sqEtyytse0g3zZFuWu5cDN0MkLz2qRDD2Ag==", + "cpu": [ + "s390x" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-x64": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.28.1.tgz", + "integrity": "sha512-u/anNYF2mmVOEDwLtnQ1wOr3EZ9sTNGLWrsYGYwHWzGA3Si84IOkHXlbWTD1NB+9/1lcnweYKO54uhxZydNzfA==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/netbsd-arm64": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/netbsd-arm64/-/netbsd-arm64-0.28.1.tgz", + "integrity": "sha512-oks0DYbLwWMmaakTsCb+zL4E+aHRVLom9IJZOAthMQEPiQmydXHkziYEsGYRx0uNV/IjEKGAV941JzH02pflqw==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "netbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/netbsd-x64": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.28.1.tgz", + "integrity": "sha512-aeL6lAnN89Hz43Mlh1G8ARasbuoYvSITDEx0tHh5b7jJnHcssqgjy9Yx430GDpmCa6OyrKoS0aNRjKundRizGg==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "netbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/openbsd-arm64": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/openbsd-arm64/-/openbsd-arm64-0.28.1.tgz", + "integrity": "sha512-MEFJe5C3R8pwXdZ5Y21oo6m7ePiS0d9pWucn99O/wvyJZChoIQKrQDxKrGeW8F5+T0okTHesAmDeiHDTIq0V/Q==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "openbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/openbsd-x64": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.28.1.tgz", + "integrity": "sha512-i/ZLIOafE0Z8cI/XANJAixoJL/uRAoS2xOA3rb0xN+KK0K177cMAsQYkzHtBrtMXAKuAc7HGgcWiZ/sRC1Nxgw==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "openbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/openharmony-arm64": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/openharmony-arm64/-/openharmony-arm64-0.28.1.tgz", + "integrity": "sha512-ge+Z7EXFNt2BO1oAMsVpiQ8EwndV9i1xXerAeTIK7AtPs3bKFXQM7nlRxDSIUIMeueR1CNXxqztLzdNeReKBJg==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "openharmony" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/sunos-x64": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.28.1.tgz", + "integrity": "sha512-BEjgtECkL3vY+SaSQ6nzVfiALUeFxpawyp8Jmf5PtYhf1Ug40N1h/hxlhts+f1FvSvarEigdxS3BlSMI2PJLcQ==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "sunos" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/win32-arm64": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.28.1.tgz", + "integrity": "sha512-lCv9eK/H6ZJWbE7bh2nw54CZ9M2nupBxJcTsdk/QQnWkdSjKGuxmmH8/GWrlT1eMmZfn4dGcCjRte397WqfQXA==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/win32-ia32": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.28.1.tgz", + "integrity": "sha512-zvb/mB2bSCoJOpoCBgYKKpX6YM6mJBlBUVUtVj41DlZJVEB6/0CKlRYxP5wWl1C1ILiCoAU5wZZ4q1P3qeS6Eg==", + "cpu": [ + "ia32" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/win32-x64": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.28.1.tgz", + "integrity": "sha512-bm4Mowrv+GXMlpWX++EcXw/iLyd1o3+bJkC2DkWXYVvgZCqD/bSj9ctZeAMC3cIxgjRVR2Dufaiu4YPxr5gW1A==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=18" + } + }, "node_modules/@octokit/action": { "version": "8.0.4", "resolved": "https://registry.npmjs.org/@octokit/action/-/action-8.0.4.tgz", @@ -96,9 +540,9 @@ } }, "node_modules/@octokit/action/node_modules/undici": { - "version": "7.28.0", - "resolved": "https://registry.npmjs.org/undici/-/undici-7.28.0.tgz", - "integrity": "sha512-cRZYrTDwWznlnRiPjggAGxZXanty6M8RV1ff8Wm4LWXBp7/IG8v5DnOm74DtUBp9OONpK75YlPnIjQqX0dBDtA==", + "version": "7.29.0", + "resolved": "https://registry.npmjs.org/undici/-/undici-7.29.0.tgz", + "integrity": "sha512-IDxfleLmmbSskfWSUATiN1nfn2rDuvnMOqb5CWR92iIfojA0Ud+ulOAAEQ57LPr9rWmsreUyf5lwyao+7GNNVw==", "license": "MIT", "engines": { "node": ">=20.18.1" @@ -246,15 +690,355 @@ } }, "node_modules/@types/node": { - "version": "26.1.1", - "resolved": "https://registry.npmjs.org/@types/node/-/node-26.1.1.tgz", - "integrity": "sha512-nxAkRSVkN1Y0JC1W8ky/fTfkGsMmcrRsbx+3XoZE+rMOX71kLYTV7fLXpqud1GpbpP5TuffXFqfX7fH2GgZREw==", + "version": "26.2.0", + "resolved": "https://registry.npmjs.org/@types/node/-/node-26.2.0.tgz", + "integrity": "sha512-5IviulTZeRNp2vAJ514cc/HUlY5nZ9fCbq9DMyC52BrhFZACo3nI0R7qBxhQmo/d27NFe96ur/b7Wwxklda+kg==", "dev": true, "license": "MIT", "dependencies": { "undici-types": "~8.3.0" } }, + "node_modules/@typescript/typescript-aix-ppc64": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@typescript/typescript-aix-ppc64/-/typescript-aix-ppc64-7.0.2.tgz", + "integrity": "sha512-MTKKkWB7p/0E9xi1d1tHtZ5PiLkGEMIq88pK2CubZjOsLtYTLqhgIgi6zepFa+9GHZ6h05NMCkQxGKiPXMxXtQ==", + "cpu": [ + "ppc64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "aix" + ], + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/@typescript/typescript-darwin-arm64": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@typescript/typescript-darwin-arm64/-/typescript-darwin-arm64-7.0.2.tgz", + "integrity": "sha512-gowzar9MwS/aRWp6f3a4KUqzRjAZjOsmGNCM6LcTgXum+dBfgsBVMN+AgvOCCbguXyick6LJhpBszxMebJ8syA==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/@typescript/typescript-darwin-x64": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@typescript/typescript-darwin-x64/-/typescript-darwin-x64-7.0.2.tgz", + "integrity": "sha512-SZ9xZInqApNlNGc9s0W1VSsktYSOe9cFqNOIqmN1Gs8SmkjKZYFt017G4VwPxASInODuAdbTW7sXiFUf893RgA==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/@typescript/typescript-freebsd-arm64": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@typescript/typescript-freebsd-arm64/-/typescript-freebsd-arm64-7.0.2.tgz", + "integrity": "sha512-W5NH4y/J0plIIS5b2xvTEkU7JFxyqdMAOgf+Ilhl0vHQXKO5dZoxd+C/jEtq56c4F3wk71RB4BMRQ2XdI+bwYQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/@typescript/typescript-freebsd-x64": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@typescript/typescript-freebsd-x64/-/typescript-freebsd-x64-7.0.2.tgz", + "integrity": "sha512-UMGDx5sTpzNw3WiPebH7l90IWfJggEd+egHt/q6p7/Cm3zqoV7VxkGXt+3DxPIw8CcmvAB0j3sVVfbhX+M4Tpw==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/@typescript/typescript-linux-arm": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@typescript/typescript-linux-arm/-/typescript-linux-arm-7.0.2.tgz", + "integrity": "sha512-gffT3xPz9sR7j/YJExkyPntrI0P2EP9XbOyWzth2/Gs0RstK+90RBcO0ncXoXy/beYll1SXw846Nf2zdnEz0QQ==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/@typescript/typescript-linux-arm64": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@typescript/typescript-linux-arm64/-/typescript-linux-arm64-7.0.2.tgz", + "integrity": "sha512-Qh4eU4/y3yDjnfjjyPYihMj5/ODIlmt+Bzu17OI+fiSRDW57QmU5SiN63exPRNJPKUzcc1INa1NXdrJ+MqHjUQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/@typescript/typescript-linux-loong64": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@typescript/typescript-linux-loong64/-/typescript-linux-loong64-7.0.2.tgz", + "integrity": "sha512-uEHck9i8hoAzXPiYRib1O7miOnz23SxIeVl6F4LXox+qov1K35jHcEW6VHKvZI+pyvl7fZEP4MCU5LYvIq1GuQ==", + "cpu": [ + "loong64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/@typescript/typescript-linux-mips64el": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@typescript/typescript-linux-mips64el/-/typescript-linux-mips64el-7.0.2.tgz", + "integrity": "sha512-R4KvAMnE43W5Qeqb0Ly56O3mWMWIAgsMyz36DCaycd5nbg/9kzm0liw3JocfRqyJY0KPmzFjbswozXyW0DnIYA==", + "cpu": [ + "mips64el" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/@typescript/typescript-linux-ppc64": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@typescript/typescript-linux-ppc64/-/typescript-linux-ppc64-7.0.2.tgz", + "integrity": "sha512-DORx5b3sd/4S7eayxm4FQv+A7CrkUIGRaHiwI8oiHTAI1fAPWhF4J0vAlkC8biAlHSVVwxMQ3tjZ2/DVbnQiiA==", + "cpu": [ + "ppc64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/@typescript/typescript-linux-riscv64": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@typescript/typescript-linux-riscv64/-/typescript-linux-riscv64-7.0.2.tgz", + "integrity": "sha512-wf0jqEDOjrPRnKwYRyyJDRo11KMbvMFrU+q4zqKyChODBzvlkbhNQfKvLxQCcwTpdDaXSHZTVuh0JoCrKCUMHQ==", + "cpu": [ + "riscv64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/@typescript/typescript-linux-s390x": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@typescript/typescript-linux-s390x/-/typescript-linux-s390x-7.0.2.tgz", + "integrity": "sha512-IkwJc3L7yhytWd/ewjyxNDfOmswCm9GWMJT/ue/dU4aZNbwZeYAetq42VyLmsmSjvoX7z74X6ZaYCtzAr0EuGw==", + "cpu": [ + "s390x" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/@typescript/typescript-linux-x64": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@typescript/typescript-linux-x64/-/typescript-linux-x64-7.0.2.tgz", + "integrity": "sha512-EYdf2cNg7rgCWJnxCdJ+F3V39O8ihb37eHAu1LK8oAFizgTQbPOK7zHHXbPt8rX24COqODXeI3sIf0fCXG7H/A==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/@typescript/typescript-netbsd-arm64": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@typescript/typescript-netbsd-arm64/-/typescript-netbsd-arm64-7.0.2.tgz", + "integrity": "sha512-+polYF4MF04aPpO5FTkHran9yUQDSXqy5GiSDKpsll5jy3l3+g9QLhpf39T+ePtefhXLOGrLl0QIjkQP6VnelA==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "netbsd" + ], + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/@typescript/typescript-netbsd-x64": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@typescript/typescript-netbsd-x64/-/typescript-netbsd-x64-7.0.2.tgz", + "integrity": "sha512-8YIT0EHM/3dq10ZOVF/A7pc/YSMtbcecct4rWtexrnSCHOPcpC2KTLXfTCR6vDpnSiY12heNb1GiN/wu+T/FyA==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "netbsd" + ], + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/@typescript/typescript-openbsd-arm64": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@typescript/typescript-openbsd-arm64/-/typescript-openbsd-arm64-7.0.2.tgz", + "integrity": "sha512-APT8+ClYnuYm1u9+kgGXoMj2VzWzcymwh2gNSQVySHfkRDGOTVkoWLjCmOQSaO+PoqQ57B0flRp9SA+7GnnkzQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "openbsd" + ], + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/@typescript/typescript-openbsd-x64": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@typescript/typescript-openbsd-x64/-/typescript-openbsd-x64-7.0.2.tgz", + "integrity": "sha512-yX7s+Q0Dln0Dt9tEzZsAjXXR/+ytBM7AlglaqyeMPxQszJ1JhlJdZ6jLA+IzldHtflX81em7lDao1xXu+aRRkg==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "openbsd" + ], + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/@typescript/typescript-sunos-x64": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@typescript/typescript-sunos-x64/-/typescript-sunos-x64-7.0.2.tgz", + "integrity": "sha512-dLJDGaLZ1D4HPQn62u1n8mBDkJREwMsAkCdkwd4Ieqw+x3TUyTsqY0YiBCtE6H6OzzgGk3iuZ3vFWRS+E8/d1g==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "sunos" + ], + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/@typescript/typescript-win32-arm64": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@typescript/typescript-win32-arm64/-/typescript-win32-arm64-7.0.2.tgz", + "integrity": "sha512-Gyl1Vy6OsWesLzmq+EP0Fb7b4Nid5232AvcA2SFcdYreldpNtYFFofPjnt62y9hQy7VTaZp65ICJjuAQRaVcIQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/@typescript/typescript-win32-x64": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@typescript/typescript-win32-x64/-/typescript-win32-x64-7.0.2.tgz", + "integrity": "sha512-0BQ3HkAHHlKLSp1qRvf3SUhGpGsDuhB/jgFw75guyqbxJqEaS0Cw/VFO8i2nHglJUzQCRtMMR/IBAKE3ETMC4g==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=16.20.0" + } + }, "node_modules/before-after-hook": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/before-after-hook/-/before-after-hook-4.0.0.tgz", @@ -274,12 +1058,88 @@ "url": "https://opencollective.com/express" } }, + "node_modules/esbuild": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.28.1.tgz", + "integrity": "sha512-HrJrvZv5ayxBzPfwphOoNzkzOIIlifzk0KJrGK2c8R4+LKpMtpYLQeUdjnwjWv/LZlkH2laZk+4w78pi99D4Vw==", + "dev": true, + "hasInstallScript": true, + "license": "MIT", + "bin": { + "esbuild": "bin/esbuild" + }, + "engines": { + "node": ">=18" + }, + "optionalDependencies": { + "@esbuild/aix-ppc64": "0.28.1", + "@esbuild/android-arm": "0.28.1", + "@esbuild/android-arm64": "0.28.1", + "@esbuild/android-x64": "0.28.1", + "@esbuild/darwin-arm64": "0.28.1", + "@esbuild/darwin-x64": "0.28.1", + "@esbuild/freebsd-arm64": "0.28.1", + "@esbuild/freebsd-x64": "0.28.1", + "@esbuild/linux-arm": "0.28.1", + "@esbuild/linux-arm64": "0.28.1", + "@esbuild/linux-ia32": "0.28.1", + "@esbuild/linux-loong64": "0.28.1", + "@esbuild/linux-mips64el": "0.28.1", + "@esbuild/linux-ppc64": "0.28.1", + "@esbuild/linux-riscv64": "0.28.1", + "@esbuild/linux-s390x": "0.28.1", + "@esbuild/linux-x64": "0.28.1", + "@esbuild/netbsd-arm64": "0.28.1", + "@esbuild/netbsd-x64": "0.28.1", + "@esbuild/openbsd-arm64": "0.28.1", + "@esbuild/openbsd-x64": "0.28.1", + "@esbuild/openharmony-arm64": "0.28.1", + "@esbuild/sunos-x64": "0.28.1", + "@esbuild/win32-arm64": "0.28.1", + "@esbuild/win32-ia32": "0.28.1", + "@esbuild/win32-x64": "0.28.1" + } + }, + "node_modules/fsevents": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", + "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==", + "dev": true, + "hasInstallScript": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^8.16.0 || ^10.6.0 || >=11.0.0" + } + }, "node_modules/json-with-bigint": { "version": "3.5.10", "resolved": "https://registry.npmjs.org/json-with-bigint/-/json-with-bigint-3.5.10.tgz", "integrity": "sha512-Vcx+JVNEBts/xfcoCS69sKrOhOk/3TVlvlT+XzUOefVKnnrbYSCKpDCm10pohsJFtsJVYnwa/cXRZ4eElzaM6w==", "license": "MIT" }, + "node_modules/tsx": { + "version": "4.23.11", + "resolved": "https://registry.npmjs.org/tsx/-/tsx-4.23.11.tgz", + "integrity": "sha512-Ry2oTEUnhBdeEdWIztY8kf3/nBGnPnjMLVGL0YfdRXMORuPER5NlKmayqxtxRxwB1xBN+RivRaJfe7PM1rtiyw==", + "dev": true, + "license": "MIT", + "dependencies": { + "esbuild": "~0.28.0" + }, + "bin": { + "tsx": "dist/cli.mjs" + }, + "engines": { + "node": ">=18.0.0" + }, + "optionalDependencies": { + "fsevents": "~2.3.3" + } + }, "node_modules/tunnel": { "version": "0.0.6", "resolved": "https://registry.npmjs.org/tunnel/-/tunnel-0.0.6.tgz", @@ -289,10 +1149,45 @@ "node": ">=0.6.11 <=0.7.0 || >=0.7.3" } }, + "node_modules/typescript": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-7.0.2.tgz", + "integrity": "sha512-8FYau96o3NKOhbjKi/qNvG/W5jhzxkbdm5sj9AbZ/5T5sWqn3hJgLfGx27sRKZWTvyzCP8dLRBTf5tBTSRVUNA==", + "dev": true, + "license": "Apache-2.0", + "bin": { + "tsc": "bin/tsc" + }, + "engines": { + "node": ">=16.20.0" + }, + "optionalDependencies": { + "@typescript/typescript-aix-ppc64": "7.0.2", + "@typescript/typescript-darwin-arm64": "7.0.2", + "@typescript/typescript-darwin-x64": "7.0.2", + "@typescript/typescript-freebsd-arm64": "7.0.2", + "@typescript/typescript-freebsd-x64": "7.0.2", + "@typescript/typescript-linux-arm": "7.0.2", + "@typescript/typescript-linux-arm64": "7.0.2", + "@typescript/typescript-linux-loong64": "7.0.2", + "@typescript/typescript-linux-mips64el": "7.0.2", + "@typescript/typescript-linux-ppc64": "7.0.2", + "@typescript/typescript-linux-riscv64": "7.0.2", + "@typescript/typescript-linux-s390x": "7.0.2", + "@typescript/typescript-linux-x64": "7.0.2", + "@typescript/typescript-netbsd-arm64": "7.0.2", + "@typescript/typescript-netbsd-x64": "7.0.2", + "@typescript/typescript-openbsd-arm64": "7.0.2", + "@typescript/typescript-openbsd-x64": "7.0.2", + "@typescript/typescript-sunos-x64": "7.0.2", + "@typescript/typescript-win32-arm64": "7.0.2", + "@typescript/typescript-win32-x64": "7.0.2" + } + }, "node_modules/undici": { - "version": "6.27.0", - "resolved": "https://registry.npmjs.org/undici/-/undici-6.27.0.tgz", - "integrity": "sha512-YmfV3YnEDzXRC5lZ2jWtWWHKGUm1zIt8AhesR1tens+HTNv+YZlN/dp6G727LOvMJ8xjP9Be7Y2Sdr96LDm+pg==", + "version": "6.28.0", + "resolved": "https://registry.npmjs.org/undici/-/undici-6.28.0.tgz", + "integrity": "sha512-LIY910g9TI13YS95lrMFrs8Rm/u/irgHeTWoKCoteeJ04CUJ92eEfj0rVn+7VKMPBpUPiUoBKfhNyLI23EE/KA==", "license": "MIT", "engines": { "node": ">=18.17" diff --git a/action/package.json b/action/package.json index 2c5876d..e517a0a 100644 --- a/action/package.json +++ b/action/package.json @@ -17,6 +17,8 @@ "zod": "^4.4.3" }, "devDependencies": { - "@types/node": "^26.1.1" + "@types/node": "^26.2.0", + "tsx": "^4.23.11", + "typescript": "^7.0.2" } } diff --git a/action/src/api.js b/action/src/api.js deleted file mode 100644 index 9eebfa3..0000000 --- a/action/src/api.js +++ /dev/null @@ -1,38 +0,0 @@ -import { spawn } from 'child_process'; -import { Octokit } from '@octokit/action'; - -import { diagnosticSchema } from './schemas.js'; - - - -/** - * Create a comment on a pull request - * @param { Octokit } octokit - * @param { Diagnostic } diagnostic - * @param { Object } context - */ -export async function createComment(octokit, diagnostic, context) -{ - const str = ` - -### clang-format suggestion -\`\`\`suggestion - raylib::Vector3 alignToWorldPlane(raylib::Vector3 vector) const; -\`\`\` -### clang-tidy diagnostics -- function 'alignToWorldPlane' should be marked [[nodiscard]] [[modernize-use-nodiscard](https://clang.llvm.org/extra/clang-tidy/checks/modernize/use-nodiscard.html)] -\`\`\`suggestion - [[nodiscard]] raylib::Vector3 alignToWorldPlane( - raylib::Vector3 vector) const; -\`\`\` -`; - for (const range of diagnostic.ranges) { - await octokit.request('POST /repos/{owner}/{repo}/issues/{issue_number}/comments', { - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: context.payload.pull_request.number, - body: str, - headers: { 'X-GitHub-Api-Version': '2026-03-10'} - }) - } -} \ No newline at end of file diff --git a/action/src/api/routes.ts b/action/src/api/routes.ts new file mode 100644 index 0000000..9c495bb --- /dev/null +++ b/action/src/api/routes.ts @@ -0,0 +1,22 @@ +import { spawn } from 'child_process'; +import { getOctokit, context } from '@actions/github'; + +import { Diagnostic } from '../typings/diagnostic'; +import { PullRequestContext, Octokit } from '../typings/github'; + + +export async function createPullRequestComments(octokit: Octokit, diagnostic: Diagnostic[], context: PullRequestContext) +{ + for (const range of diagnostic) { + await octokit.request('POST /repos/{owner}/{repo}/issues/{issue_number}/comments', { + owner: context.owner, + repo: context.repo, + issue_number: context.issueNumber, + body: "**Debtlint suggestion**", + headers: { 'X-GitHub-Api-Version': '2026-03-10'} + }); + }; +} + +async function createThreadComments() {} + diff --git a/action/src/converter.js b/action/src/converter.js deleted file mode 100644 index e69de29..0000000 diff --git a/action/src/schemas.js b/action/src/typings/diagnostic.ts similarity index 68% rename from action/src/schemas.js rename to action/src/typings/diagnostic.ts index a225165..5249cd9 100644 --- a/action/src/schemas.js +++ b/action/src/typings/diagnostic.ts @@ -1,28 +1,21 @@ import { z } from "zod"; -/** -* @typedef {z.infer} Position -*/ const positionSchema = z.object({ source: z.string(), line: z.number().min(0), character: z.number().min(0), }); -/** -* @typedef {z.infer} Range -*/ const rangeSchema = z.object({ start: positionSchema, end: positionSchema, }); -/** -* @typedef {z.infer} Diagnostic -*/ export const diagnosticSchema = z.object({ code: z.number().min(0) , severity: z.string(), ranges: z.array(rangeSchema), code_description: z.string(), }) + +export type Diagnostic = z.infer \ No newline at end of file diff --git a/action/src/typings/github.ts b/action/src/typings/github.ts new file mode 100644 index 0000000..e7e82c0 --- /dev/null +++ b/action/src/typings/github.ts @@ -0,0 +1,13 @@ +import { z } from "zod"; +import { context, getOctokit } from "@actions/github"; + +export type Octokit = ReturnType; +export type GithubContext = typeof context; + +export const PullRequestSchema = z.object({ + owner: z.string(), + repo: z.string(), + issueNumber: z.number() +}); + +export type PullRequestContext = z.infer diff --git a/action/src/utils/convert.ts b/action/src/utils/convert.ts new file mode 100644 index 0000000..f5b920c --- /dev/null +++ b/action/src/utils/convert.ts @@ -0,0 +1,15 @@ +import { context } from "@actions/github"; +import { PullRequestSchema, type PullRequestContext } from '@/typings/github' +import type { GithubContext } from "@/typings/github"; + +export function parsePullRequestContext(githubContext: GithubContext): PullRequestContext +{ + if (githubContext.payload.pull_request === undefined) { + throw new Error("Pull request number is not defined") + } + return PullRequestSchema.parse({ + owner: githubContext.repo.owner, + repo: githubContext.repo.repo, + issueNumber: githubContext.payload.pull_request.number + }); +} \ No newline at end of file diff --git a/action/src/executor.js b/action/src/utils/executor.ts similarity index 53% rename from action/src/executor.js rename to action/src/utils/executor.ts index 288aa56..980bed0 100644 --- a/action/src/executor.js +++ b/action/src/utils/executor.ts @@ -1,28 +1,20 @@ import { spawn } from 'child_process'; -import { diagnosticSchema } from './schemas.js'; - -/** - * Execute a command in a child process - * @param {string} cmd - * @param {string[]} args - * @returns {Promise} - */ -export const execCommand = (cmd, args = []) => { +export const execCommand = (cmd: string, args: string[] = []): Promise => { return new Promise((resolve, reject) => { const process = spawn(cmd, args); - let output = "" - let errorOutput = "" + let output: string = "" + let errorOutput: string = "" - process.stdout.on('data', (data) => { + process.stdout.on('data', (data: Buffer) => { output += data.toString(); }); - process.stderr.on('data', (data) => { + process.stderr.on('data', (data: Buffer) => { errorOutput += data.toString(); }); - process.on('close', (code) => { + process.on('close', (code: number) => { if (code !== 0) { return reject(new Error(`Process exited with code ${code}: ${errorOutput}`)); } diff --git a/action/tsconfig.json b/action/tsconfig.json new file mode 100644 index 0000000..6b0b9ad --- /dev/null +++ b/action/tsconfig.json @@ -0,0 +1,112 @@ +{ + "compilerOptions": { + /* Visit https://aka.ms/tsconfig to read more about this file */ + + /* Projects */ + // "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */ + // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */ + // "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */ + // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */ + // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */ + // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */ + + /* Language and Environment */ + "target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */ + // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */ + // "jsx": "preserve", /* Specify what JSX code is generated. */ + // "libReplacement": true, /* Enable lib replacement. */ + // "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */ + // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */ + // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */ + // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */ + // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */ + // "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */ + // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */ + // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */ + "moduleDetection": "force", /* Control what method is used to detect module-format JS files. */ + + /* Modules */ + "module": "Preserve", /* Specify what module code is generated. */ + // "rootDir": "./", /* Specify the root folder within your source files. */ + // "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */ + "paths": { "@/*": ["./src/*"] }, /* Specify a set of entries that re-map imports to additional lookup locations. */ + // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ + // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */ + "types": ["node"], /* 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. */ + // "rewriteRelativeImportExtensions": true, /* Rewrite '.ts', '.tsx', '.mts', and '.cts' file extensions in relative import paths to their JavaScript equivalent in output files. */ + // "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. */ + // "noUncheckedSideEffectImports": true, /* Check side effect imports. */ + "resolveJsonModule": true, /* Enable importing .json files. */ + // "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */ + // "noResolve": true, /* Disallow 'import's, 'require's or ''s from expanding the number of files TypeScript should add to a project. */ + + /* JavaScript Support */ + "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */ + // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */ + // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */ + + /* Emit */ + // "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */ + // "declarationMap": true, /* Create sourcemaps for d.ts files. */ + // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */ + // "sourceMap": true, /* Create source map files for emitted JavaScript files. */ + // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */ + // "noEmit": true, /* Disable emitting files from a compilation. */ + // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */ + // "outDir": "./", /* Specify an output folder for all emitted files. */ + // "removeComments": true, /* Disable emitting comments. */ + // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */ + // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */ + // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */ + // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ + // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */ + // "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */ + // "newLine": "crlf", /* Set the newline character for emitting files. */ + // "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */ + // "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */ + // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */ + // "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */ + // "declarationDir": "./", /* Specify the output directory for generated declaration files. */ + + /* Interop Constraints */ + "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ + // "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */ + // "isolatedDeclarations": true, /* Require sufficient annotation on exports so other tools can trivially generate declaration files. */ + // "erasableSyntaxOnly": true, /* Do not allow runtime constructs that are not part of ECMAScript. */ + // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ + "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ + // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ + "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */ + + /* Type Checking */ + "strict": true, /* Enable all strict type-checking options. */ + // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */ + // "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */ + // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */ + // "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */ + // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */ + // "strictBuiltinIteratorReturn": true, /* Built-in iterators are instantiated with a 'TReturn' type of 'undefined' instead of 'any'. */ + // "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */ + // "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */ + // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */ + // "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */ + // "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */ + // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */ + // "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */ + // "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */ + // "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */ + // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */ + // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */ + // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */ + // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */ + + /* Completeness */ + // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ + "skipLibCheck": true /* Skip type checking all .d.ts files. */ + } +} From f66cce955a8633dcb029381433eec095e31f7d08 Mon Sep 17 00:00:00 2001 From: rayan Date: Fri, 7 Aug 2026 23:33:30 +0200 Subject: [PATCH 45/59] fix: format with rustfmt --- src/linter/runner.rs | 118 +++++++++++++++++++++---------------------- 1 file changed, 59 insertions(+), 59 deletions(-) diff --git a/src/linter/runner.rs b/src/linter/runner.rs index 6eb34b7..abd034d 100644 --- a/src/linter/runner.rs +++ b/src/linter/runner.rs @@ -1,69 +1,69 @@ use super::diagnostic::{Diagnostic, Position, Range}; -pub fn get_duplicated() -> Vec { +pub fn get_duplicated() -> Vec { vec![ - Diagnostic { - code: 1, - severity: String::from("low"), - ranges: vec![ - Range { - start: Position { - source: "src/linter/runner.rs".to_string(), - line: 10, - character: 1, + Diagnostic { + code: 1, + severity: String::from("low"), + ranges: vec![ + Range { + start: Position { + source: "src/linter/runner.rs".to_string(), + line: 10, + character: 1, + }, + end: Position { + source: "src/linter/runner.rs".to_string(), + line: 19, + character: 1, + }, }, - end: Position { - source: "src/linter/runner.rs".to_string(), - line: 19, - character: 1, + Range { + start: Position { + source: "src/debug_run.rs".to_string(), + line: 10, + character: 1, + }, + end: Position { + source: "src/debug_run.rs".to_string(), + line: 16, + character: 1, + }, }, - }, - Range { - start: Position { - source: "src/debug_run.rs".to_string(), - line: 10, - character: 1, + ], + code_description: String::from("Duplicate"), + }, + Diagnostic { + code: 2, + severity: String::from("high"), + ranges: vec![ + Range { + start: Position { + source: "src/tokenizer/decode.rs".to_string(), + line: 10, + character: 1, + }, + end: Position { + source: "src/tokenizer/decode.rs".to_string(), + line: 19, + character: 1, + }, }, - end: Position { - source: "src/debug_run.rs".to_string(), - line: 16, - character: 1, + Range { + start: Position { + source: "src/debug_run.rs".to_string(), + line: 10, + character: 1, + }, + end: Position { + source: "src/debug_run.rs".to_string(), + line: 16, + character: 1, + }, }, - }, - ], - code_description: String::from("Duplicate"), - }, - Diagnostic { - code: 2, - severity: String::from("high"), - ranges: vec![ - Range { - start: Position { - source: "src/tokenizer/decode.rs".to_string(), - line: 10, - character: 1, - }, - end: Position { - source: "src/tokenizer/decode.rs".to_string(), - line: 19, - character: 1, - }, - }, - Range { - start: Position { - source: "src/debug_run.rs".to_string(), - line: 10, - character: 1, - }, - end: Position { - source: "src/debug_run.rs".to_string(), - line: 16, - character: 1, - }, - }, - ], - code_description: String::from("Duplicate code"), - } + ], + code_description: String::from("Duplicate code"), + }, ] } From 87295c9fac5ae0aacb5d8974b2bb33abfcf7970a Mon Sep 17 00:00:00 2001 From: rayan Date: Fri, 7 Aug 2026 23:50:49 +0200 Subject: [PATCH 46/59] refactor: det-21 use nushell to cross plateform action and use tsx --- action/action.yml | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/action/action.yml b/action/action.yml index 94fb815..0dd769e 100644 --- a/action/action.yml +++ b/action/action.yml @@ -13,19 +13,22 @@ inputs: runs: using: composite steps: + - name: Setup nu shell + uses: hustcer/setup-nu@v3 + with: + version: 0.114.1 - name: Install debtlint - shell: sh + shell: nu {0} run: cargo install debtlint - name: Install dependencies - shell: sh - run: npm install tsx + shell: nu {0} + run: npm install working-directory: ./action - - name: Run debtlint - shell: sh + shell: nu {0} env: GITHUB_TOKEN: ${{ github.token }} - run: tsx ${{ github.action_path }}/index.ts \ No newline at end of file + run: npx tsx ${{ github.action_path }}/index.ts \ No newline at end of file From 254c0b82215a0a12d3cb6af3bb7fbc75e925860d Mon Sep 17 00:00:00 2001 From: rayan Date: Fri, 7 Aug 2026 23:51:29 +0200 Subject: [PATCH 47/59] fix: det-21 fix index.ts by main.ts --- action/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action/action.yml b/action/action.yml index 0dd769e..247f5e9 100644 --- a/action/action.yml +++ b/action/action.yml @@ -31,4 +31,4 @@ runs: shell: nu {0} env: GITHUB_TOKEN: ${{ github.token }} - run: npx tsx ${{ github.action_path }}/index.ts \ No newline at end of file + run: npx tsx ${{ github.action_path }}/main.ts \ No newline at end of file From b9d7a4869355549f7cc2afdff22a58badd5f1c84 Mon Sep 17 00:00:00 2001 From: rayan Date: Sat, 8 Aug 2026 12:12:18 +0200 Subject: [PATCH 48/59] fix: det-21 specify action directory in action.yml --- action/action.yml | 3 ++- action/main.ts | 8 ++++---- action/src/api/routes.ts | 2 +- action/tsconfig.json | 2 +- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/action/action.yml b/action/action.yml index 247f5e9..ea23c6d 100644 --- a/action/action.yml +++ b/action/action.yml @@ -24,11 +24,12 @@ runs: - name: Install dependencies shell: nu {0} + working-directory: ${{ github.action_path }} run: npm install - working-directory: ./action - name: Run debtlint shell: nu {0} env: GITHUB_TOKEN: ${{ github.token }} + working-directory: ${{ github.action_path }} run: npx tsx ${{ github.action_path }}/main.ts \ No newline at end of file diff --git a/action/main.ts b/action/main.ts index 350e223..f655e29 100644 --- a/action/main.ts +++ b/action/main.ts @@ -8,15 +8,15 @@ import { parsePullRequestContext } from "@/utils/convert" import { createPullRequestComments } from "@/api/routes"; async function run() { - const GITHUB_TOKEN: string = process.env.GITHUB_TOKEN!; - const octokit = getOctokit(GITHUB_TOKEN); - const eventContext = parsePullRequestContext(context) + //const GITHUB_TOKEN: string = process.env.GITHUB_TOKEN!; + //const octokit = getOctokit(GITHUB_TOKEN); + //const eventContext = parsePullRequestContext(context) const rawOutput = await execCommand('cargo', ['run', 'main.rs']); const diagnostic: Diagnostic[] = z.array(diagnosticSchema).parse(JSON.parse(rawOutput)); console.log(diagnostic) - await createPullRequestComments(octokit, diagnostic, eventContext) + //await createPullRequestComments(octokit, diagnostic, eventContext) } run() \ No newline at end of file diff --git a/action/src/api/routes.ts b/action/src/api/routes.ts index 9c495bb..9be0a5c 100644 --- a/action/src/api/routes.ts +++ b/action/src/api/routes.ts @@ -1,7 +1,7 @@ import { spawn } from 'child_process'; import { getOctokit, context } from '@actions/github'; -import { Diagnostic } from '../typings/diagnostic'; +import { Diagnostic } from '@/typings/diagnostic'; import { PullRequestContext, Octokit } from '../typings/github'; diff --git a/action/tsconfig.json b/action/tsconfig.json index 6b0b9ad..85feabd 100644 --- a/action/tsconfig.json +++ b/action/tsconfig.json @@ -27,7 +27,7 @@ /* Modules */ "module": "Preserve", /* Specify what module code is generated. */ - // "rootDir": "./", /* Specify the root folder within your source files. */ + "rootDir": "src", /* Specify the root folder within your source files. */ // "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */ "paths": { "@/*": ["./src/*"] }, /* Specify a set of entries that re-map imports to additional lookup locations. */ // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ From 7b2cc857ffa602ebe16b45d15e62f3002b339f03 Mon Sep 17 00:00:00 2001 From: rayan Date: Sat, 8 Aug 2026 12:14:51 +0200 Subject: [PATCH 49/59] test: det-21 call only linter in main(to test) --- src/main.rs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/main.rs b/src/main.rs index 142e47b..2d64183 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,18 +10,18 @@ use debtlint::pipeline::{BpeConfig, run_bpe}; use ingestion::ingest_codebase; fn main() -> std::io::Result<()> { - let args = Args::parse(); - let cfg = get_config(); - let files = ingest_codebase(cfg); - - let _result = run_bpe( - &files, - BpeConfig { - vocab_size: args.vocab_size, - min_frequency: args.min_frequency, - }, - args.load_vocab.as_deref(), - )?; + //let args = Args::parse(); + //let cfg = get_config(); + //let files = ingest_codebase(cfg); +// + //let _result = run_bpe( + // &files, + // BpeConfig { + // vocab_size: args.vocab_size, + // min_frequency: args.min_frequency, + // }, + // args.load_vocab.as_deref(), + //)?; let _ = run_linter(); Ok(()) } From e097390a1a0343cd4e320fecc5e71fb21f673eb8 Mon Sep 17 00:00:00 2001 From: rayan Date: Sat, 8 Aug 2026 12:20:04 +0200 Subject: [PATCH 50/59] refactor: det-21 remove comment on api call --- action/main.ts | 8 ++++---- action/tsconfig.json | 2 +- src/main.rs | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/action/main.ts b/action/main.ts index f655e29..350e223 100644 --- a/action/main.ts +++ b/action/main.ts @@ -8,15 +8,15 @@ import { parsePullRequestContext } from "@/utils/convert" import { createPullRequestComments } from "@/api/routes"; async function run() { - //const GITHUB_TOKEN: string = process.env.GITHUB_TOKEN!; - //const octokit = getOctokit(GITHUB_TOKEN); - //const eventContext = parsePullRequestContext(context) + const GITHUB_TOKEN: string = process.env.GITHUB_TOKEN!; + const octokit = getOctokit(GITHUB_TOKEN); + const eventContext = parsePullRequestContext(context) const rawOutput = await execCommand('cargo', ['run', 'main.rs']); const diagnostic: Diagnostic[] = z.array(diagnosticSchema).parse(JSON.parse(rawOutput)); console.log(diagnostic) - //await createPullRequestComments(octokit, diagnostic, eventContext) + await createPullRequestComments(octokit, diagnostic, eventContext) } run() \ No newline at end of file diff --git a/action/tsconfig.json b/action/tsconfig.json index 85feabd..9327a34 100644 --- a/action/tsconfig.json +++ b/action/tsconfig.json @@ -27,7 +27,7 @@ /* Modules */ "module": "Preserve", /* Specify what module code is generated. */ - "rootDir": "src", /* Specify the root folder within your source files. */ + //"rootDir": "src", /* Specify the root folder within your source files. */ // "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */ "paths": { "@/*": ["./src/*"] }, /* Specify a set of entries that re-map imports to additional lookup locations. */ // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ diff --git a/src/main.rs b/src/main.rs index 2d64183..474b78b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,7 +13,7 @@ fn main() -> std::io::Result<()> { //let args = Args::parse(); //let cfg = get_config(); //let files = ingest_codebase(cfg); -// + // //let _result = run_bpe( // &files, // BpeConfig { From abebdd8f7560fd7f1198b1f539b27c4c9f52575f Mon Sep 17 00:00:00 2001 From: rayan Date: Sat, 8 Aug 2026 18:45:40 +0200 Subject: [PATCH 51/59] refactor(app): det-21 move code description and add imbrecated loop --- action/main.ts | 13 +++++++------ action/src/api/routes.ts | 22 ++++++++++++---------- action/src/typings/diagnostic.ts | 4 ++-- src/linter/diagnostic.rs | 2 +- src/linter/runner.rs | 4 ++-- 5 files changed, 24 insertions(+), 21 deletions(-) diff --git a/action/main.ts b/action/main.ts index 350e223..837c69a 100644 --- a/action/main.ts +++ b/action/main.ts @@ -8,15 +8,16 @@ import { parsePullRequestContext } from "@/utils/convert" import { createPullRequestComments } from "@/api/routes"; async function run() { - const GITHUB_TOKEN: string = process.env.GITHUB_TOKEN!; - const octokit = getOctokit(GITHUB_TOKEN); - const eventContext = parsePullRequestContext(context) + //const GITHUB_TOKEN: string = process.env.GITHUB_TOKEN!; + //const octokit = getOctokit(GITHUB_TOKEN); + //const eventContext = parsePullRequestContext(context) const rawOutput = await execCommand('cargo', ['run', 'main.rs']); - const diagnostic: Diagnostic[] = z.array(diagnosticSchema).parse(JSON.parse(rawOutput)); + const diagnostics: Diagnostic[] = z.array(diagnosticSchema).parse(JSON.parse(rawOutput)); - console.log(diagnostic) - await createPullRequestComments(octokit, diagnostic, eventContext) + console.log("Diagnostic: ", diagnostics) + console.log("Ranges:") + //await createPullRequestComments(octokit, diagnostic, eventContext) } run() \ No newline at end of file diff --git a/action/src/api/routes.ts b/action/src/api/routes.ts index 9be0a5c..5c105a4 100644 --- a/action/src/api/routes.ts +++ b/action/src/api/routes.ts @@ -5,17 +5,19 @@ import { Diagnostic } from '@/typings/diagnostic'; import { PullRequestContext, Octokit } from '../typings/github'; -export async function createPullRequestComments(octokit: Octokit, diagnostic: Diagnostic[], context: PullRequestContext) +export async function createPullRequestComments(octokit: Octokit, diagnostics: Diagnostic[], context: PullRequestContext) { - for (const range of diagnostic) { - await octokit.request('POST /repos/{owner}/{repo}/issues/{issue_number}/comments', { - owner: context.owner, - repo: context.repo, - issue_number: context.issueNumber, - body: "**Debtlint suggestion**", - headers: { 'X-GitHub-Api-Version': '2026-03-10'} - }); - }; + for (const diagnostic of diagnostics) { + for (const range of diagnostic.ranges) { + await octokit.request('POST /repos/{owner}/{repo}/issues/{issue_number}/comments', { + owner: context.owner, + repo: context.repo, + issue_number: context.issueNumber, + body: "**Debtlint suggestion**", + headers: { 'X-GitHub-Api-Version': '2026-03-10'} + }); + } + } } async function createThreadComments() {} diff --git a/action/src/typings/diagnostic.ts b/action/src/typings/diagnostic.ts index 5249cd9..b93b21e 100644 --- a/action/src/typings/diagnostic.ts +++ b/action/src/typings/diagnostic.ts @@ -12,10 +12,10 @@ const rangeSchema = z.object({ }); export const diagnosticSchema = z.object({ - code: z.number().min(0) , + code: z.number().min(0), severity: z.string(), ranges: z.array(rangeSchema), - code_description: z.string(), + description: z.string(), }) export type Diagnostic = z.infer \ No newline at end of file diff --git a/src/linter/diagnostic.rs b/src/linter/diagnostic.rs index 2a19a8e..09b4c5b 100644 --- a/src/linter/diagnostic.rs +++ b/src/linter/diagnostic.rs @@ -18,5 +18,5 @@ pub struct Diagnostic { pub severity: String, pub code: u16, pub ranges: Vec, - pub code_description: String, + pub description: String, } diff --git a/src/linter/runner.rs b/src/linter/runner.rs index abd034d..642f9ce 100644 --- a/src/linter/runner.rs +++ b/src/linter/runner.rs @@ -31,7 +31,7 @@ pub fn get_duplicated() -> Vec { }, }, ], - code_description: String::from("Duplicate"), + description: String::from("Duplicate"), }, Diagnostic { code: 2, @@ -62,7 +62,7 @@ pub fn get_duplicated() -> Vec { }, }, ], - code_description: String::from("Duplicate code"), + description: String::from("Duplicate code"), }, ] } From 4fee6251bf2991119e42b2ed1bb27717a107a41f Mon Sep 17 00:00:00 2001 From: rayan Date: Tue, 11 Aug 2026 03:08:33 +0200 Subject: [PATCH 52/59] feat: det-21 use Act to test action without github minutes --- .gitignore | 7 ++-- Dockerfile | 5 +++ action/action.yml | 15 ++++++--- action/main.ts | 11 +++---- action/src/api/routes.ts | 55 ++++++++++++++++++++++++-------- action/src/typings/diagnostic.ts | 7 ++-- event.json | 16 ++++++++++ src/linter/diagnostic.rs | 2 +- src/linter/runner.rs | 33 ++++++------------- 9 files changed, 96 insertions(+), 55 deletions(-) create mode 100644 Dockerfile create mode 100644 event.json diff --git a/.gitignore b/.gitignore index 4f518cb..4ded108 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ - +# Act +.secrets +.env # Added by cargo - -/target +/target \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..007c691 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,5 @@ +FROM catthehacker/ubuntu:act-latest + +ENV ACTIONS_RUNNER_FORCE_ACTIONS_NODE_VERSION=node20 + +RUN curl https://sh.rustup.rs -sSf | sh -s -- -y \ No newline at end of file diff --git a/action/action.yml b/action/action.yml index ea23c6d..3e27d13 100644 --- a/action/action.yml +++ b/action/action.yml @@ -10,6 +10,7 @@ inputs: description: "File passed to the program." required: false + runs: using: composite steps: @@ -17,7 +18,12 @@ runs: uses: hustcer/setup-nu@v3 with: version: 0.114.1 - + + - name: Add .cargo/bin to PATH + shell: nu {0} + run: | + $"($env.HOME)/.cargo/bin" | save --append $env.GITHUB_PATH + - name: Install debtlint shell: nu {0} run: cargo install debtlint @@ -26,10 +32,11 @@ runs: shell: nu {0} working-directory: ${{ github.action_path }} run: npm install - + - name: Run debtlint shell: nu {0} env: - GITHUB_TOKEN: ${{ github.token }} + GITHUB_TOKEN: ${{ env.GITHUB_TOKEN }} working-directory: ${{ github.action_path }} - run: npx tsx ${{ github.action_path }}/main.ts \ No newline at end of file + run: | + npx tsx ${{ github.action_path }}/main.ts \ No newline at end of file diff --git a/action/main.ts b/action/main.ts index 837c69a..bb8ff7c 100644 --- a/action/main.ts +++ b/action/main.ts @@ -8,16 +8,13 @@ import { parsePullRequestContext } from "@/utils/convert" import { createPullRequestComments } from "@/api/routes"; async function run() { - //const GITHUB_TOKEN: string = process.env.GITHUB_TOKEN!; - //const octokit = getOctokit(GITHUB_TOKEN); - //const eventContext = parsePullRequestContext(context) + const GITHUB_TOKEN: string = process.env.GITHUB_TOKEN!; + const octokit = getOctokit(GITHUB_TOKEN); + const eventContext = parsePullRequestContext(context) const rawOutput = await execCommand('cargo', ['run', 'main.rs']); const diagnostics: Diagnostic[] = z.array(diagnosticSchema).parse(JSON.parse(rawOutput)); - - console.log("Diagnostic: ", diagnostics) - console.log("Ranges:") - //await createPullRequestComments(octokit, diagnostic, eventContext) + await createPullRequestComments(octokit, diagnostics, eventContext) } run() \ No newline at end of file diff --git a/action/src/api/routes.ts b/action/src/api/routes.ts index 5c105a4..6ba6f2b 100644 --- a/action/src/api/routes.ts +++ b/action/src/api/routes.ts @@ -1,24 +1,53 @@ -import { spawn } from 'child_process'; -import { getOctokit, context } from '@actions/github'; +import { readFile } from 'fs'; -import { Diagnostic } from '@/typings/diagnostic'; -import { PullRequestContext, Octokit } from '../typings/github'; +import { Diagnostic, Fragment } from '@/typings/diagnostic'; +import { PullRequestContext, Octokit } from '@/typings/github'; +async function getSuggestion(diagnostic: Diagnostic): Promise { + const workspace: string = process.env.GITHUB_WORKSPACE!; + let content: string = "\n## Debtlint suggestion\n" + + console.log("Workspace: ", workspace) + for (const range of diagnostic.ranges) { + readFile(range.source, 'utf-8', (err: NodeJS.ErrnoException | null, data: string) => { + if (err) console.error(err); + let fragment: string = "```" + range.source + const lines: string[] = data.split("/\r?\n/").slice(range.start.line, range.end.line) + for (const line of lines) { + fragment += line + } + content += (fragment + "```") + }); + } + return content; +} export async function createPullRequestComments(octokit: Octokit, diagnostics: Diagnostic[], context: PullRequestContext) { for (const diagnostic of diagnostics) { - for (const range of diagnostic.ranges) { - await octokit.request('POST /repos/{owner}/{repo}/issues/{issue_number}/comments', { - owner: context.owner, - repo: context.repo, - issue_number: context.issueNumber, - body: "**Debtlint suggestion**", - headers: { 'X-GitHub-Api-Version': '2026-03-10'} - }); - } + await octokit.request('POST /repos/{owner}/{repo}/issues/{issue_number}/comments', { + owner: context.owner, + repo: context.repo, + issue_number: context.issueNumber, + body: await getSuggestion(diagnostic), + headers: { 'X-GitHub-Api-Version': '2026-03-10'} + }); } } async function createThreadComments() {} +// +//### clang-format suggestion +// +//```suggestion +// raylib::Vector3 alignToWorldPlane(raylib::Vector3 vector) const; +//``` +//### clang-tidy diagnostics +//- function 'alignToWorldPlane' should be marked [[nodiscard]] [[modernize-use-nodiscard](https://clang.llvm.org/extra/clang-tidy/checks/modernize/use-nodiscard.html)] +// +//```suggestion +// [[nodiscard]] raylib::Vector3 alignToWorldPlane( +// raylib::Vector3 vector) const; +//``` + diff --git a/action/src/typings/diagnostic.ts b/action/src/typings/diagnostic.ts index b93b21e..cc26f41 100644 --- a/action/src/typings/diagnostic.ts +++ b/action/src/typings/diagnostic.ts @@ -1,12 +1,12 @@ import { z } from "zod"; const positionSchema = z.object({ - source: z.string(), line: z.number().min(0), character: z.number().min(0), }); -const rangeSchema = z.object({ +export const fragmentSchema = z.object({ + source: z.string(), start: positionSchema, end: positionSchema, }); @@ -14,8 +14,9 @@ const rangeSchema = z.object({ export const diagnosticSchema = z.object({ code: z.number().min(0), severity: z.string(), - ranges: z.array(rangeSchema), + ranges: z.array(fragmentSchema), description: z.string(), }) +export type Fragment = z.infer export type Diagnostic = z.infer \ No newline at end of file diff --git a/event.json b/event.json new file mode 100644 index 0000000..bfee8a6 --- /dev/null +++ b/event.json @@ -0,0 +1,16 @@ +{ + "pull_request": { + "number": 12, + "head": { + "ref": "test/debtlint-action", + "sha": "33048d2b243c75ca17a60276398dd8f419511220" + }, + "base": { + "ref": "main", + "sha": "bc2e984d32ecb1616d37386cf5c017ac5f5cb7bf" + } + }, + "repository": { + "full_name": "Rayan-ouer/plazza-mirror" + } +} \ No newline at end of file diff --git a/src/linter/diagnostic.rs b/src/linter/diagnostic.rs index 09b4c5b..549440e 100644 --- a/src/linter/diagnostic.rs +++ b/src/linter/diagnostic.rs @@ -2,13 +2,13 @@ use serde::Serialize; #[derive(Serialize, Debug)] pub struct Position { - pub source: String, pub line: u32, pub character: u32, } #[derive(Serialize, Debug)] pub struct Range { + pub source: String, pub start: Position, pub end: Position, } diff --git a/src/linter/runner.rs b/src/linter/runner.rs index 642f9ce..97c3b5a 100644 --- a/src/linter/runner.rs +++ b/src/linter/runner.rs @@ -7,26 +7,24 @@ pub fn get_duplicated() -> Vec { severity: String::from("low"), ranges: vec![ Range { + source: "src/Core.cpp".to_string(), start: Position { - source: "src/linter/runner.rs".to_string(), - line: 10, + line: 50, character: 1, }, end: Position { - source: "src/linter/runner.rs".to_string(), - line: 19, + line: 54, character: 1, }, }, Range { + source: "src/Kitchen.cpp".to_string(), start: Position { - source: "src/debug_run.rs".to_string(), - line: 10, + line: 31, character: 1, }, end: Position { - source: "src/debug_run.rs".to_string(), - line: 16, + line: 64, character: 1, }, }, @@ -38,26 +36,13 @@ pub fn get_duplicated() -> Vec { severity: String::from("high"), ranges: vec![ Range { + source: "src/Pizza.cpp".to_string(), start: Position { - source: "src/tokenizer/decode.rs".to_string(), - line: 10, + line: 3, character: 1, }, end: Position { - source: "src/tokenizer/decode.rs".to_string(), - line: 19, - character: 1, - }, - }, - Range { - start: Position { - source: "src/debug_run.rs".to_string(), - line: 10, - character: 1, - }, - end: Position { - source: "src/debug_run.rs".to_string(), - line: 16, + line: 8, character: 1, }, }, From 0e22ca257d0a4d0855a04bdc81612dab758772db Mon Sep 17 00:00:00 2001 From: rayan Date: Tue, 11 Aug 2026 04:02:07 +0200 Subject: [PATCH 53/59] feat: save act configuration and functional CI --- action/action.yml | 4 +--- action/src/api/routes.ts | 25 ++++++++++++++----------- action/src/typings/severity.ts | 0 src/linter/runner.rs | 33 ++++++++++++++++++++++----------- 4 files changed, 37 insertions(+), 25 deletions(-) create mode 100644 action/src/typings/severity.ts diff --git a/action/action.yml b/action/action.yml index 3e27d13..fa46219 100644 --- a/action/action.yml +++ b/action/action.yml @@ -37,6 +37,4 @@ runs: shell: nu {0} env: GITHUB_TOKEN: ${{ env.GITHUB_TOKEN }} - working-directory: ${{ github.action_path }} - run: | - npx tsx ${{ github.action_path }}/main.ts \ No newline at end of file + run: npx tsx --tsconfig action/tsconfig.json ${{ github.action_path }}/main.ts \ No newline at end of file diff --git a/action/src/api/routes.ts b/action/src/api/routes.ts index 6ba6f2b..d967e8a 100644 --- a/action/src/api/routes.ts +++ b/action/src/api/routes.ts @@ -1,24 +1,27 @@ -import { readFile } from 'fs'; +import { readFile } from "fs/promises"; import { Diagnostic, Fragment } from '@/typings/diagnostic'; import { PullRequestContext, Octokit } from '@/typings/github'; + async function getSuggestion(diagnostic: Diagnostic): Promise { - const workspace: string = process.env.GITHUB_WORKSPACE!; - let content: string = "\n## Debtlint suggestion\n" + let content = "\n## Debtlint suggestion\n"; + content += `### ${diagnostic.description}\n` - console.log("Workspace: ", workspace) for (const range of diagnostic.ranges) { - readFile(range.source, 'utf-8', (err: NodeJS.ErrnoException | null, data: string) => { - if (err) console.error(err); - let fragment: string = "```" + range.source - const lines: string[] = data.split("/\r?\n/").slice(range.start.line, range.end.line) + try { + const data = await readFile(range.source, "utf-8"); + let fragment = "```" + range.source.split(".").pop() + "\n"; + const lines = data.split(/\r?\n/).slice(range.start.line, range.end.line); for (const line of lines) { - fragment += line + fragment += line + "\n"; } - content += (fragment + "```") - }); + content += fragment + "```\n"; + } catch (err) { + console.error(`Error reading ${range.source}:`, err); + } } + console.log("Content:", content); return content; } diff --git a/action/src/typings/severity.ts b/action/src/typings/severity.ts new file mode 100644 index 0000000..e69de29 diff --git a/src/linter/runner.rs b/src/linter/runner.rs index 97c3b5a..403e618 100644 --- a/src/linter/runner.rs +++ b/src/linter/runner.rs @@ -7,47 +7,58 @@ pub fn get_duplicated() -> Vec { severity: String::from("low"), ranges: vec![ Range { - source: "src/Core.cpp".to_string(), + source: "src/linter/runner.rs".to_string(), start: Position { - line: 50, + line: 10, character: 1, }, end: Position { - line: 54, + line: 19, character: 1, }, }, Range { - source: "src/Kitchen.cpp".to_string(), + source: "src/debug_run.rs".to_string(), start: Position { - line: 31, + line: 10, character: 1, }, end: Position { - line: 64, + line: 16, character: 1, }, }, ], - description: String::from("Duplicate"), + description: String::from("This code can be refactorised."), }, Diagnostic { code: 2, severity: String::from("high"), ranges: vec![ Range { - source: "src/Pizza.cpp".to_string(), + source: "src/tokenizer/decode.rs".to_string(), start: Position { - line: 3, + line: 10, character: 1, }, end: Position { - line: 8, + line: 19, + character: 1, + }, + }, + Range { + source: "src/debug_run.rs".to_string(), + start: Position { + line: 10, + character: 1, + }, + end: Position { + line: 16, character: 1, }, }, ], - description: String::from("Duplicate code"), + description: String::from("This code is duplicated."), }, ] } From 17548d467bd3c36b493d88a0efad65f4db88ec04 Mon Sep 17 00:00:00 2001 From: rayan Date: Tue, 11 Aug 2026 04:11:49 +0200 Subject: [PATCH 54/59] refactor: det-21 remove act configuration to this branch --- Dockerfile | 5 ----- action/action.yml | 7 +------ action/src/api/routes.ts | 15 --------------- event.json | 16 ---------------- 4 files changed, 1 insertion(+), 42 deletions(-) delete mode 100644 Dockerfile delete mode 100644 event.json diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 007c691..0000000 --- a/Dockerfile +++ /dev/null @@ -1,5 +0,0 @@ -FROM catthehacker/ubuntu:act-latest - -ENV ACTIONS_RUNNER_FORCE_ACTIONS_NODE_VERSION=node20 - -RUN curl https://sh.rustup.rs -sSf | sh -s -- -y \ No newline at end of file diff --git a/action/action.yml b/action/action.yml index fa46219..83eed99 100644 --- a/action/action.yml +++ b/action/action.yml @@ -18,12 +18,7 @@ runs: uses: hustcer/setup-nu@v3 with: version: 0.114.1 - - - name: Add .cargo/bin to PATH - shell: nu {0} - run: | - $"($env.HOME)/.cargo/bin" | save --append $env.GITHUB_PATH - + - name: Install debtlint shell: nu {0} run: cargo install debtlint diff --git a/action/src/api/routes.ts b/action/src/api/routes.ts index d967e8a..3a6f865 100644 --- a/action/src/api/routes.ts +++ b/action/src/api/routes.ts @@ -21,7 +21,6 @@ async function getSuggestion(diagnostic: Diagnostic): Promise { console.error(`Error reading ${range.source}:`, err); } } - console.log("Content:", content); return content; } @@ -40,17 +39,3 @@ export async function createPullRequestComments(octokit: Octokit, diagnostics: D async function createThreadComments() {} -// -//### clang-format suggestion -// -//```suggestion -// raylib::Vector3 alignToWorldPlane(raylib::Vector3 vector) const; -//``` -//### clang-tidy diagnostics -//- function 'alignToWorldPlane' should be marked [[nodiscard]] [[modernize-use-nodiscard](https://clang.llvm.org/extra/clang-tidy/checks/modernize/use-nodiscard.html)] -// -//```suggestion -// [[nodiscard]] raylib::Vector3 alignToWorldPlane( -// raylib::Vector3 vector) const; -//``` - diff --git a/event.json b/event.json deleted file mode 100644 index bfee8a6..0000000 --- a/event.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "pull_request": { - "number": 12, - "head": { - "ref": "test/debtlint-action", - "sha": "33048d2b243c75ca17a60276398dd8f419511220" - }, - "base": { - "ref": "main", - "sha": "bc2e984d32ecb1616d37386cf5c017ac5f5cb7bf" - } - }, - "repository": { - "full_name": "Rayan-ouer/plazza-mirror" - } -} \ No newline at end of file From 19823f7fafe47f3492080274483702f1f1c7a154 Mon Sep 17 00:00:00 2001 From: rayan Date: Tue, 11 Aug 2026 04:12:55 +0200 Subject: [PATCH 55/59] refactor: det-21 uncomment main --- src/main.rs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/main.rs b/src/main.rs index 474b78b..a3580d7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,18 +10,18 @@ use debtlint::pipeline::{BpeConfig, run_bpe}; use ingestion::ingest_codebase; fn main() -> std::io::Result<()> { - //let args = Args::parse(); - //let cfg = get_config(); - //let files = ingest_codebase(cfg); - // - //let _result = run_bpe( - // &files, - // BpeConfig { - // vocab_size: args.vocab_size, - // min_frequency: args.min_frequency, - // }, - // args.load_vocab.as_deref(), - //)?; + let args = Args::parse(); + let cfg = get_config(); + let files = ingest_codebase(cfg); + + let _result = run_bpe( + &files, + BpeConfig { + vocab_size: args.vocab_size, + min_frequency: args.min_frequency, + }, + args.load_vocab.as_deref(), + )?; let _ = run_linter(); Ok(()) } From ee0d7aa53d921c220921860945a77eb440d1937c Mon Sep 17 00:00:00 2001 From: rayan Date: Tue, 11 Aug 2026 04:13:59 +0200 Subject: [PATCH 56/59] refactor: det-21 format with rustfmt --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index a3580d7..142e47b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,7 +13,7 @@ fn main() -> std::io::Result<()> { let args = Args::parse(); let cfg = get_config(); let files = ingest_codebase(cfg); - + let _result = run_bpe( &files, BpeConfig { From a646fd8563ea401d201dfad0d3f17c19bf24f061 Mon Sep 17 00:00:00 2001 From: rayan Date: Tue, 11 Aug 2026 04:15:57 +0200 Subject: [PATCH 57/59] refactor: det-21 replave env.GITHUB_TOKEN by native token runner variable --- action/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action/action.yml b/action/action.yml index 83eed99..6a2ad44 100644 --- a/action/action.yml +++ b/action/action.yml @@ -31,5 +31,5 @@ runs: - name: Run debtlint shell: nu {0} env: - GITHUB_TOKEN: ${{ env.GITHUB_TOKEN }} + GITHUB_TOKEN: ${{ github.token }} run: npx tsx --tsconfig action/tsconfig.json ${{ github.action_path }}/main.ts \ No newline at end of file From 73d3b321bb1b7f69e6b680bef2322a1b81308209 Mon Sep 17 00:00:00 2001 From: rayan Date: Mon, 24 Aug 2026 22:10:38 +0200 Subject: [PATCH 58/59] feat: det-21 handle new inputs in jobs file --- action/action.yml | 15 +++++++++++---- action/main.ts | 1 + 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/action/action.yml b/action/action.yml index 6a2ad44..9f8d9f3 100644 --- a/action/action.yml +++ b/action/action.yml @@ -6,10 +6,17 @@ branding: color: "green" inputs: - files: - description: "File passed to the program." + config-path: + description: "Debtlint configuration file." + required: false + + vocab-path: + description: "Debtlint vocabulary. If speficied Debtlint will run with the ```--load-vocab``` flag." + required: false + + extensions: + description: "The file extensions to run Debtlint against. This is a comma-separated string." required: false - runs: using: composite @@ -18,7 +25,7 @@ runs: uses: hustcer/setup-nu@v3 with: version: 0.114.1 - + - name: Install debtlint shell: nu {0} run: cargo install debtlint diff --git a/action/main.ts b/action/main.ts index bb8ff7c..acb9b00 100644 --- a/action/main.ts +++ b/action/main.ts @@ -12,6 +12,7 @@ async function run() { const octokit = getOctokit(GITHUB_TOKEN); const eventContext = parsePullRequestContext(context) + console.log(context) const rawOutput = await execCommand('cargo', ['run', 'main.rs']); const diagnostics: Diagnostic[] = z.array(diagnosticSchema).parse(JSON.parse(rawOutput)); await createPullRequestComments(octokit, diagnostics, eventContext) From 9f9da50928a5cd7a814529f9da0de3035e404bc4 Mon Sep 17 00:00:00 2001 From: rayan Date: Tue, 25 Aug 2026 01:31:16 +0200 Subject: [PATCH 59/59] feat: det-21 add generic function to handle argument properly in ci --- .github/workflows/debtlint.yml | 3 ++- action/action.yml | 2 +- action/main.ts | 8 ++++++-- action/src/utils/flags.ts | 6 ++++++ 4 files changed, 15 insertions(+), 4 deletions(-) create mode 100644 action/src/utils/flags.ts diff --git a/.github/workflows/debtlint.yml b/.github/workflows/debtlint.yml index 9aadf9a..dee260a 100644 --- a/.github/workflows/debtlint.yml +++ b/.github/workflows/debtlint.yml @@ -14,4 +14,5 @@ jobs: - name: Run debtlint uses: ./action with: - files: "src" \ No newline at end of file + vocab-path: fixtures/sample.vocab.json + extensions: 'rs, py' \ No newline at end of file diff --git a/action/action.yml b/action/action.yml index 9f8d9f3..e0f93b5 100644 --- a/action/action.yml +++ b/action/action.yml @@ -25,7 +25,7 @@ runs: uses: hustcer/setup-nu@v3 with: version: 0.114.1 - + - name: Install debtlint shell: nu {0} run: cargo install debtlint diff --git a/action/main.ts b/action/main.ts index acb9b00..fcb3ab7 100644 --- a/action/main.ts +++ b/action/main.ts @@ -2,7 +2,9 @@ import { z } from "zod"; import { Diagnostic, diagnosticSchema } from '@/typings/diagnostic'; import { getOctokit, context } from '@actions/github'; +import { getInput } from "@actions/core"; +import { addOption } from "@/utils/flags"; import { execCommand } from "@/utils/executor" import { parsePullRequestContext } from "@/utils/convert" import { createPullRequestComments } from "@/api/routes"; @@ -12,8 +14,10 @@ async function run() { const octokit = getOctokit(GITHUB_TOKEN); const eventContext = parsePullRequestContext(context) - console.log(context) - const rawOutput = await execCommand('cargo', ['run', 'main.rs']); + const args: string[] = []; + addOption(args, "--load-vocab", getInput("config-path")); + + const rawOutput = await execCommand('cargo', ['run', 'main.rs'].concat(args)); const diagnostics: Diagnostic[] = z.array(diagnosticSchema).parse(JSON.parse(rawOutput)); await createPullRequestComments(octokit, diagnostics, eventContext) } diff --git a/action/src/utils/flags.ts b/action/src/utils/flags.ts new file mode 100644 index 0000000..63a00c1 --- /dev/null +++ b/action/src/utils/flags.ts @@ -0,0 +1,6 @@ +export function addOption(args: string[], flag: string, value: string): void +{ + if (value) { + args.push(flag, value); + } +}