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

Allow for retrieving latest prerelease as data source. #1066

Closed

Conversation

youcandanch
Copy link
Contributor

@youcandanch youcandanch commented Feb 13, 2022

Description

Being able to retrieve the latest release from a given repository is awesome, but there's circumstances in which it'd be beneficial to grab the latest prerelease. In a continuous deployment workflow where there's a "prerelease" like environment (staging, preproduction, prerelease, rc, etc.) it'd be great to be able to pull the tag information directly from the provider, rather than having to skip out to the API to do it.

This PR introduces that functionality by allowing for passing latest_prerelease as a valid value to retrieve_by on the release data source. It's a little more involved than retrieving just the latest release, because the GitHub API at the moment doesn't allow for allowing prereleases as a flag on /latest. Instead, we're retrieving a few pages worth of releases, filtering out the prereleases, and selecting the most recently published one.

This does mean that there's a pretty substantial performance difference, as there's both more data to process and more requests being made.

@youcandanch
Copy link
Contributor Author

@kfcampbell anything I need to do on this to get it into a reviewable state? Haven't done work on the provider before so wanted to make sure I'm not missing anything. Thanks in advance!

Copy link
Member

@kfcampbell kfcampbell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had a couple of thoughts, and I approved the Action to run. Thanks for creating this!

Ideally we'd have a documentation update to go on the website for the latest_prerelease functionality as well.

Comment on lines +120 to +121
// TODO: 10 is sort of arbitrary here -- what's the best way to allow configurability
// for this to prevent the provider from becoming glacially slow on large repos?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an excellent question. Do you know what the max number of releases we can retrieve per page with the API?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

100 is the limit.

Comment on lines +126 to +143
for _, rel := range releases {
if *rel.Prerelease != true || *rel.Draft == true {
continue
}
if release == nil {
release = rel
} else {
if rel.PublishedAt.After(release.PublishedAt.Time) {
release = rel
}
}
}
if response.NextPage > nextPage {
nextPage = response.NextPage
} else {
break
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a little uncomfortable with this logic as-is. What do you think about refactoring it to a function like GetLatestRelease that we could write a unit test for?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I like that. Will take a stab at it this weekend.

@kfcampbell kfcampbell added this to the v4.22.0 milestone Mar 3, 2022
@kfcampbell kfcampbell removed this from the v4.22.0 milestone Mar 18, 2022
@youcandanch
Copy link
Contributor Author

Still haven't had a moment to swing back to this, but I did open a post on the GitHub community for something similar: https://github.community/t/release-api-should-include-a-way-to-retrieve-the-latest-prerelease/239836

It'd be more ideal to handle it at the API level, I think, though that's an ask for core GitHub team and I imagine a fairly large one to think through.

@nickfloyd nickfloyd added the Status: Stale Used by stalebot to clean house label Nov 30, 2022
@nickfloyd
Copy link
Contributor

👋 Hey Friends, this issue has been automatically marked as stale because it has no recent activity. It will be closed if no further activity occurs. Please add the Status: Pinned label if you feel that this issue needs to remain open/active. Thank you for your contributions and help in keeping things tidy!

@github-actions github-actions bot removed the Status: Stale Used by stalebot to clean house label Dec 1, 2022
@github-actions
Copy link

👋 Hey Friends, this pull request has been automatically marked as stale because it has no recent activity. It will be closed if no further activity occurs. Please add the Status: Pinned label if you feel that this issue needs to remain open/active. Thank you for your contributions and help in keeping things tidy!

@github-actions github-actions bot added the Status: Stale Used by stalebot to clean house label Aug 29, 2023
@github-actions github-actions bot closed this Sep 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Stale Used by stalebot to clean house
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants