Skip to content
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

github resolver shorthand hardcodes default branch #40

Open
pbrisbin opened this issue Jul 8, 2021 · 8 comments
Open

github resolver shorthand hardcodes default branch #40

pbrisbin opened this issue Jul 8, 2021 · 8 comments

Comments

@pbrisbin
Copy link

pbrisbin commented Jul 8, 2021

We're experimenting with remote, custom snapshots and wanted to use the github:user:repo:path shorthand, but we can't because we use main as our default branch and it expands to master.

I'm not sure how you would go about addressing this limitation, but I just wanted to raise it and see what you thought. I'm happy to implement the fix, if we can come up with one.

@pbrisbin
Copy link
Author

pbrisbin commented Jul 8, 2021

And, I immediately had an idea. What about,

resolver: github:user:repo:path@ref

Where @master is the default, preserving the behavior of all existing code. One could specify tags or branches there, which sounds useful in general.

@qrilka
Copy link
Contributor

qrilka commented Jul 8, 2021

@pbrisbin
Copy link
Author

pbrisbin commented Jul 8, 2021

What version of the object does the contents/ API return? I assume it's "latest on default branch". If so, then yeah that totally unblocks me to use main. However, my follow-up @ref idea gives you more, since users could pull tags or other branches by that mechanism.

@qrilka
Copy link
Contributor

qrilka commented Jul 8, 2021

Sure, the point is to have @ref optional and use the default branch correctly

@pbrisbin
Copy link
Author

pbrisbin commented Jul 8, 2021

I don't think we can do both, can we?

  1. Respect @ref, default to @master when missing, continue with raw.github.com/...
  2. Fetch api.github.com/.../contents

(1) will open up @ref syntax generally, but when not used continues to hard-code master.

(2) will respect default branch, but cannot be used to select not default branch.

What am I missing?

@qrilka
Copy link
Contributor

qrilka commented Jul 8, 2021

I guess we should have information whether @ref was specified or not and use either raw.github.com or api.github.com. That would slightly complicate the code but will be slightly more user-friendly.

@qrilka
Copy link
Contributor

qrilka commented Jul 8, 2021

BTW api.github.com also supports branches, see https://api.github.com/repos/commercialhaskell/stack/contents/README.md?ref=master

@pbrisbin
Copy link
Author

pbrisbin commented Jul 8, 2021

Neat. Seems like API + ?ref would be ideal. Could be tricky implementation-wise, since the code in question here is pure:

githubSnapshotLocation :: Text -> Text -> Text -> RawSnapshotLocation

And expected to give a URL directly to the content (not to an API with a .content field).

I like the way Pantry's machinery (unlike templates) is just a series of syntactic expansions from (e.g.) lts-X.Y to github:commercialhaskell:stackage-snapshots:/lts/X/Y.yaml to https://raw.github.com/.... Introducing, the API call and .content access kind of breaks that. But it would be valuable for omiting @ref to result in respecting default branch, instead of a static default.

So maybe worth it, but it would expand the diff significantly to implement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants