walkdiff 0.7.0 → 0.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -1
- package/README.md +2 -2
- package/package.json +1 -1
- package/walkdiff.mjs +74 -15
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
-
##
|
|
3
|
+
## 0.7.2
|
|
4
|
+
|
|
5
|
+
- **`walkdiff --version`:** shows which Walkdiff runs, and every error now ends with the version, such as `(walkdiff 0.7.2)`, so a pasted error says which release it came from. The troubleshooting guide covers "transport 'ssh' not allowed" and how to find which Walkdiff runs when several are installed.
|
|
6
|
+
- **No duplicate-code warnings on migrations:** migration files, such as db-migrate's, repeat the same template by design and must not share code, so duplicate detection now leaves them out. Rails' `db/migrate/` now also counts as a database migration for the sensitive-path check, as it already did for breaking changes.
|
|
7
|
+
|
|
8
|
+
## 0.7.1
|
|
9
|
+
|
|
10
|
+
- **Works with git configs that route https to ssh:** a `url.*.insteadOf` rule that sends `https://gitlab.com/` or `https://github.com/` to ssh, common for cargo or go with private repositories, made reviews fail with "transport 'ssh' not allowed". Walkdiff's own fetch now stays on https with its token, and the rule still applies to everything else.
|
|
4
11
|
|
|
5
12
|
## 0.7.0
|
|
6
13
|
|
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
A review companion for GitHub pull requests and GitLab merge requests. `walkdiff review <url>` fetches the
|
|
6
6
|
change, analyzes it, and serves a local report. (Working name; the project name is still an open decision.)
|
|
7
7
|
|
|
8
|
-
Status: early release, [v0.7.
|
|
8
|
+
Status: early release, [v0.7.2](CHANGELOG.md). To run it on your team's PRs, see the [pilot guide](docs/pilot.md).
|
|
9
9
|
|
|
10
10
|
**Documentation:** [getting started](docs/getting-started.md), [configuration](docs/configuration.md), [troubleshooting](docs/troubleshooting.md), [security policy](SECURITY.md).
|
|
11
11
|
|
|
@@ -98,7 +98,7 @@ Tokens and code stay on your machine, apart from the host itself, package names
|
|
|
98
98
|
|
|
99
99
|
## In CI
|
|
100
100
|
|
|
101
|
-
The GitHub Action (`navasvarela/walkdiff@v0.7.
|
|
101
|
+
The GitHub Action (`navasvarela/walkdiff@v0.7.2`) and the GitLab template (`ci/gitlab-ci.yml`) generate the report for each PR, keep it as a job artifact, and post one summary comment that is updated on each push. The [pilot guide](docs/pilot.md) has the setup. Locally, `walkdiff review` also works without a URL inside a CI job, and `walkdiff comment --report <dir> --report-url <url>` posts the summary.
|
|
102
102
|
|
|
103
103
|
## AI review
|
|
104
104
|
|
package/package.json
CHANGED
package/walkdiff.mjs
CHANGED
|
@@ -8,7 +8,7 @@ import { z } from "zod";
|
|
|
8
8
|
import { createHash, randomBytes } from "node:crypto";
|
|
9
9
|
import { Language, Parser } from "web-tree-sitter";
|
|
10
10
|
import { homedir, tmpdir } from "node:os";
|
|
11
|
-
import { existsSync } from "node:fs";
|
|
11
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
12
12
|
import { parse } from "smol-toml";
|
|
13
13
|
import Anthropic from "@anthropic-ai/sdk";
|
|
14
14
|
import { betaZodOutputFormat } from "@anthropic-ai/sdk/helpers/beta/zod";
|
|
@@ -107,7 +107,7 @@ async function fetchCommits(request) {
|
|
|
107
107
|
...refspecs
|
|
108
108
|
], {
|
|
109
109
|
cwd: repoDir,
|
|
110
|
-
env:
|
|
110
|
+
env: fetchEnv(request.cloneUrl, request.credentials)
|
|
111
111
|
});
|
|
112
112
|
const stillMissing = await missingCommits(repoDir, missing);
|
|
113
113
|
if (stillMissing.length > 0) throw new MissingCommitsError(stillMissing, request.cloneUrl);
|
|
@@ -136,18 +136,33 @@ async function missingCommits(repoDir, commits) {
|
|
|
136
136
|
return commits.filter((_, index) => present.at(index) !== true);
|
|
137
137
|
}
|
|
138
138
|
const ALLOWED_PROTOCOLS = "https:http";
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
139
|
+
/**
|
|
140
|
+
* The fetch keeps the person's git config, for proxies and credential helpers, with three
|
|
141
|
+
* additions:
|
|
142
|
+
* - A rewrite of the clone URL to itself. People route https to ssh with `url.*.insteadOf`,
|
|
143
|
+
* for cargo or go with private repositories, and that rewrite would carry this fetch to a
|
|
144
|
+
* transport ALLOWED_PROTOCOLS refuses. Git applies the longest matching `insteadOf`, and
|
|
145
|
+
* the full URL is longer than any prefix rule that matches it, so this one wins and the
|
|
146
|
+
* fetch stays on https, with its token.
|
|
147
|
+
* - The token as an `Authorization` header, through GIT_CONFIG_* variables rather than `-c`
|
|
148
|
+
* arguments or the remote URL, which keeps it out of `ps` output and the repository's config.
|
|
149
|
+
* - No redirects, because git would send that header to wherever one points.
|
|
150
|
+
*/
|
|
151
|
+
function fetchEnv(cloneUrl, credentials) {
|
|
152
|
+
const entries = [[`url.${cloneUrl}.insteadOf`, cloneUrl]];
|
|
153
|
+
if (credentials !== void 0) {
|
|
154
|
+
const basic = Buffer.from(`${credentials.username}:${credentials.token}`).toString("base64");
|
|
155
|
+
entries.push(["http.extraHeader", `Authorization: Basic ${basic}`], ["http.followRedirects", "false"]);
|
|
156
|
+
}
|
|
142
157
|
return {
|
|
143
158
|
GIT_ALLOW_PROTOCOL: ALLOWED_PROTOCOLS,
|
|
144
|
-
|
|
145
|
-
GIT_CONFIG_KEY_0: "http.extraHeader",
|
|
146
|
-
GIT_CONFIG_VALUE_0: `Authorization: Basic ${basic}`,
|
|
147
|
-
GIT_CONFIG_KEY_1: "http.followRedirects",
|
|
148
|
-
GIT_CONFIG_VALUE_1: "false"
|
|
159
|
+
...configEnv(entries)
|
|
149
160
|
};
|
|
150
161
|
}
|
|
162
|
+
function configEnv(entries) {
|
|
163
|
+
const numbered = entries.flatMap(([key, value], index) => [[`GIT_CONFIG_KEY_${index}`, key], [`GIT_CONFIG_VALUE_${index}`, value]]);
|
|
164
|
+
return Object.fromEntries([["GIT_CONFIG_COUNT", String(entries.length)], ...numbered]);
|
|
165
|
+
}
|
|
151
166
|
async function exists(path) {
|
|
152
167
|
try {
|
|
153
168
|
await access(path);
|
|
@@ -3246,6 +3261,16 @@ async function pythonSurface(repository, paths) {
|
|
|
3246
3261
|
return (!manifest.endsWith("pyproject.toml") || PYPROJECT_BUILDS.test(texts.get(manifest) ?? "")) && listedInDunderAll(texts.get(path), name);
|
|
3247
3262
|
};
|
|
3248
3263
|
}
|
|
3264
|
+
// packages/engine/src/risk/migrationFiles.ts
|
|
3265
|
+
/**
|
|
3266
|
+
* Where frameworks keep database migrations: `migrations/` for db-migrate, knex, Sequelize,
|
|
3267
|
+
* TypeORM, Django and most others, `alembic/versions/` for Alembic, and `db/migrate/` and
|
|
3268
|
+
* `db/post_migrate/` for Rails and GitLab.
|
|
3269
|
+
*/
|
|
3270
|
+
const MIGRATION_PATH = /(^|\/)migrations?\/|(^|\/)alembic\/versions\/|(^|\/)db\/(?:post_)?migrate\//;
|
|
3271
|
+
function isMigrationPath(path) {
|
|
3272
|
+
return MIGRATION_PATH.test(path);
|
|
3273
|
+
}
|
|
3249
3274
|
// packages/engine/src/risk/breaking/migrations.ts
|
|
3250
3275
|
const SchemaChangeKind = {
|
|
3251
3276
|
DropTable: "dropTable",
|
|
@@ -3254,7 +3279,6 @@ const SchemaChangeKind = {
|
|
|
3254
3279
|
RenameColumn: "renameColumn",
|
|
3255
3280
|
ChangeType: "changeType"
|
|
3256
3281
|
};
|
|
3257
|
-
const MIGRATION_FILE = /(^|\/)migrations?\/|(^|\/)alembic\/versions\/|(^|\/)db\/(?:post_)?migrate\//;
|
|
3258
3282
|
const DOWN_FILE = /\.down\.sql$|(^|\/)U\d[^/]*\.sql$/i;
|
|
3259
3283
|
const DOWN_SECTION = /\bdef\s+down(?:grade)?\b|\bdown\s*[(:=]|\bexports\.down\b|\+goose\s+Down|\+migrate\s+Down|migrate:down/i;
|
|
3260
3284
|
const UP_SECTION = /\bdef\s+(?:up(?:grade)?|change)\b|\bup\s*[(:=]|\bexports\.up\b|\+goose\s+Up|\+migrate\s+Up|migrate:up/i;
|
|
@@ -3445,7 +3469,7 @@ function changeOnLine(lines, index) {
|
|
|
3445
3469
|
}
|
|
3446
3470
|
function isMigration(file) {
|
|
3447
3471
|
const { path, status } = file.diff;
|
|
3448
|
-
return status !== FileChangeStatus.Deleted &&
|
|
3472
|
+
return status !== FileChangeStatus.Deleted && isMigrationPath(path) && !DOWN_FILE.test(path) && !isTestPath(path) && !isThirdParty(file);
|
|
3449
3473
|
}
|
|
3450
3474
|
/** Names this PR's migrations bring into being, which nothing outside the PR can depend on yet. */
|
|
3451
3475
|
function namesCreatedInThisChange(migrations) {
|
|
@@ -6147,13 +6171,13 @@ function runProblem(result, okExitCodes, scanner) {
|
|
|
6147
6171
|
*/
|
|
6148
6172
|
async function runJscpd(request, candidates, workspace) {
|
|
6149
6173
|
if (request.disabled?.has(JSCPD.id)) return notRun(JSCPD.check, TURNED_OFF_IN_SETTINGS);
|
|
6150
|
-
const reviewable = candidates.filter((file) =>
|
|
6174
|
+
const reviewable = candidates.filter((file) => isDuplicationCandidate(file.diff.path) && hasAddedLines(file));
|
|
6151
6175
|
if (reviewable.length === 0) return {
|
|
6152
6176
|
findings: [],
|
|
6153
6177
|
checksRun: [],
|
|
6154
6178
|
notChecked: []
|
|
6155
6179
|
};
|
|
6156
|
-
const sources = (await listSourceFiles(request.repoDir, request.head)).filter((path) =>
|
|
6180
|
+
const sources = (await listSourceFiles(request.repoDir, request.head)).filter((path) => isDuplicationCandidate(path) && !request.isIgnored(path) && !CONFIG_LIKE_FILE.test(basename(path)));
|
|
6157
6181
|
if (sources.length > MAX_DUPLICATION_SOURCE_FILES) return notRun(JSCPD.check, `the repository has more than ${MAX_DUPLICATION_SOURCE_FILES} source files`);
|
|
6158
6182
|
const root = await prepareScanRoot(workspace, JSCPD.name, []);
|
|
6159
6183
|
await copySources(request, sources, root);
|
|
@@ -6173,6 +6197,15 @@ async function runJscpd(request, candidates, workspace) {
|
|
|
6173
6197
|
return notRun(JSCPD.check, `its report could not be read: ${messageOf(error)}`);
|
|
6174
6198
|
}
|
|
6175
6199
|
}
|
|
6200
|
+
/**
|
|
6201
|
+
* Tests repeat setup on purpose. Migrations are written from a template, such as db-migrate's
|
|
6202
|
+
* `setup`, `up` and `down`, and are frozen once run, so copying code into one rather than
|
|
6203
|
+
* importing it is right: the migration must not change when the app does. Either would make
|
|
6204
|
+
* every new file look like a copy of the last.
|
|
6205
|
+
*/
|
|
6206
|
+
function isDuplicationCandidate(path) {
|
|
6207
|
+
return !isTestPath(path) && !isMigrationPath(path);
|
|
6208
|
+
}
|
|
6176
6209
|
async function copySources(request, paths, root) {
|
|
6177
6210
|
for (let start = 0; start < paths.length; start += SCAN_BATCH_FILES) {
|
|
6178
6211
|
const batch = paths.slice(start, start + SCAN_BATCH_FILES);
|
|
@@ -6251,7 +6284,7 @@ const BUILT_IN_RULES = [
|
|
|
6251
6284
|
pathRule("path.auth", RiskSeverity.Medium, new RegExp(`${SEGMENT}(auth|authn|authz|login|session|sessions|oauth|sso|permissions?|acl|rbac|access[_-]?control)${END}`, "i"), "Authentication or authorization", "A mistake here can let users act as someone else or reach data they should not."),
|
|
6252
6285
|
pathRule("path.crypto", RiskSeverity.Medium, new RegExp(`${SEGMENT}(crypto|cryptography|encrypt|encryption|cipher|signing|signature|jwt|keys?tore)${END}`, "i"), "Cryptography", "Subtle errors in cryptographic code rarely show in tests; check algorithms, key handling and randomness."),
|
|
6253
6286
|
pathRule("path.payments", RiskSeverity.Medium, new RegExp(`${SEGMENT}(payments?|billing|invoices?|stripe)${END}`, "i"), "Payments or billing", "Errors here cost money directly; check amounts, currencies and idempotency."),
|
|
6254
|
-
pathRule("path.migration", RiskSeverity.Medium,
|
|
6287
|
+
pathRule("path.migration", RiskSeverity.Medium, MIGRATION_PATH, "Database migration", "Migrations change production data and can be slow or irreversible; check locking and rollback."),
|
|
6255
6288
|
pathRule("path.infrastructure", RiskSeverity.Low, /\.tf$|(^|\/)Dockerfile[^/]*$|(^|\/)docker-compose[^/]*\.ya?ml$|(^|\/)(k8s|kubernetes|helm|charts)\//, "Infrastructure or deployment", "Changes the environment the code runs in: exposure, permissions and resource limits.")
|
|
6256
6289
|
];
|
|
6257
6290
|
/** One finding per file: team rules from the config first, then the first built-in rule that matches. */
|
|
@@ -9104,6 +9137,7 @@ Options:
|
|
|
9104
9137
|
--report <dir> With comment: the directory review wrote (--out)
|
|
9105
9138
|
--report-url <url> With comment: where reviewers can open the report
|
|
9106
9139
|
-h, --help Show this help
|
|
9140
|
+
-v, --version Show which Walkdiff this is
|
|
9107
9141
|
|
|
9108
9142
|
Environment:
|
|
9109
9143
|
GITHUB_TOKEN, GH_TOKEN Token for GitHub (required for private repositories)
|
|
@@ -9157,10 +9191,16 @@ function parseCommand(argv) {
|
|
|
9157
9191
|
type: "boolean",
|
|
9158
9192
|
short: "h",
|
|
9159
9193
|
default: false
|
|
9194
|
+
},
|
|
9195
|
+
version: {
|
|
9196
|
+
type: "boolean",
|
|
9197
|
+
short: "v",
|
|
9198
|
+
default: false
|
|
9160
9199
|
}
|
|
9161
9200
|
}
|
|
9162
9201
|
});
|
|
9163
9202
|
const [command, url, ...extra] = positionals;
|
|
9203
|
+
if (values.version) return { kind: "version" };
|
|
9164
9204
|
if (values.help || command === void 0) return { kind: "help" };
|
|
9165
9205
|
if (command === "setup") {
|
|
9166
9206
|
if (url !== void 0) throw new UsageError(`Unexpected arguments: ${[url, ...extra].join(" ")}`);
|
|
@@ -10541,6 +10581,13 @@ async function runComment(options, deps) {
|
|
|
10541
10581
|
deps.log(`Could not post the summary comment (this token may be read-only): ${error.message}`);
|
|
10542
10582
|
}
|
|
10543
10583
|
}
|
|
10584
|
+
// packages/cli/src/version.ts
|
|
10585
|
+
const MANIFEST_PATH = firstExisting([resolve(import.meta.dirname, "package.json"), resolve(import.meta.dirname, "../../../package.json")]);
|
|
10586
|
+
const manifestSchema = z.object({ version: z.string().min(1) });
|
|
10587
|
+
/** The running Walkdiff's version, read from its package.json. */
|
|
10588
|
+
function walkdiffVersion(manifestPath = MANIFEST_PATH) {
|
|
10589
|
+
return manifestSchema.parse(JSON.parse(readFileSync(manifestPath, "utf8"))).version;
|
|
10590
|
+
}
|
|
10544
10591
|
// packages/cli/src/main.ts
|
|
10545
10592
|
const EXIT_FAILURE = 1;
|
|
10546
10593
|
const EXIT_USAGE = 2;
|
|
@@ -10553,6 +10600,9 @@ async function main(argv) {
|
|
|
10553
10600
|
case "help":
|
|
10554
10601
|
console.log(USAGE);
|
|
10555
10602
|
return;
|
|
10603
|
+
case "version":
|
|
10604
|
+
console.log(`walkdiff ${walkdiffVersion()}`);
|
|
10605
|
+
return;
|
|
10556
10606
|
case "setup":
|
|
10557
10607
|
await installScannersHere((message) => console.error(message));
|
|
10558
10608
|
console.error(`Scanners are ready in ${MANAGED_SCANNERS_ROOT}.`);
|
|
@@ -10592,6 +10642,15 @@ main(process.argv.slice(2)).catch((error) => {
|
|
|
10592
10642
|
return;
|
|
10593
10643
|
}
|
|
10594
10644
|
console.error(error instanceof Error ? `${error.name}: ${error.message}` : String(error));
|
|
10645
|
+
console.error(versionLine());
|
|
10595
10646
|
process.exitCode = EXIT_FAILURE;
|
|
10596
10647
|
});
|
|
10648
|
+
/** Names the version in every failure, so a report of one says which Walkdiff it came from. */
|
|
10649
|
+
function versionLine() {
|
|
10650
|
+
try {
|
|
10651
|
+
return `(walkdiff ${walkdiffVersion()})`;
|
|
10652
|
+
} catch {
|
|
10653
|
+
return "(walkdiff, version unknown)";
|
|
10654
|
+
}
|
|
10655
|
+
}
|
|
10597
10656
|
export {};
|