-
Notifications
You must be signed in to change notification settings - Fork 1k
add SourceURLsForPath() to SourceManager interface #1166
add SourceURLsForPath() to SourceManager interface #1166
Conversation
to expose the deduced possible source URLs for a given import path. This information is useful for importing configuration from other tools that support vendoring forks
CodeClimate doesn't like me using |
Don't worry about the code climate error, we can ignore it when we merge. |
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.
this looks generally good, and is hooking into the right test. basically just some nits on wording in errors and docs!
internal/gps/maybe_source.go
Outdated
for _, url := range mb.possibleURLs() { | ||
urls += url.String() + "\n" | ||
} | ||
errs = append(errs, errors.Wrapf(err, "failed to set up %q", urls)) |
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.
nit: let's make an incremental improvement on the output we currently have and change the message to "failed to set sources from the following URLs:\n%s"
.
(note also, use %s
instead of %q
, as otherwise we'll end up quoting the whole group of URLs, which i don't think makes a ton of sense.)
internal/gps/source_manager.go
Outdated
@@ -71,6 +72,9 @@ type SourceManager interface { | |||
// project/source root. | |||
DeduceProjectRoot(ip string) (ProjectRoot, error) | |||
|
|||
// SourceURLsForPath takes an import path and deduces the possible source URLs |
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.
let's be a little more verbose and explanatory with this:
"SourceURLsForPath takes an import path and deduces the set of source URLs that may refer to a canonical upstream source. In general, these URLs differ only by protocol (e.g. https vs. ssh), not path."
Thanks @sdboyer, fixed the comment & error string |
internal/gps/maybe_source.go
Outdated
for _, url := range mb.possibleURLs() { | ||
urls += url.String() + "\n" | ||
} | ||
errs = append(errs, errors.Wrapf(err, "failed to set sources from the following URLs:\n%s", urls)) |
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.
🤦♂️
i fatfingered that. i meant "failed to set up sources from the following URLs:\n"
- sorry!
Thanks @sdboyer - fixed the typo |
and an error msg in `maybeSources.try()`
450d24f
to
348b869
Compare
What does this do / why do we need it?
This exposes all possible source URLs that are deduced for a given import path.
This PR was created to accommodate #1149 (
gvt
importer), following @sdboyer 's advice.gvt
allows the user to specify an alternate url (e.g. fork) for a vendored import, via theRepository
field in the manifest. However, all packages that are listed in the manifest have theRepository
field even if it points to the original source URL.gps
already has a complex logic of deducing the source URLs given an import, however the actual URLs are not exposed to the callers of SourceManager. The new exportedSourceURLsForPath()
will allow the importers to understand if the a URL is a not a default one, and only in such a case, pass it as a constraint.This change required a slight modification to
gps
's internalmaybeSource
interface and some refactoring to the various implementations: thegetURL() string
method (which wasn't called anywhere) was changed topossibleURLs() []*url.URL
. In addition a small change was done to thegopkg.in
deducer.