Repository navigation
stripe: sdk changelogs read the api version they pin; stripe/api lists api versions #246
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b042587
changelog: read the API version each stripe sdk release pins
adssib 2fd00ee
pins: skip code blocks before headings; fall back to the tag before
adssib 54acfb4
stripe-sdks: say the changelog may be read at the tag before
adssib 843a2b5
openapi: list stripe/api by api version, as its releases' notes name …
adssib b118177
stripe.md: one known-gaps list; the ga file declares every listed ver…
adssib File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| package changelog | ||
|
|
||
| import ( | ||
| "context" | ||
| "log" | ||
| "regexp" | ||
| "strings" | ||
|
|
||
| "github.com/patch-it-dev/patch-it-plugins/core/plugin" | ||
| ) | ||
|
|
||
| // What a release pins: a sentence in its own section of the changelog that | ||
| // names the version of another source it pins, in the words its SDK uses | ||
| // (Stripe's, checked 2026-11-20 in all seven SDKs' CHANGELOG.md): | ||
| // | ||
| // This release changes the pinned API version to `2026-11-18.endive`. | ||
| // This release **doesn't** change the pinned API version; it still uses `2026-05-27.dahlia`. | ||
| // This release **does not** change the pinned API version. It's still `2026-06-24.dahlia`. | ||
| // This release uses the same pinned API version to `2026-03-25.dahlia` as the last major release. | ||
| // | ||
| // A release that says nothing pins nothing here, even though it keeps the | ||
| // release before's: only what a release states is read. Two different | ||
| // versions in one section are none (precision over recall). Older wordings | ||
| // ("Major version release for API version 2022-08-01", "Move to API version | ||
| // …") don't say "pinned" and aren't read. | ||
| var statedPin = []*regexp.Regexp{ | ||
| regexp.MustCompile("pinned API version to `(" + apiVersion + ")`"), | ||
| regexp.MustCompile("change the pinned API version[.;] (?:[Ii]t's still|it still uses) `(" + apiVersion + ")`"), | ||
| } | ||
|
|
||
| // apiVersion is a dated API version, with the release's name when it has | ||
| // one: "2026-11-18.endive", "2022-08-01". | ||
| const apiVersion = `\d{4}-\d{2}-\d{2}(?:\.[a-z]+)?` | ||
|
|
||
| // pins are the versions each release of a Markdown changelog states it | ||
| // pins, by release as its heading names it. | ||
| func pins(file []byte) map[string]string { | ||
| out, conflict := map[string]string{}, map[string]bool{} | ||
| release, fenced := "", false | ||
| for _, l := range strings.Split(strings.ReplaceAll(string(file), "\r\n", "\n"), "\n") { | ||
| // A code block first: a "# comment" in an example isn't a heading. | ||
| // A release's heading closes a block its section left open. | ||
| if m := mdRelease.FindStringSubmatch(l); m != nil && strings.HasPrefix(l, "## ") { | ||
| release, fenced = m[1], false | ||
| continue | ||
| } | ||
| if strings.HasPrefix(strings.TrimSpace(l), "```") { | ||
| fenced = !fenced | ||
| continue | ||
| } | ||
| if fenced { | ||
| continue | ||
| } | ||
| if strings.HasPrefix(l, "## ") || strings.HasPrefix(l, "# ") { | ||
| release = "" | ||
| if m := mdRelease.FindStringSubmatch(l); m != nil { | ||
| release = m[1] | ||
| } | ||
| continue | ||
| } | ||
| if release == "" { | ||
| continue | ||
| } | ||
| l = strings.ReplaceAll(l, "**", "") | ||
| for _, re := range statedPin { | ||
| for _, m := range re.FindAllStringSubmatch(l, -1) { | ||
| if have, ok := out[release]; ok && have != m[1] { | ||
| conflict[release] = true | ||
| } | ||
| out[release] = m[1] | ||
| } | ||
| } | ||
| } | ||
| for r := range conflict { | ||
| delete(out, r) | ||
| } | ||
| return out | ||
| } | ||
|
|
||
| // pinned sets each version's MapsTo to what its section states it pins (f.Pins), | ||
| // read from the changelog at the newest version's tag, which has every | ||
| // earlier release's section, or at the one before when that tag can't be read | ||
| // (a release on the registry before its tag is pushed). A changelog that | ||
| // can't be fetched leaves the versions as listed: what they pin is read on a | ||
| // later listing. | ||
| func (f File) pinned(ctx context.Context, env plugin.Env, vs []plugin.Version) []plugin.Version { | ||
| if f.Pins == "" || f.Notes || len(vs) == 0 { | ||
| return vs | ||
| } | ||
| var page []byte | ||
| var err error | ||
| for i := len(vs) - 1; i >= 0 && i >= len(vs)-2; i-- { | ||
| if page, err = env.Get(ctx, f.At(vs[i].ID).URL()); err == nil { | ||
| break | ||
| } | ||
| } | ||
| if err != nil { | ||
| log.Printf("%s: what its releases pin isn't read this time: %v", f.API, err) | ||
| return vs | ||
| } | ||
| stated := pins(page) | ||
| for i := range vs { | ||
| if v, ok := stated[vs[i].ID]; ok { | ||
| vs[i].MapsTo = plugin.Pin{API: f.Pins, Version: v} | ||
| } | ||
| } | ||
| return vs | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| package changelog | ||
|
|
||
| import ( | ||
| "context" | ||
| "net/http" | ||
| "net/http/httptest" | ||
| "os" | ||
| "strings" | ||
| "testing" | ||
|
|
||
| "github.com/patch-it-dev/patch-it-plugins/core/kit/kittest" | ||
| "github.com/patch-it-dev/patch-it-plugins/core/plugin" | ||
| "github.com/patch-it-dev/patch-it-plugins/core/versions" | ||
| _ "github.com/patch-it-dev/patch-it-plugins/plugins/openapi" // registers stripe/api | ||
| ) | ||
|
|
||
| // Every pin the seven Stripe SDK sources read from their saved changelogs is | ||
| // a version stripe/api lists, from its saved release listing | ||
| // (../openapi/adapter/testdata/versions/): the pin and the listing name an API | ||
| // version the same way, so a feed query on an SDK's versions finds the API's. | ||
| func TestStripePinsAreVersionsStripeAPILists(t *testing.T) { | ||
| listing, err := os.ReadFile("../openapi/adapter/testdata/versions/stripe-openapi-releases.json") | ||
| if err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
| if r.URL.Path != "/repos/stripe/openapi/releases" || r.URL.Query().Get("page") != "1" { | ||
| t.Errorf("unexpected request %s", r.URL) | ||
| http.NotFound(w, r) | ||
| return | ||
| } | ||
| w.Write(listing) | ||
| })) | ||
| defer srv.Close() | ||
| old := versions.GitHubAPI | ||
| versions.GitHubAPI = srv.URL | ||
| defer func() { versions.GitHubAPI = old }() | ||
|
|
||
| api, ok := plugin.Lookup("stripe/api") | ||
| if !ok { | ||
| t.Fatal("stripe/api isn't registered") | ||
| } | ||
| vs, err := api.(plugin.Versioned).ListVersions(context.Background(), plugin.Env{}) | ||
| if err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| listed := map[string]bool{} | ||
| for _, v := range vs { | ||
| listed[v.ID] = true | ||
| } | ||
|
|
||
| n := 0 | ||
| for _, c := range []struct { | ||
| file File | ||
| tag string | ||
| }{ | ||
| {StripePython, "17.1.0"}, {StripeNode, "23.2.0"}, {StripeGo, "87.2.0"}, {StripeJava, "34.1.0"}, | ||
| {StripeRuby, "21.1.0"}, {StripeDotnet, "53.2.0"}, {StripePHP, "23.1.0"}, | ||
| } { | ||
| for release, pin := range pins(kittest.Read(t, "testdata/pins/"+strings.ReplaceAll(c.file.API, "/", "-")+"-"+c.tag+"-CHANGELOG.md")) { | ||
| n++ | ||
| if c.file.Pins != "stripe/api" || !listed[pin] { | ||
| t.Errorf("%s %s pins %s %s, which stripe/api doesn't list", c.file.API, release, c.file.Pins, pin) | ||
| } | ||
| } | ||
| } | ||
| if n == 0 { | ||
| t.Fatal("no pins read") | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,133 @@ | ||
| package changelog | ||
|
|
||
| import ( | ||
| "context" | ||
| "errors" | ||
| "maps" | ||
| "strings" | ||
| "testing" | ||
|
|
||
| "github.com/patch-it-dev/patch-it-plugins/core/kit/kittest" | ||
| "github.com/patch-it-dev/patch-it-plugins/core/plugin" | ||
| ) | ||
|
|
||
| // Each Stripe SDK's changelog at its newest tag, trimmed to the releases | ||
| // that state their pinned API version in each wording the SDKs use, and one | ||
| // that states none (testdata/README.md): what each release pins, exactly as | ||
| // stated, and nothing for the release that doesn't say. | ||
| func TestStripeReleasesStateWhatTheyPin(t *testing.T) { | ||
| for _, c := range []struct { | ||
| file File | ||
| tag string | ||
| want map[string]string | ||
| }{ | ||
| {StripePython, "17.1.0", map[string]string{"17.1.0": "2026-11-18.endive"}}, // 17.0.0 says nothing | ||
| {StripeNode, "23.2.0", map[string]string{"23.2.0": "2026-11-18.endive", "22.0.0": "2026-03-25.dahlia"}}, | ||
| {StripeGo, "87.2.0", map[string]string{"87.2.0": "2026-11-18.endive", "86.0.0": "2026-05-27.dahlia"}}, | ||
| {StripeJava, "34.1.0", map[string]string{"34.1.0": "2026-10-28.endive", "33.0.0": "2026-05-27.dahlia"}}, | ||
| {StripeRuby, "21.1.0", map[string]string{"21.1.0": "2026-11-18.endive"}}, | ||
| {StripeDotnet, "53.2.0", map[string]string{"53.2.0": "2026-11-18.endive", "52.0.0": "2026-05-27.dahlia"}}, | ||
| {StripePHP, "23.1.0", map[string]string{"23.1.0": "2026-11-18.endive", "21.0.0": "2026-06-24.dahlia"}}, | ||
| } { | ||
| t.Run(c.file.API, func(t *testing.T) { | ||
| if c.file.Pins != "stripe/api" { | ||
| t.Errorf("Pins %q, want stripe/api", c.file.Pins) | ||
| } | ||
| got := pins(kittest.Read(t, "testdata/pins/"+strings.ReplaceAll(c.file.API, "/", "-")+"-"+c.tag+"-CHANGELOG.md")) | ||
| if !maps.Equal(got, c.want) { | ||
| t.Errorf("got %v, want %v", got, c.want) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| // Listed, each version carries what its own section states it pins, read | ||
| // from the changelog at the newest version's tag; a version whose section | ||
| // says nothing pins nothing. | ||
| func TestListedVersionsCarryWhatTheyPin(t *testing.T) { | ||
| env := kittest.Env(t, kittest.Pages{ | ||
| "https://api.github.com/repos/stripe/stripe-go/tags?per_page=100&page=1": "testdata/versions/stripe-go-tags-pins.json", | ||
| StripeGo.At("87.2.0").URL(): "testdata/pins/stripe-go-87.2.0-CHANGELOG.md", | ||
| }) | ||
| vs, err := Plugin{File: StripeGo}.ListVersions(context.Background(), env) | ||
| if err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| var got []string | ||
| for _, v := range vs { | ||
| got = append(got, v.ID+"="+v.MapsTo.API+"@"+v.MapsTo.Version) | ||
| } | ||
| want := "86.0.0=stripe/api@2026-05-27.dahlia 86.4.2=@ 87.2.0=stripe/api@2026-11-18.endive" | ||
| if strings.Join(got, " ") != want { | ||
| t.Errorf("got %s\nwant %s", strings.Join(got, " "), want) | ||
| } | ||
| } | ||
|
|
||
| // A changelog that can't be fetched at the newest two tags leaves the listing | ||
| // as it is, pinning nothing; a source without Pins never fetches it. | ||
| func TestPinsAreReadOnlyWhenTheyCanBe(t *testing.T) { | ||
| tags := kittest.Read(t, "testdata/versions/stripe-go-tags-pins.json") | ||
| var fetched []string | ||
| env := plugin.Env{Get: func(_ context.Context, url string) ([]byte, error) { | ||
| fetched = append(fetched, url) | ||
| if strings.Contains(url, "/tags?") { | ||
| return tags, nil | ||
| } | ||
| return nil, errors.New("503") | ||
| }} | ||
| vs, err := Plugin{File: StripeGo}.ListVersions(context.Background(), env) | ||
| if err != nil || len(vs) != 3 { | ||
| t.Fatalf("%v, %d versions", err, len(vs)) | ||
| } | ||
| if len(fetched) != 3 { // the tags, then the newest two releases' changelogs | ||
| t.Errorf("fetched %v", fetched) | ||
| } | ||
| for _, v := range vs { | ||
| if !v.MapsTo.IsZero() { | ||
| t.Errorf("%s pins %v with no changelog read", v.ID, v.MapsTo) | ||
| } | ||
| } | ||
| unpinned := StripeGo | ||
| unpinned.Pins = "" | ||
| fetched = nil | ||
| if _, err := (Plugin{File: unpinned}).ListVersions(context.Background(), env); err != nil || len(fetched) != 1 { | ||
| t.Errorf("without Pins: %v, fetched %v", err, fetched) | ||
| } | ||
| } | ||
|
|
||
| // Two different versions in one release's section are none; a statement in | ||
| // a code block, or before the first release, is nobody's. | ||
| func TestAnUnsurePinIsNone(t *testing.T) { | ||
| got := pins([]byte("# Changelog\nThis release changes the pinned API version to `2020-01-01`.\n" + | ||
| "## 2.0.0 - 2026-01-02\nThis release changes the pinned API version to `2026-01-01.a`.\nThis release changes the pinned API version to `2026-01-02.b`.\n" + | ||
| "## 1.1.0 - 2026-01-01\n```\nThis release changes the pinned API version to `2025-12-01.a`.\n```\n" + | ||
| "## 1.0.0 - 2025-12-01\n* This release changes the pinned API version to `2025-11-01.a`.\n")) | ||
| if want := map[string]string{"1.0.0": "2025-11-01.a"}; !maps.Equal(got, want) { | ||
| t.Errorf("got %v, want %v", got, want) | ||
| } | ||
| // A "# comment" in a code example doesn't end the release's section. | ||
| got = pins([]byte("## 3.0.0 - 2026-02-01\n```sh\n# upgrade\n```\nThis release changes the pinned API version to `2026-02-01.c`.\n")) | ||
| if want := map[string]string{"3.0.0": "2026-02-01.c"}; !maps.Equal(got, want) { | ||
| t.Errorf("after a code block: got %v, want %v", got, want) | ||
| } | ||
| } | ||
|
|
||
| // When the newest release's tag can't be read yet, the one before's | ||
| // changelog says what the earlier releases pin. | ||
| func TestPinsFallBackToTheTagBefore(t *testing.T) { | ||
| tags := kittest.Read(t, "testdata/versions/stripe-go-tags-pins.json") | ||
| file := kittest.Read(t, "testdata/pins/stripe-go-87.2.0-CHANGELOG.md") | ||
| env := plugin.Env{Get: func(_ context.Context, url string) ([]byte, error) { | ||
| switch { | ||
| case strings.Contains(url, "/tags?"): | ||
| return tags, nil | ||
| case url == StripeGo.At("86.4.2").URL(): | ||
| return file, nil | ||
| } | ||
| return nil, errors.New("404") | ||
| }} | ||
| vs, err := Plugin{File: StripeGo}.ListVersions(context.Background(), env) | ||
| if err != nil || len(vs) != 3 || vs[0].MapsTo.Version != "2026-05-27.dahlia" { | ||
| t.Errorf("%v %+v", err, vs) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Non-blocking: the heading check runs before the fence check, so a
# commentline inside a fenced Ruby/Python/shell example (common in migration notes) ends the current release: any pin sentence after that code block in the same section is lost. That loses a pin rather than inventing one, so precision is fine. Moving the fence toggle above the heading check fixes it:(A changelog that never closes a fence would then hide every heading after it. If you care about that, also reset
fencedon a##heading.)