Skip to content

feat(cli): add GitHub integration that publishes lint results - #94

Closed
luoling8192 wants to merge 1 commit into
alint-dev:mainfrom
luoling8192:luoling8192/feat/github-integration
Closed

luoling8192 wants to merge 1 commit into
alint-dev:mainfrom
luoling8192:luoling8192/feat/github-integration

Conversation

@luoling8192

Copy link
Copy Markdown

Summary

A repository that runs alint in CI must write its own script to show the result on a pull request. LobeHub wrote such a script for its monorepo. This PR adds the same capability to the CLI, so each repository can use one command.

alint integrations github <file> reads saved --format json output and publishes it to GitHub:

  • A check run named alint with one line annotation for each diagnostic.
  • One summary comment on the pull request. Each run rewrites the same comment.
  • The same summary in the job summary.
permissions:
  checks: write
  contents: read
  pull-requests: write

steps:
  - run: alint --format json src > alint-output.json || [ $? -eq 1 ]
  - run: alint integrations github alint-output.json
    env:
      GITHUB_TOKEN: ${{ github.token }}

This PR is independent. It does not add suggestion blocks. A diagnostic has no replacement text and no exact range today, so that needs a change to the rule contract first.

Change map

Module Before After Description
integrations/github Did not exist. Converts a run result to findings, a Markdown summary, and annotations. Calls the GitHub REST API. findings.ts is pure. api.ts owns the network calls. github.ts owns the command and the environment.
output-inspect/run-result inspect.ts owned the reader and the validation of saved output. A shared module owns them. output inspect and the new command read saved output the same way. The messages and exit codes of output inspect did not change.
README No CI publication section. A GitHub Pull Requests section. pnpm docs:update synchronized packages/cli/README.md.

Behavior

  • The check run conclusion is failure when a diagnostic is an error, neutral when there are only warnings, and success when there are no findings.
  • The command returns 0 after it publishes the result, also when the result has errors. The check run reports the errors, so the job does not fail a second time. It returns 2 when it cannot read the file or GitHub rejects a request.
  • On a pull request event, the check run goes to pull_request.head.sha from GITHUB_EVENT_PATH. GITHUB_SHA is the temporary merge commit there, and a check run on that commit does not show on the pull request.
  • ALINT_GITHUB_SHA and ALINT_GITHUB_PULL_REQUEST select the commit and the pull request for other events. These are environment variables and not options, because the argument parser converts a commit that has only digits to a number.
  • The suggestion text comes from evidence.suggestion, which declarative rules and @alint-js/plugin-js rules set.
  • GitHub accepts 50 annotations for each request. The command sends more annotations in update requests.
  • A pull request that never had findings gets no comment. After a comment exists, a clean run rewrites it.
  • GITHUB_API_URL and GITHUB_SERVER_URL select the API and the link host, so GitHub Enterprise Server works without more configuration.

Boundaries and risks

Boundary Failure mode Protection Evidence or gap
Summary size GitHub rejects a body above 65536 characters. The table has at most 100 rows. The remaining count is stated. findings.test.ts
Annotation limit GitHub rejects more than 50 annotations in one request. Batches of 50. github.test.ts with 120 diagnostics
Fork pull requests The token is read-only. The command returns 2 with the GitHub error. github.test.ts with a 403 response. The README states the limit.
Real GitHub API The local server in the tests does not prove that GitHub accepts the payload. None. Not verified. Only a GitHub App token can create a check run, so a personal token cannot run this command. A workflow run in a repository is necessary.

Verification

  • pnpm -F @alint-js/cli exec vitest run src/cli/commands/integrations/github src/cli/cli.test.ts: 124 tests passed. The new tests call the CLI against a local HTTP server and do not use mocks.
  • pnpm -F @alint-js/cli exec vitest run: 423 passed, 4 failed. The 4 failures are in git.test.ts, lint/dirty.test.ts, and stop-gate.test.ts. They also fail on main on macOS because the temporary directory is a symbolic link (/var and /private/var).
  • pnpm typecheck: passed after pnpm -r run build.
  • pnpm lint: passed.

Follow-up

  • Add a base option to --dirty, so CI does not need git reset --mixed <merge-base> to lint only the changes of a pull request.
  • Add structured fix data to diagnostics. Then this integration can publish suggestion blocks.

🤖 Generated with Claude Code

`alint integrations github <file>` reads saved JSON output and publishes it
to GitHub. It adds a check run with line annotations, one summary comment on
the pull request, and a job summary.

The check run fails only when a diagnostic is an error. Each run rewrites the
same summary comment.

`output inspect` and the new command share one reader for saved output.

Co-authored-by: Neko Ayaka <neko@ayaka.moe>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@luoling8192

Copy link
Copy Markdown
Author

The publication logic moved to a separate action, as the owner requested: https://github.com/alint-dev/setup. This PR is not necessary.

@luoling8192 luoling8192 closed this Oct 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant