@tisankan/slop-check 0.0.0-stage → 1.0.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Tisankan Jeyakumar
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,223 @@
1
- # Temporary Holding Version
1
+ # slop-check
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [![slop score](https://img.shields.io/badge/slop_score-0-brightgreen)](https://github.com/tisankanj/slop-check)
4
+ [![ci](https://github.com/tisankanj/slop-check/actions/workflows/ci.yml/badge.svg)](https://github.com/tisankanj/slop-check/actions/workflows/ci.yml)
5
+ [![npm](https://img.shields.io/npm/v/@tisankan/slop-check)](https://www.npmjs.com/package/@tisankan/slop-check)
6
+ [![license](https://img.shields.io/badge/license-MIT-blue)](LICENSE)
7
+
8
+ **Catch AI slop in your diff before your reviewer does.**
9
+
10
+ AI writes code fast, and it leaves things behind: swallowed errors,
11
+ `// ... existing code ...` pasted from a chat, comments that narrate the edit,
12
+ `as any`, debug logs. slop-check reads only the lines you added, flags those
13
+ leftovers with a one-line reason, and gives the change one number: the slop score.
14
+
15
+ ![slop-check output on a 16-line change: 10 findings, slop score 100, Pure slop](docs/demo.png)
16
+
17
+ <details>
18
+ <summary>The 16 lines behind this screenshot</summary>
19
+
20
+ ```ts
21
+ import { db } from './db';
22
+
23
+ // Get user by id
24
+ export async function getUserById(id: string) {
25
+ try {
26
+ const user = await db.users.find(id);
27
+ console.log('user:', user);
28
+ return user;
29
+ } catch (error) {}
30
+ }
31
+
32
+ // Updated to use the new cache API
33
+ export function saveUser(user: any) {
34
+ // ... existing code ...
35
+ console.log('✅ User saved');
36
+ }
37
+
38
+ // In a real application you would rotate this key
39
+ const apiKey = 'your-api-key-here';
40
+ ```
41
+
42
+ Commit message: `feat: supercharge user caching`. <!-- slop-check-ignore -->
43
+
44
+ </details>
45
+
46
+ ## Try it
47
+
48
+ Run it inside any git repo, on any branch. No config, no dependencies, no API keys.
49
+
50
+ ```bash
51
+ npx @tisankan/slop-check
52
+ ```
53
+
54
+ It compares your branch with `main` (or `master`, or `origin/HEAD`) and includes
55
+ uncommitted changes to tracked files. New files count once you `git add` them.
56
+ Needs Node.js 20 or newer. To install it once: `npm i -g @tisankan/slop-check`,
57
+ then run `slop-check`.
58
+
59
+ ```bash
60
+ npx @tisankan/slop-check --all # every tracked file
61
+ npx @tisankan/slop-check --staged # staged changes, for a git hook
62
+ npx @tisankan/slop-check develop # compare with another base
63
+ ```
64
+
65
+ ## What's your repo's slop score?
66
+
67
+ ```bash
68
+ npx @tisankan/slop-check --all --badge
69
+ ```
70
+
71
+ That prints a badge for your README, like the one at the top of this page:
72
+
73
+ ```markdown
74
+ [![slop score](https://img.shields.io/badge/slop_score-0-brightgreen)](https://github.com/tisankanj/slop-check)
75
+ ```
76
+
77
+ | Score | Label |
78
+ | --- | --- |
79
+ | 0 | Hand-written |
80
+ | 1 to 10 | Mostly human |
81
+ | 11 to 30 | Needs a once-over |
82
+ | 31 to 60 | Sloppy |
83
+ | 61 to 100 | Pure slop |
84
+
85
+ The score is slop points per 100 added lines, capped at 100. A high finding is
86
+ worth 5 points, a medium one 3, a low one 1. Changes under 20 lines count as 20,
87
+ so one small slip does not score like a disaster.
88
+
89
+ ## Check every pull request
90
+
91
+ ```yaml
92
+ # .github/workflows/slop-check.yml
93
+ name: slop-check
94
+ on: pull_request
95
+
96
+ permissions:
97
+ contents: read
98
+ pull-requests: write
99
+
100
+ jobs:
101
+ slop-check:
102
+ runs-on: ubuntu-latest
103
+ steps:
104
+ - uses: actions/checkout@v7
105
+ with:
106
+ fetch-depth: 0
107
+ - uses: tisankanj/slop-check@v1
108
+ with:
109
+ max-score: 30
110
+ ```
111
+
112
+ The action writes the report to the job summary and keeps one comment on the
113
+ pull request up to date.
114
+
115
+ | Input | Default | What it does |
116
+ | --- | --- | --- |
117
+ | `max-score` | empty | Fail the job when the score is above this number. Empty never fails. |
118
+ | `comment` | `true` | Post one PR comment and update it on every push. |
119
+ | `github-token` | `github.token` | Token used for the comment. |
120
+
121
+ Output: `score`. Pull requests from forks get a read-only token, so they get the
122
+ job summary but no comment.
123
+
124
+ ## Rules
125
+
126
+ | Rule | Weight | Catches |
127
+ | --- | --- | --- |
128
+ | `empty-catch` | high | `catch (e) {}` and `except: pass` |
129
+ | `placeholder-code` | high | `// ... existing code ...`, `// TODO: implement` |
130
+ | `catch-rethrow` | medium | A catch block that only rethrows |
131
+ | `debug-leftover` | medium | `debugger`, `console.log('user:', user)`, `breakpoint()` |
132
+ | `type-escape` | medium | `as any`, `: any`, `@ts-ignore`, bare `# type: ignore` |
133
+ | `change-history-comment` | medium | `// Updated to use ...`, `// Added error handling` |
134
+ | `narration-comment` | medium | `// Let me ...`, `// I've added ...`, `// As requested` |
135
+ | `disclaimer-comment` | medium | `// In a real application you would ...` |
136
+ | `placeholder-value` | medium | `'your-api-key-here'`, `YOUR_API_KEY`, `REPLACE_ME` |
137
+ | `restating-comment` | low | `// get user by id` above `getUserById(id)` |
138
+ | `emoji-in-code` | low | Emoji in log calls and at the start of comments |
139
+ | `buzzword` | low | Brochure phrases in comments, docs and commit messages |
140
+ | `em-dash` | low | The em dash character. **Off by default.** |
141
+ | `ai-attribution` | high | Tool credit lines in commits. **Off by default.** |
142
+
143
+ Every rule, with bad and good examples: [docs/rules.md](docs/rules.md).
144
+
145
+ ## Quiet on human code
146
+
147
+ Before release, every rule ran against express, requests, cobra and ky: about
148
+ 83,000 lines of code written by people. Any rule that fired on normal human code
149
+ more than once in ten was narrowed or switched off. On those four repos the
150
+ default rules now report 23 findings in total, almost all of them real restating
151
+ comments and real `as any` casts.
152
+
153
+ If slop-check flags something a careful person wrote on purpose, that is a bug.
154
+ Please [open an issue](https://github.com/tisankanj/slop-check/issues) with the line.
155
+
156
+ ## Anti-slop, not anti-AI
157
+
158
+ slop-check does not try to guess whether AI wrote your code, and it does not care.
159
+ It flags leftovers a reviewer would ask you to remove, whoever typed them. That is
160
+ also why AI credit lines in commits are off by default: many teams require them.
161
+
162
+ ## Config
163
+
164
+ Optional `.slopcheckrc.json` in the repo root. Command line flags win over it.
165
+
166
+ ```json
167
+ {
168
+ "rules": { "em-dash": "on", "restating-comment": "off" },
169
+ "ignore": ["docs/legacy/**", "**/*.generated.ts"],
170
+ "maxScore": 30
171
+ }
172
+ ```
173
+
174
+ `ignore` takes `**`, `*` and `?`. Dependencies, build output, lockfiles and
175
+ minified files are skipped already. Add `slop-check-ignore` anywhere on a line to
176
+ skip that line.
177
+
178
+ ## Git hook
179
+
180
+ ```bash
181
+ # .git/hooks/pre-commit
182
+ npx --yes @tisankan/slop-check --staged --max-score 30
183
+ ```
184
+
185
+ ## All options
186
+
187
+ ```text
188
+ slop-check [base] check the current branch against base
189
+ --staged check staged changes only
190
+ --all check every tracked file
191
+ --json print JSON instead of text
192
+ --badge print a README badge for this score
193
+ --max-score <n> exit 1 if the score is above n
194
+ --list-rules print every rule with its weight and status
195
+ --no-color plain output (NO_COLOR is also respected)
196
+ -h, --help show help
197
+ -v, --version show the version
198
+ ```
199
+
200
+ Exit codes: `0` done, `1` score above `--max-score`, `2` usage or git error.
201
+
202
+ `--json` prints `{ score, label, base, mode, files, addedLines, findings }`. Each
203
+ finding has `rule`, `weight`, `message`, and either `file` and `line` or `commit`.
204
+
205
+ ## Contributing
206
+
207
+ False positives are the most useful thing you can report.
208
+ [CONTRIBUTING.md](CONTRIBUTING.md) explains how to run the tests and add a rule,
209
+ and there are [good first issues](https://github.com/tisankanj/slop-check/labels/good%20first%20issue)
210
+ ready to pick up.
211
+
212
+ A new rule is one object in [src/rules.js](src/rules.js), a test file with
213
+ "flags" and "does not flag" cases, a section in [docs/rules.md](docs/rules.md), and
214
+ a run against a few human-written repos to show it stays quiet. `node --test` runs
215
+ everything. Zero dependencies is on purpose; please keep it that way.
216
+
217
+ This repo checks itself on every pull request with `max-score: 0`. Its test
218
+ fixtures and `docs/rules.md` are full of slop on purpose, so
219
+ [.slopcheckrc.json](.slopcheckrc.json) ignores them.
220
+
221
+ ## License
222
+
223
+ [MIT](LICENSE). Made by [Tisankan Jeyakumar](https://github.com/tisankanj).
package/action.yml ADDED
@@ -0,0 +1,25 @@
1
+ name: slop-check
2
+ description: Catch AI slop in your diff before your reviewer does.
3
+ author: Tisankan Jeyakumar
4
+ branding:
5
+ icon: filter
6
+ color: green
7
+ inputs:
8
+ max-score:
9
+ description: Fail the job when the slop score is above this number (0 to 100). Leave empty to never fail.
10
+ required: false
11
+ default: ''
12
+ comment:
13
+ description: Post one PR comment with the score and keep it updated. Set to false to only write the job summary.
14
+ required: false
15
+ default: 'true'
16
+ github-token:
17
+ description: Token used to post the PR comment.
18
+ required: false
19
+ default: ${{ github.token }}
20
+ outputs:
21
+ score:
22
+ description: The slop score, from 0 to 100.
23
+ runs:
24
+ using: node24
25
+ main: src/action-main.js
@@ -0,0 +1,147 @@
1
+ #!/usr/bin/env node
2
+ import { readFileSync } from 'node:fs';
3
+ import { parseArgs } from 'node:util';
4
+ import { enabledRules, loadConfig } from '../src/config.js';
5
+ import { findRepoRoot, SlopCheckError } from '../src/git.js';
6
+ import { formatJson, formatText } from '../src/report.js';
7
+ import { RULES } from '../src/rules.js';
8
+ import { runCheck } from '../src/run.js';
9
+ import { badgeMarkdown } from '../src/score.js';
10
+
11
+ const HELP = `Usage: slop-check [base] [options]
12
+
13
+ Checks the lines your branch added for leftovers of unreviewed AI output.
14
+
15
+ slop-check check the current branch against main
16
+ slop-check <base> check the current branch against <base>
17
+
18
+ Options:
19
+ --staged check staged changes only
20
+ --all check every tracked file
21
+ --json print JSON instead of text
22
+ --badge print a README badge for this score
23
+ --max-score <n> exit 1 if the score is above n
24
+ --list-rules print every rule with its weight and status
25
+ --no-color plain output (NO_COLOR is also respected)
26
+ -h, --help show this help
27
+ -v, --version show the version
28
+ `;
29
+
30
+ const OPTIONS = {
31
+ staged: { type: 'boolean' },
32
+ all: { type: 'boolean' },
33
+ json: { type: 'boolean' },
34
+ badge: { type: 'boolean' },
35
+ 'max-score': { type: 'string' },
36
+ 'list-rules': { type: 'boolean' },
37
+ 'no-color': { type: 'boolean' },
38
+ help: { type: 'boolean', short: 'h' },
39
+ version: { type: 'boolean', short: 'v' },
40
+ };
41
+
42
+ function weightName(weight) {
43
+ if (weight >= 5) {
44
+ return 'high';
45
+ }
46
+ return weight >= 3 ? 'medium' : 'low';
47
+ }
48
+
49
+ function readVersion() {
50
+ const packageJson = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'));
51
+ return packageJson.version;
52
+ }
53
+
54
+ // Outside a repo there is no config file, but --list-rules should still work.
55
+ function loadConfigIfInRepo() {
56
+ try {
57
+ return loadConfig(findRepoRoot(process.cwd()));
58
+ } catch {
59
+ return loadConfig(process.cwd());
60
+ }
61
+ }
62
+
63
+ function listRules() {
64
+ const enabled = enabledRules(loadConfigIfInRepo());
65
+ const rows = [];
66
+ for (const rule of RULES) {
67
+ const status = enabled.has(rule.id) ? 'on' : 'off';
68
+ rows.push(`${rule.id.padEnd(24)}${weightName(rule.weight).padEnd(8)}${status.padEnd(5)}${rule.message}`);
69
+ }
70
+ return `${rows.join('\n')}\n`;
71
+ }
72
+
73
+ function parseMaxScore(value) {
74
+ if (value === undefined) {
75
+ return null;
76
+ }
77
+ const number = Number(value);
78
+ if (!Number.isInteger(number) || number < 0 || number > 100) {
79
+ throw new SlopCheckError('--max-score must be a whole number from 0 to 100');
80
+ }
81
+ return number;
82
+ }
83
+
84
+ function main() {
85
+ let parsed;
86
+ try {
87
+ parsed = parseArgs({ options: OPTIONS, allowPositionals: true, strict: true });
88
+ } catch (error) {
89
+ throw new SlopCheckError(`${error.message}. Run slop-check --help.`);
90
+ }
91
+ const flags = parsed.values;
92
+
93
+ if (flags.help) {
94
+ process.stdout.write(HELP);
95
+ return 0;
96
+ }
97
+ if (flags.version) {
98
+ process.stdout.write(`${readVersion()}\n`);
99
+ return 0;
100
+ }
101
+ if (flags['list-rules']) {
102
+ process.stdout.write(listRules());
103
+ return 0;
104
+ }
105
+ if (flags.staged && flags.all) {
106
+ throw new SlopCheckError('use --staged or --all, not both');
107
+ }
108
+ if (parsed.positionals.length > 1) {
109
+ throw new SlopCheckError('give at most one base. Run slop-check --help.');
110
+ }
111
+
112
+ const flagMaxScore = parseMaxScore(flags['max-score']);
113
+ const config = loadConfig(findRepoRoot(process.cwd()));
114
+ for (const warning of config.warnings) {
115
+ process.stderr.write(`slop-check: warning: ${warning}\n`);
116
+ }
117
+
118
+ let mode = 'branch';
119
+ if (flags.staged) {
120
+ mode = 'staged';
121
+ } else if (flags.all) {
122
+ mode = 'all';
123
+ }
124
+ const result = runCheck({ cwd: process.cwd(), mode, ref: parsed.positionals[0], config });
125
+
126
+ if (flags.json) {
127
+ process.stdout.write(formatJson(result));
128
+ } else if (flags.badge) {
129
+ process.stdout.write(`${badgeMarkdown(result.score, result.color)}\n`);
130
+ } else {
131
+ const color = Boolean(process.stdout.isTTY) && !flags['no-color'] && !process.env.NO_COLOR;
132
+ process.stdout.write(formatText(result, { color }));
133
+ }
134
+
135
+ const maxScore = flagMaxScore === null ? config.maxScore : flagMaxScore;
136
+ return maxScore !== null && result.score > maxScore ? 1 : 0;
137
+ }
138
+
139
+ try {
140
+ process.exitCode = main();
141
+ } catch (error) {
142
+ if (!(error instanceof SlopCheckError)) {
143
+ throw error;
144
+ }
145
+ process.stderr.write(`slop-check: ${error.message}\n`);
146
+ process.exitCode = 2;
147
+ }
package/package.json CHANGED
@@ -1,6 +1,46 @@
1
1
  {
2
2
  "name": "@tisankan/slop-check",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.0.0",
4
+ "description": "Catch AI slop in your diff before your reviewer does.",
5
+ "type": "module",
6
+ "bin": {
7
+ "slop-check": "bin/slop-check.js"
8
+ },
9
+ "files": [
10
+ "bin",
11
+ "src",
12
+ "action.yml",
13
+ "README.md",
14
+ "LICENSE"
15
+ ],
16
+ "scripts": {
17
+ "test": "node --test"
18
+ },
19
+ "engines": {
20
+ "node": ">=20"
21
+ },
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "git+https://github.com/tisankanj/slop-check.git"
25
+ },
26
+ "homepage": "https://github.com/tisankanj/slop-check#readme",
27
+ "bugs": {
28
+ "url": "https://github.com/tisankanj/slop-check/issues"
29
+ },
30
+ "keywords": [
31
+ "ai",
32
+ "ai-slop",
33
+ "linter",
34
+ "code-review",
35
+ "cli",
36
+ "github-action",
37
+ "claude-code",
38
+ "cursor",
39
+ "copilot"
40
+ ],
41
+ "author": "Tisankan Jeyakumar",
42
+ "publishConfig": {
43
+ "access": "public"
44
+ },
45
+ "license": "MIT"
46
+ }
@@ -0,0 +1,9 @@
1
+ // The file GitHub runs. It always starts the action, so a symlinked action path
2
+ // can never skip the check and pass by doing nothing.
3
+ import { runAction } from './action.js';
4
+
5
+ const cwd = process.env.GITHUB_WORKSPACE || process.cwd();
6
+ const outcome = await runAction({ env: process.env, fetchFn: fetch, cwd });
7
+ if (outcome.failed) {
8
+ process.exitCode = 1;
9
+ }
package/src/action.js ADDED
@@ -0,0 +1,157 @@
1
+ // GitHub Action entry: runs the check on a pull request, writes the job summary,
2
+ // and keeps one PR comment up to date with the score.
3
+
4
+ import { randomUUID } from 'node:crypto';
5
+ import { appendFileSync, readFileSync } from 'node:fs';
6
+ import { loadConfig } from './config.js';
7
+ import { commitExists, findRepoRoot, SlopCheckError } from './git.js';
8
+ import { formatText } from './report.js';
9
+ import { runCheck } from './run.js';
10
+ import { badgeMarkdown } from './score.js';
11
+
12
+ const MARKER = '<!-- slop-check -->';
13
+ const ZERO_SHA = '0'.repeat(40);
14
+ // GitHub rejects comments over 65536 characters.
15
+ const MAX_REPORT_LENGTH = 60000;
16
+
17
+ function readInputs(env) {
18
+ const maxScoreText = (env['INPUT_MAX-SCORE'] || '').trim();
19
+ return {
20
+ maxScore: maxScoreText === '' ? null : Number(maxScoreText),
21
+ comment: (env.INPUT_COMMENT || 'true').trim() !== 'false',
22
+ token: env['INPUT_GITHUB-TOKEN'] || '',
23
+ };
24
+ }
25
+
26
+ function readEvent(env) {
27
+ if (!env.GITHUB_EVENT_PATH) {
28
+ return {};
29
+ }
30
+ return JSON.parse(readFileSync(env.GITHUB_EVENT_PATH, 'utf8'));
31
+ }
32
+
33
+ function pickBaseSha(eventName, event, root) {
34
+ if (event.pull_request) {
35
+ return event.pull_request.base.sha;
36
+ }
37
+ // After a force push the old `before` commit is gone, so use the default base.
38
+ if (eventName === 'push' && event.before && event.before !== ZERO_SHA && commitExists(root, event.before)) {
39
+ return event.before;
40
+ }
41
+ return undefined;
42
+ }
43
+
44
+ // A fence longer than any backtick run in the text, so file names cannot close it.
45
+ function codeFence(text) {
46
+ let longest = 0;
47
+ for (const run of text.match(/`+/g) || []) {
48
+ longest = Math.max(longest, run.length);
49
+ }
50
+ return '`'.repeat(Math.max(3, longest + 1));
51
+ }
52
+
53
+ // File names are printed in the log. Pausing workflow commands stops a file named
54
+ // `::error::x.js` from being run as a command.
55
+ function writeLog(text) {
56
+ const token = randomUUID();
57
+ process.stdout.write(`::stop-commands::${token}\n${text}::${token}::\n`);
58
+ }
59
+
60
+ function buildReport(result) {
61
+ let text = formatText(result, { color: false });
62
+ if (text.length > MAX_REPORT_LENGTH) {
63
+ text = `${text.slice(0, MAX_REPORT_LENGTH)}\n... report cut short, run slop-check locally for the rest.\n`;
64
+ }
65
+ const fence = codeFence(text);
66
+ return [
67
+ MARKER,
68
+ `### Slop score: ${result.score}/100 (${result.label})`,
69
+ '',
70
+ `${fence}text`,
71
+ text.trimEnd(),
72
+ fence,
73
+ '',
74
+ badgeMarkdown(result.score, result.color),
75
+ '',
76
+ ].join('\n');
77
+ }
78
+
79
+ async function upsertComment(env, inputs, prNumber, body, fetchFn) {
80
+ const api = `${env.GITHUB_API_URL || 'https://api.github.com'}/repos/${env.GITHUB_REPOSITORY}`;
81
+ const headers = {
82
+ Authorization: `Bearer ${inputs.token}`,
83
+ Accept: 'application/vnd.github+json',
84
+ 'X-GitHub-Api-Version': '2022-11-28',
85
+ 'User-Agent': 'slop-check',
86
+ };
87
+
88
+ const list = await fetchFn(`${api}/issues/${prNumber}/comments?per_page=100`, { headers });
89
+ if (!list.ok) {
90
+ return list.status;
91
+ }
92
+ const comments = await list.json();
93
+ const existing = comments.find((comment) => typeof comment.body === 'string' && comment.body.startsWith(MARKER));
94
+
95
+ const request = existing
96
+ ? { url: `${api}/issues/comments/${existing.id}`, method: 'PATCH' }
97
+ : { url: `${api}/issues/${prNumber}/comments`, method: 'POST' };
98
+ const response = await fetchFn(request.url, { method: request.method, headers, body: JSON.stringify({ body }) });
99
+ return response.ok ? null : response.status;
100
+ }
101
+
102
+ export async function runAction({ env, fetchFn, cwd }) {
103
+ const inputs = readInputs(env);
104
+ const event = readEvent(env);
105
+
106
+ let result;
107
+ let config;
108
+ try {
109
+ const validMaxScore = Number.isInteger(inputs.maxScore) && inputs.maxScore >= 0 && inputs.maxScore <= 100;
110
+ if (inputs.maxScore !== null && !validMaxScore) {
111
+ throw new SlopCheckError('max-score must be a whole number from 0 to 100');
112
+ }
113
+ const root = findRepoRoot(cwd);
114
+ config = loadConfig(root);
115
+ for (const warning of config.warnings) {
116
+ process.stdout.write(`::warning::slop-check: ${warning}\n`);
117
+ }
118
+ result = runCheck({ cwd, mode: 'branch', baseSha: pickBaseSha(env.GITHUB_EVENT_NAME, event, root), config });
119
+ } catch (error) {
120
+ if (!(error instanceof SlopCheckError)) {
121
+ throw error;
122
+ }
123
+ process.stdout.write(`::error::slop-check: ${error.message}\n`);
124
+ return { score: null, failed: true };
125
+ }
126
+
127
+ writeLog(formatText(result, { color: false }));
128
+ const report = buildReport(result);
129
+ if (env.GITHUB_STEP_SUMMARY) {
130
+ appendFileSync(env.GITHUB_STEP_SUMMARY, report);
131
+ }
132
+ if (env.GITHUB_OUTPUT) {
133
+ appendFileSync(env.GITHUB_OUTPUT, `score=${result.score}\n`);
134
+ }
135
+
136
+ const prNumber = event.pull_request ? event.pull_request.number : null;
137
+ if (inputs.comment && prNumber && inputs.token) {
138
+ let failedStatus;
139
+ try {
140
+ failedStatus = await upsertComment(env, inputs, prNumber, report, fetchFn);
141
+ } catch (error) {
142
+ failedStatus = error.message;
143
+ }
144
+ // Fork PRs get a read-only token. The job summary still has the full report.
145
+ if (failedStatus) {
146
+ process.stdout.write(`::warning::slop-check could not post the PR comment (${failedStatus}). The job summary has the report.\n`);
147
+ }
148
+ }
149
+
150
+ const maxScore = inputs.maxScore === null ? config.maxScore : inputs.maxScore;
151
+ const failed = maxScore !== null && result.score > maxScore;
152
+ if (failed) {
153
+ process.stdout.write(`::error::Slop score ${result.score} is above max-score ${maxScore}.\n`);
154
+ }
155
+ return { score: result.score, failed };
156
+ }
157
+