Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
- [ ] One pinned drop test: a realistic input that produces no event
- [ ] `providers/<api>.md` written or updated from `providers/_template.md`, including **Why this source**
- [ ] Fetches only through `env.Get` / `kit/`
- [ ] `go build ./... && go vet ./... && gofmt -l . && go test -race ./...` pass locally
- [ ] `make check` passes locally (and `make plugins-json` was run if a plugin or its row changed)
- [ ] Nothing private: no credentials, internal hosts, private links, customer names

## Notes for the reviewer
Expand Down
46 changes: 14 additions & 32 deletions .github/workflows/CI_go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# detector. Two guards keep plugins self-contained:
# - imports: only this module, the standard library and the approved dependencies;
# - network: net/http only in the fetch layer (fetch/, kit/, adapter/).
# The steps are Makefile targets, so `make check` runs exactly this locally.
# Until the Go code lands there is no go.mod, and every step after the first is skipped
# with a notice, so the check passes.
name: CI_go
Expand Down Expand Up @@ -43,57 +44,38 @@ jobs:
go-version-file: go.mod
cache-dependency-path: go.sum

# Each step is a Makefile target; `make check` runs the same ones (plus
# the internal-names check) locally.
- name: go.mod and go.sum are tidy
if: steps.go.outputs.present == 'true'
run: |
go mod tidy
if ! git diff --exit-code -- go.mod go.sum; then
echo "::error file=go.mod::go.mod/go.sum are not tidy. Run 'go mod tidy' and commit the result."
exit 1
fi
run: make tidy

- name: go build
if: steps.go.outputs.present == 'true'
run: go build ./...
run: make build

- name: gofmt
if: steps.go.outputs.present == 'true'
run: |
unformatted=$(gofmt -l .)
if [ -n "$unformatted" ]; then
for f in $unformatted; do echo "::error file=$f::not gofmt-formatted. Run 'gofmt -w .'."; done
exit 1
fi
run: make fmt

- name: go vet
if: steps.go.outputs.present == 'true'
run: go vet ./...
run: make vet

# An allowlist, so a plugin can't pull in a database driver, a cloud SDK or
# anything private. Adding a dependency means adding it here, in review.
# An allowlist (ALLOWED in the Makefile), so a plugin can't pull in a
# database driver, a cloud SDK or anything private. Adding a dependency
# means adding it there, in review.
- name: imports are this module, the standard library or approved
if: steps.go.outputs.present == 'true'
run: |
module=$(go list -m)
allowed="^($module(/|$)|gopkg\.in/yaml\.v3$)"
others=$(go list -deps -test -f '{{if not .Standard}}{{.ImportPath}}{{end}}' ./... | sed 's/ \[.*//' | sort -u | grep -vE "$allowed" || true)
if [ -n "$others" ]; then
echo "::error::imports outside the allowlist (CI_go.yml):"; echo "$others"; exit 1
fi
run: make imports

# Plugins fetch through env.Get / kit, never on their own.
- name: net/http only in the fetch layer
if: steps.go.outputs.present == 'true'
run: |
module=$(go list -m)
bad=$(go list -f '{{.ImportPath}} {{join .Imports " "}}' ./... \
| grep -E '(^| )net/http( |$)' | cut -d' ' -f1 \
| grep -vE "^$module/(fetch|kit|adapter)(/|$)" || true)
if [ -n "$bad" ]; then
echo "::error::these packages import net/http; fetch through env.Get or kit instead:"; echo "$bad"; exit 1
fi
run: make nethttp

# -race: the fetcher and the tests' HTTP servers run on other goroutines.
# Also fails when docs/plugins.json is out of date (make plugins-json).
- name: go test
if: steps.go.outputs.present == 'true'
run: go test -race -count=1 ./...
run: make test
20 changes: 12 additions & 8 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Rules for AI coding agents (and humans) working in this repo. `CLAUDE.md` import

**If you add a plugin, add its row to [`docs/plugins.md`](docs/plugins.md) in the same PR. If you change a plugin's id, provider, source, what it watches, format plugin or status, update its row in the same PR. If you remove one, remove its row.**

The list of supported APIs on docs.patch-it.dev is generated from that file, so a plugin missing from it doesn't exist as far as users can tell. No CI check enforces this: you are the check. Before you finish, compare the registered plugins with the table and say in the PR that you did.
The list of supported APIs on docs.patch-it.dev is generated from that file, so a plugin missing from it doesn't exist as far as users can tell. Then run `make plugins-json`: it regenerates [`docs/plugins.json`](docs/plugins.json) from the plugin registry and the table, and fails if a registered plugin has no row (or a row has no plugin, a wrong format or no provider page). `go test` fails while `docs/plugins.json` is out of date. The check can't tell whether a row's words are right: you are that check. Say in the PR that you compared them.

Keep the table between the `<!-- plugins:start -->` and `<!-- plugins:end -->` markers a plain Markdown table, one row per plugin, absolute links only (the docs site copies it verbatim).

Expand All @@ -33,29 +33,33 @@ Refer to the service that runs these plugins as "patch-it's hosted ingestion ser

## Commands

**Run `make check` before you say you're done.** It runs exactly what `CI_go` runs (each CI step is a Makefile target) plus the internal-names check over every tracked file; if it passes locally, those checks pass in CI.

```sh
go build ./...
go vet ./...
gofmt -l . # must print nothing
go test -race ./...
python3 scripts/leak_guard.py --all # the internal-names check over every tracked file
make check # tidy, build, gofmt, vet, the import allowlist, the net/http guard, go test -race, leak guard
make check PATCH_IT=../patch-it # also CI_contract: contract/fixtures/ against a patch-it checkout
make plugins-json # regenerate docs/plugins.json after adding or changing a plugin or its row
```

One target at a time: `make tidy`, `make build`, `make fmt`, `make vet`, `make imports`, `make nethttp`, `make test`, `make leak-guard`, `make contract`. Use `make GO=/path/to/go check` for another Go.

## Layout

Go module `github.com/patch-it-dev/patch-it-plugins`; the only dependency is `gopkg.in/yaml.v3`.

```
plugin/ the Plugin interface, the registry, Env, Result, Spec (baselines)
cmd/list-plugins/ writes docs/plugins.json (make plugins-json); internal/pluginlist/ is its logic
plugins/<format>/ one package per format plugin: openapi, retirements, migrationguide,
removedmembers, changelog, feed, apichangelog; plugins/all imports every one
removedmembers, changelog, feed, apichangelog, catalog; plugins/all imports every one
kit/ kit/kittest/ Unchanged, Cite, Wayback; the test kit (Mem, Pages, Ingest, Golden)
event/ migrate/ the change-event types from patch-it's contract (v1 + v2), v1 -> v2
fetch/ the HTTP fetch with retries and the ETag / Last-Modified cache
diff/ normalize/ hint/ adapter/ the OpenAPI diff engine and the spec adapters
retire/ sdkguide/ deprecations-page and migration-guide readers
contract/fixtures/ a copy of patch-it's change-event fixtures (CI_contract checks it)
docs/plugins.md the list of supported plugins (Rule 1)
docs/plugins.md the list of supported plugins (Rule 1); docs/plugins.json is generated from it
Makefile make check (what CI_go runs, plus the leak guard), make plugins-json
docs/ contributor docs, including writing-a-plugin.md
providers/<api>.md one page per provider
scripts/ leak_guard.py (hashed internal names), check_contract.py
Expand Down
6 changes: 3 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Thanks for helping patch-it watch more APIs. This file is the rulebook; [docs/wr

## The rules

1. **Add your plugin to [docs/plugins.md](docs/plugins.md).** Every new plugin gets a row; every change to a plugin's id, provider, source, what it watches or status updates its row. The list on docs.patch-it.dev is built from that file, so a plugin that isn't listed is invisible to users.
1. **Add your plugin to [docs/plugins.md](docs/plugins.md).** Every new plugin gets a row; every change to a plugin's id, provider, source, what it watches or status updates its row. The list on docs.patch-it.dev is built from that file, so a plugin that isn't listed is invisible to users. Then run `make plugins-json` to regenerate [`docs/plugins.json`](docs/plugins.json); it fails if the registry and the table disagree, and the tests fail while the JSON is out of date.
2. **Fetch only through the environment.** Plugins get their sources from `env.Get` or the helpers in `kit/`, never from `net/http` directly, the filesystem or a database. That keeps tests offline and lets the hosted service cache, retry and rate-limit politely.
3. **Every plugin has a golden test** over a real saved copy of its source: `testdata/<file>` in, `testdata/golden/<api>.json` out. `testdata/README.md` lists each file with its URL, the date you fetched it, its license, and a short quote of the part your plugin reads. Keep openly licensed files whole; trim vendor documentation pages to what the test needs.
4. **Precision over recall.** A missed change is a bug we can fix later. A wrong change becomes a wrong pull request in someone's repo. When in doubt, don't emit.
Expand All @@ -26,15 +26,15 @@ That adds `Signed-off-by: Your Name <you@example.com>`, matching the commit's au

- One plugin or one fix per PR. Fill in the PR template's checklist.
- Commit subjects: short, lowercase, imperative (`add the foo plugin`, `fix stripe hint parsing`).
- Run the tests before you push (see [README](README.md#run-the-tests)).
- **Run `make check` before you push.** It runs exactly what `CI_go` runs (tidy, build, gofmt, vet, the import allowlist, the `net/http` guard, `go test -race`) plus the internal-names check, so a green `make check` means those CI checks pass.
- A maintainer listed in `.github/CODEOWNERS` reviews every PR.
- **Reviews:** Claude also reviews each PR against the rules above, once, when it's opened or marked ready. PRs from forks get no secrets, so for those a maintainer comments `@claude review` and Claude reviews it read-only (it never runs a fork's code). Only maintainers can call `@claude`. Claude's review helps; a maintainer still decides.

## CI

| Workflow | What it checks |
|---|---|
| `CI_go` | `go mod tidy`, build, vet, gofmt, `go test -race`; plugins import only this module, the standard library and approved dependencies; `net/http` only in the fetch layer |
| `CI_go` | `go mod tidy`, build, vet, gofmt, `go test -race` (including that `docs/plugins.json` is up to date); plugins import only this module, the standard library and approved dependencies; `net/http` only in the fetch layer. Each step is a [Makefile](Makefile) target: `make check` runs them all locally |
| `CI_dco` | Every commit in the PR is signed off by its author |
| `CI_leak_guard` | gitleaks over the PR's commits, and a check for known internal names (stored as hashes only). Also runs weekly over the whole repo |
| `Claude Code Review` | Claude reviews the PR against the rules above, once (PRs from this repo's branches; forks: a maintainer comments `@claude review`). Advisory, not a required check |
Expand Down
81 changes: 81 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# `make check` is what CI runs on every pull request: the CI_go steps (each one
# is a target here, and CI_go calls these same targets), the internal-names
# check of CI_leak_guard over every tracked file, and CI_contract's fixture
# comparison when you point it at a patch-it checkout. Run it before you open a PR.
#
# make check everything below, in CI's order
# make check PATCH_IT=../patch-it also compare contract/fixtures/ with patch-it's
# make plugins-json regenerate docs/plugins.json from the registry and docs/plugins.md
#
# The `::error` lines are GitHub annotations; locally they're plain messages.

GO ?= go
PYTHON ?= python3

# Packages allowed outside the standard library: this module and the approved
# dependencies. Adding a dependency means adding it here, in review.
MODULE := github.com/patch-it-dev/patch-it-plugins
ALLOWED := ^($(MODULE)(/|$$)|gopkg\.in/yaml\.v3$$)

.PHONY: check tidy build fmt vet imports nethttp test leak-guard contract plugins-json

check: tidy build fmt vet imports nethttp test leak-guard contract
@echo "make check: all passed"

# go.mod and go.sum are tidy.
tidy:
$(GO) mod tidy
@git diff --exit-code -- go.mod go.sum || { echo "::error file=go.mod::go.mod/go.sum are not tidy. Run 'go mod tidy' and commit the result."; exit 1; }

build:
$(GO) build ./...

fmt:
@unformatted=$$(gofmt -l .); \
if [ -n "$$unformatted" ]; then \
for f in $$unformatted; do echo "::error file=$$f::not gofmt-formatted. Run 'gofmt -w $$f'."; done; \
exit 1; \
fi

vet:
$(GO) vet ./...

# An allowlist, so a plugin can't pull in a database driver, a cloud SDK or
# anything private.
imports:
@others=$$($(GO) list -deps -test -f '{{if not .Standard}}{{.ImportPath}}{{end}}' ./... | sed 's/ \[.*//' | sort -u | grep -vE '$(ALLOWED)' || true); \
if [ -n "$$others" ]; then \
echo "::error::imports outside the allowlist (Makefile, ALLOWED):"; echo "$$others"; exit 1; \
fi

# Plugins fetch through env.Get / kit, never on their own.
nethttp:
@bad=$$($(GO) list -f '{{.ImportPath}} {{join .Imports " "}}' ./... \
| grep -E '(^| )net/http( |$$)' | cut -d' ' -f1 \
| grep -vE '^$(MODULE)/(fetch|kit|adapter)(/|$$)' || true); \
if [ -n "$$bad" ]; then \
echo "::error::these packages import net/http; fetch through env.Get or kit instead:"; echo "$$bad"; exit 1; \
fi

# -race: the fetcher and the tests' HTTP servers run on other goroutines.
# Includes the check that docs/plugins.json is up to date (internal/pluginlist).
test:
$(GO) test -race -count=1 ./...

# CI_leak_guard checks only what a PR adds (plus gitleaks); this checks every
# tracked file.
leak-guard:
$(PYTHON) scripts/leak_guard.py --all

# CI_contract: contract/fixtures/ hold the same events as patch-it's fixtures/.
# Needs a patch-it checkout; skipped without one, as CI_contract skips while
# patch-it can't be read anonymously.
contract:
@if [ -n "$(PATCH_IT)" ]; then \
$(PYTHON) scripts/check_contract.py "$(PATCH_IT)/fixtures"; \
else \
echo "contract: skipped (make check PATCH_IT=<a patch-it checkout> compares contract/fixtures/)"; \
fi

plugins-json:
$(GO) run ./cmd/list-plugins
7 changes: 2 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,10 @@ See **[docs/plugins.md](docs/plugins.md)**. The same list is on [docs.patch-it.d

## Run the tests

Go (the version in `go.mod`), no other setup:
Go (the version in `go.mod`), `make` and Python 3, no other setup:

```sh
go build ./...
go vet ./...
gofmt -l . # prints nothing when formatted
go test -race ./...
make check # what CI runs: tidy, build, gofmt, vet, import and net/http guards, go test -race, leak guard
```

The tests are offline: every plugin's test reads a saved copy of its source from `testdata/` and compares the events with a golden file. One package: `go test ./plugins/feed`. After an intended change to a plugin's output, `go test ./plugins/<name> -update` rewrites its golden files; review that diff like code.
Expand Down
55 changes: 55 additions & 0 deletions cmd/list-plugins/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Command list-plugins writes docs/plugins.json: every registered plugin
// joined with its row in docs/plugins.md (id, provider, what it watches,
// format plugin, source URL, status, provider page). It fails when the
// registry and the table disagree. Run it from the repo root:
//
// go run ./cmd/list-plugins # rewrite docs/plugins.json (make plugins-json)
// go run ./cmd/list-plugins -check # fail if docs/plugins.json is out of date (make check)
// go run ./cmd/list-plugins -o - # print it
package main

import (
"bytes"
"flag"
"fmt"
"os"
"path/filepath"

"github.com/patch-it-dev/patch-it-plugins/internal/pluginlist"
_ "github.com/patch-it-dev/patch-it-plugins/plugins/all"
)

func main() {
root := flag.String("root", ".", "the repo root")
out := flag.String("o", pluginlist.JSON, "where to write the list, relative to -root; - for stdout")
check := flag.Bool("check", false, "don't write: fail if the file differs from what would be written")
flag.Parse()
if err := run(*root, *out, *check); err != nil {
fmt.Fprintln(os.Stderr, "list-plugins:", err)
os.Exit(1)
}
}

func run(root, out string, check bool) error {
plugins, err := pluginlist.List(root)
if err != nil {
return err
}
b, err := pluginlist.Marshal(plugins)
if err != nil {
return err
}
if out == "-" {
_, err := os.Stdout.Write(b)
return err
}
path := filepath.Join(root, out)
if check {
have, err := os.ReadFile(path)
if err != nil || !bytes.Equal(have, b) {
return fmt.Errorf("%s is out of date: run `make plugins-json` and commit it", out)
}
return nil
}
return os.WriteFile(path, b, 0o644)
}
1 change: 1 addition & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
| Page | What's in it |
|---|---|
| [plugins.md](plugins.md) | Every supported plugin: id, provider, what it watches, source. Also published on [docs.patch-it.dev](https://docs.patch-it.dev/supported-apis/plugins/). |
| [plugins.json](plugins.json) | The same list as JSON, generated by `make plugins-json` from the plugin registry and plugins.md. Don't edit by hand. |
| [writing-a-plugin.md](writing-a-plugin.md) | How to add a provider: the `Plugin` interface, fetching through `env.Get` and `kit/`, saving the source, the golden test with `kittest`, the provider page and the plugin list. |

| [../providers/](../providers/) | One page per provider: why that source, what the plugin reads and ignores. |
Expand Down
Loading
Loading