-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Go: Make models-as-data package column match any version without "$ANYVERSION" #16799
Go: Make models-as-data package column match any version without "$ANYVERSION" #16799
Conversation
I don't think this needs a change note because models-as-data is in beta for Go. I am happy to add one if someone wants, though. |
Click to show differences in coveragegoGenerated file changes for go
- Others,"``github.com/go-jose/go-jose/$ANYVERSION/jwt``, ``gopkg.in/square/go-jose.v2/jwt``",,8,2
+ Others,"``github.com/go-jose/go-jose/jwt``, ``gopkg.in/square/go-jose.v2/jwt``",,8,2
- github.com/go-jose/go-jose/$ANYVERSION/jwt,1,,4,,1,,4,
+ github.com/go-jose/go-jose/jwt,1,,4,,1,,4,
- github.com/go-pg/pg/$ANYVERSION/orm,,,6,,,,6,
+ github.com/go-pg/pg/orm,,,6,,,,6,
- github.com/golang/protobuf/$ANYVERSION/proto,,,4,,,,4,
+ github.com/golang/protobuf/proto,,,4,,,,4,
- github.com/kataras/iris/$ANYVERSION/middleware/jwt,1,,,1,,,,
+ github.com/kataras/iris/middleware/jwt,1,,,1,,,,
- github.com/lestrrat-go/jwx/$ANYVERSION/jwk,1,,,1,,,,
+ github.com/lestrrat-go/jwx/jwk,1,,,1,,,,
- github.com/sendgrid/sendgrid-go/$ANYVERSION/helpers/mail,,,1,,,,1,
+ github.com/sendgrid/sendgrid-go/helpers/mail,,,1,,,,1,
- golang.org/x/net/$ANYVERSION/html,,,16,,,,16,
+ golang.org/x/net/html,,,16,,,,16,
- google.golang.org/protobuf/$ANYVERSION/internal/encoding/text,,,1,,,,1,
+ google.golang.org/protobuf/internal/encoding/text,,,1,,,,1,
- google.golang.org/protobuf/$ANYVERSION/internal/impl,,,2,,,,2,
+ google.golang.org/protobuf/internal/impl,,,2,,,,2,
- google.golang.org/protobuf/$ANYVERSION/proto,,,8,,,,8,
+ google.golang.org/protobuf/proto,,,8,,,,8,
- google.golang.org/protobuf/$ANYVERSION/reflect/protoreflect,,,1,,,,1,
+ google.golang.org/protobuf/reflect/protoreflect,,,1,,,,1,
- k8s.io/apimachinery/$ANYVERSION/pkg/runtime,,,47,,,,47,
+ k8s.io/apimachinery/pkg/runtime,,,47,,,,47, |
DCA shows nothing interesting. |
if p.suffix(p.length() - thisVersion.length()) = thisVersion | ||
then result = p.prefix(p.length() - 12) | ||
else |
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.
Perhaps slightly simpler:
if p.suffix(p.length() - thisVersion.length()) = thisVersion | |
then result = p.prefix(p.length() - 12) | |
else | |
p = result + thisVersion | |
or | |
not p = any(string s) + thisVersion and |
* | ||
* If `p` has `$THISVERSION` at the end then we remove that and do not attempt | ||
* to match any other versions of the same package. If `p` contains a major | ||
* version suffix (like "/v2") then we also do not attempt to match any |
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.
qldoc terminates a bit abruptly.
There was a bug in the regex where it had an unwanted $ at the end. This was introduced by copilot, and I didn't check it carefully enough. I could have just copy-pasted it from the other location where I had the correct regex. (Should I try to only specify the regex in one place?) |
If you want - I don't have a strong opinion on that. OTOH, if you need to account for specifically not matching something like |
Good idea about using lookahead. I don't think it's very likely that we'll come across that, but it's better to be safe than sorry. |
The QA results look fine so I'm marking this ready to review. |
Looks sensible except that the syntax is a bit weird: the |
I like the suggestion. I think we could be a bit clearer than "versioned". I think "fixed-version" would be clearer, so I'll implement that. |
Currently, "fixed-version:" is only needed for v0 and v1 (because having "/v3" in the package column will have the same effect). Here's an idea, to get more functionality:
Or maybe introduce "min-version:github.com/a/b/v4/c" to match version 4 and higher, and a corresponding "max-version:". Alternatively, we could use the existing range syntax, like "v[2..4]", "v[..4]" and "v[3..]" (though I don't think we allow open-ended ranges in go at the moment). I don't think we need to implement any of these now, but we could in future if we find that we need it. |
In future sounds wise :) Fixed = fixed, default = any seems fine for now. |
The test failure is unrelated and will be fixed tomorrow. I think this is ready to merge once I've rerun the tests tomorrow. |
Note that if the package column contains major version suffix (like "/v2") or if it ends with "$THISVERSION" (which is removed) then we don't do any version matching.
I accidentally included a `$` at the end, so it only matched a major version suffix at the end of the package path.
Co-authored-by: Anders Schack-Mulligen <aschackmull@users.noreply.github.com>
e3a806b
to
a30b34c
Compare
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.
Looks good -- suggest editing the PR title and description (and commit messages?) for future readers' sake.
Currently a models-as-data package column like "github.com/a/b/c/d" will match the import path for any major version, but only if the major version suffix (like "/v2") goes at the end ("github.com/a/b/c/d/v2"). If the module path is "github.com/a/b" then we actually want to match ""github.com/a/b/v2/c/d". At the moment this is possible by putting "github.com/a/b/$ANYVERSION/c/d" in the package column.
This PR changes that so we will match major version suffixes at the correct place in the package path.
There are times when we only want to match a specific version of a package. If the package column contains a major version suffix (like "/v2") or if it starts with "fixed-version:" then we don't do any version matching (and prefix is removed).