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 AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Refer to the service that runs these plugins as "patch-it's hosted ingestion ser

## Rules for plugin code

- **How to read is a kind; what to read is a provider.** `kinds/<kind>/` reads one kind of source, written once, and imports no provider. `providers/<provider>/` holds one provider and nothing about another: `provider.go` (its registration, built from the kinds' exported types), `README.md` (its page), any code only it needs (`<source>.go`: an OpenAPI adapter, a feed's reader), `testdata/` and its tests. A provider imports only `core/` and `kinds/`. No folder per source, no forwarders: when code moves, the old path goes in the same change. `go test ./providers/all` checks all of this.
- **How to read is a kind; what to read is a provider.** `kinds/<kind>/` reads one kind of source, written once, and imports no provider. `providers/<provider>/` holds one provider and nothing about another: `provider.go` (its registration, built from the kinds' exported types), `README.md` (its page), any code only it needs (`<source>.go`: an OpenAPI adapter, a feed's reader), `testdata/` and its tests. A provider imports only `core/` and `kinds/`. No folder per source, no forwarders: when code moves, the old path goes in the same change, and no package keeps a type alias (`type X = …`), a re-export (`var X = otherpkg.Y`) or a func that only calls another package's (a genuine one says why with `alias-ok: <reason>` in its doc comment). `go test ./providers/all` checks all of this.

- **Start a new source with `make new-plugin ARGS='--provider <id> --name <Name> --source <id> --kind <kind>'`** (`go run ./cmd/new-plugin`; [which kind](docs/which-kind.md)): it writes into `providers/<id>/`, a new folder or one more source in the existing one. Then fill in every `TODO(new-plugin)`; `make todos` (part of `make check` and CI_go) fails while one is left.
- **Fetch only through the environment** (`env.Get` or `core/kit/`). No `net/http` outside the fetch layer, no filesystem outside `testdata/`, no database.
Expand Down
7 changes: 5 additions & 2 deletions cmd/new-plugin/formats.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ var formats = map[string]formatSpec{
layer: "api",
def: `package {{.Package}}

import "github.com/patch-it-dev/patch-it-plugins/kinds/notices/feed"
import (
"github.com/patch-it-dev/patch-it-plugins/core/extract"
"github.com/patch-it-dev/patch-it-plugins/kinds/notices/feed"
)

// {{.Ident}} is {{.Provider}}'s feed of changes.
//
Expand All @@ -60,7 +63,7 @@ var {{.Ident}} = feed.Feed{
// an entry that isn't a breaking change or a deprecation. Precision over
// recall: readCloudflareAPI in providers/cloudflare/api.go is a worked
// example.
func read{{.Ident}}(e feed.Entry) []feed.Finding {
func read{{.Ident}}(e extract.Entry) []feed.Finding {
return nil
}
`,
Expand Down
12 changes: 6 additions & 6 deletions kinds/notices/feed/feed_test.go → core/extract/feed_test.go
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
package feed
package extract

import (
"testing"
)

func TestParseRefusesWhatIsntAFeed(t *testing.T) {
func TestParseFeedRefusesWhatIsntAFeed(t *testing.T) {
for name, b := range map[string]string{
"html": "<!doctype html><html><body>moved</body></html>",
"no items": `<rss version="2.0"><channel><title>x</title></channel></rss>`,
"no entry": `<feed xmlns="http://www.w3.org/2005/Atom"><id>x</id></feed>`,
} {
if _, err := Parse([]byte(b)); err == nil {
if _, err := ParseFeed([]byte(b)); err == nil {
t.Errorf("%s: want an error, never zero events read as a quiet week", name)
}
}
}

// RSS without content:encoded falls back to description; Atom takes the
// alternate link and the category terms.
func TestParseReadsBothFormats(t *testing.T) {
r, err := Parse([]byte(`<rss version="2.0"><channel><item><title>A &amp; B</title><link>https://x.test/a</link>
func TestParseFeedReadsBothFormats(t *testing.T) {
r, err := ParseFeed([]byte(`<rss version="2.0"><channel><item><title>A &amp; B</title><link>https://x.test/a</link>
<category>Retired</category><description>&lt;p&gt;text&lt;/p&gt;</description></item></channel></rss>`))
if err != nil || r[0].Title != "A & B" || r[0].HTML != "<p>text</p>" || r[0].Categories[0] != "Retired" || r[0].ID != "https://x.test/a" {
t.Errorf("rss: %+v %v", r, err)
}
a, err := Parse([]byte(`<feed xmlns="http://www.w3.org/2005/Atom"><entry><id>i</id><title>T</title>
a, err := ParseFeed([]byte(`<feed xmlns="http://www.w3.org/2005/Atom"><entry><id>i</id><title>T</title>
<link rel="self" href="https://x.test/self"/><link rel="alternate" href="https://x.test/e"/>
<category term="Deprecated"/><summary type="html">&lt;b&gt;s&lt;/b&gt;</summary></entry></feed>`))
if err != nil || a[0].Link != "https://x.test/e" || a[0].HTML != "<b>s</b>" || a[0].Categories[0] != "Deprecated" {
Expand Down
19 changes: 0 additions & 19 deletions kinds/notices/feed/extract.go

This file was deleted.

5 changes: 3 additions & 2 deletions kinds/notices/feed/feed.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"time"

"github.com/patch-it-dev/patch-it-plugins/core/event"
"github.com/patch-it-dev/patch-it-plugins/core/extract"
"github.com/patch-it-dev/patch-it-plugins/core/kit"
)

Expand All @@ -40,7 +41,7 @@ type Feed struct {
// Reader turns one entry into findings: what it can name for sure, and what
// it drops. It returns nothing for an entry that isn't breaking or a
// deprecation.
type Reader func(e Entry) []Finding
type Reader func(e extract.Entry) []Finding

// Finding is one change a reader found in an entry, or one it dropped.
type Finding struct {
Expand All @@ -56,7 +57,7 @@ type Finding struct {

// Findings reads every entry of a feed.
func (f Feed) Findings(b []byte) ([]Finding, error) {
entries, err := Parse(b)
entries, err := extract.ParseFeed(b)
if err != nil {
return nil, err
}
Expand Down
5 changes: 3 additions & 2 deletions kinds/notices/feed/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"strings"

"github.com/patch-it-dev/patch-it-plugins/core/event"
"github.com/patch-it-dev/patch-it-plugins/core/extract"
)

var (
Expand Down Expand Up @@ -36,12 +37,12 @@ func Dated(lines []string) (line, date string, ct event.ChangeType) {
// The date after the words, not the first on the line: "deprecated
// as of February 23, 2026 and will be shut down on August 23, 2026".
if m := willStop.FindStringIndex(l); m != nil {
if d := Date(l[m[1]:]); d != "" {
if d := extract.Date(l[m[1]:]); d != "" {
return l, d, event.ChangeTypeBreaking
}
}
if m := willSoften.FindStringIndex(l); m != nil {
if d := Date(l[m[1]:]); d != "" {
if d := extract.Date(l[m[1]:]); d != "" {
return l, d, event.ChangeTypeDeprecation
}
}
Expand Down
8 changes: 3 additions & 5 deletions kinds/openapi/openapi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ var specs = map[string]string{
"id":{"type":"string"},"latest_charge":{"type":"string"}}}}}}`,
}

func openStore(*testing.T) *kittest.Mem { return kittest.NewMem() }

func storedEvents(t *testing.T, s *kittest.Mem) []string {
t.Helper()
events, err := s.All()
Expand All @@ -99,7 +97,7 @@ func storedEvents(t *testing.T, s *kittest.Mem) []string {
// stored as change events, once.
func TestAPairStoresItsEventsOnce(t *testing.T) {
ctx := context.Background()
s := openStore(t)
s := kittest.NewMem()

if _, err := pair(ctx, s, fakeAdapter{specs: specs}, "v1", "v2"); err != nil {
t.Fatalf("pair: %v", err)
Expand Down Expand Up @@ -132,7 +130,7 @@ func TestAPairStoresItsEventsOnce(t *testing.T) {
// hint source in these tests always errors: noChangelog).
func TestIngestStoresEventsWhenTheChangelogIsUnreachable(t *testing.T) {
ctx := context.Background()
s := openStore(t)
s := kittest.NewMem()
if _, err := pair(ctx, s, fakeAdapter{specs: specs}, "v1", "v2"); err != nil {
t.Fatalf("pair: %v", err)
}
Expand All @@ -152,7 +150,7 @@ func TestAPairAttachesMigrationHintsFromTheChangelog(t *testing.T) {
}}}

ctx := context.Background()
s := openStore(t)
s := kittest.NewMem()
if _, err := pairWith(ctx, s, newPlugin(fakeAdapter{specs: specs}, withHints), "v1", "v2"); err != nil {
t.Fatalf("pair: %v", err)
}
Expand Down
Loading
Loading