Skip to content

Commit

Permalink
Merge pull request #1729 from ehuss/fix-github_releases-octocrab
Browse files Browse the repository at this point in the history
Fix github_releases with invalid URIs
  • Loading branch information
Mark-Simulacrum authored Oct 5, 2023
2 parents f7a3336 + c2e5cfb commit ebad750
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/handlers/github_releases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub(super) async fn handle(
log::debug!("loading the git tags");
let tags = load_paginated(
ctx,
&format!("repos/{}/git/matching-refs/tags", event.repo().full_name),
&format!("/repos/{}/git/matching-refs/tags", event.repo().full_name),
|git_ref: &GitRef| {
git_ref
.name
Expand All @@ -54,7 +54,7 @@ pub(super) async fn handle(
log::debug!("loading the existing releases");
let releases = load_paginated(
ctx,
&format!("repos/{}/releases", event.repo().full_name),
&format!("/repos/{}/releases", event.repo().full_name),
|release: &Release| release.tag_name.clone(),
)
.await?;
Expand Down Expand Up @@ -85,7 +85,7 @@ pub(super) async fn handle(
let e: octocrab::Result<serde_json::Value> = ctx
.octocrab
.post(
format!("repos/{}/releases", event.repo().full_name),
format!("/repos/{}/releases", event.repo().full_name),
Some(&serde_json::json!({
"tag_name": tag,
"name": expected_name,
Expand Down Expand Up @@ -141,15 +141,24 @@ where
R: Eq + PartialEq + std::hash::Hash,
F: Fn(&T) -> R,
{
let mut current_page: Page<T> = ctx.octocrab.get::<Page<T>, _, ()>(url, None).await?;
let mut current_page: Page<T> = ctx
.octocrab
.get::<Page<T>, _, ()>(url, None)
.await
.with_context(|| format!("failed to load {url}"))?;

let mut items = current_page
.take_items()
.into_iter()
.map(|val| (key(&val), val))
.collect::<HashMap<R, T>>();

while let Some(mut new_page) = ctx.octocrab.get_page::<T>(&current_page.next).await? {
while let Some(mut new_page) = ctx
.octocrab
.get_page::<T>(&current_page.next)
.await
.with_context(|| format!("failed to load next page {:?}", current_page.next))?
{
items.extend(
new_page
.take_items()
Expand Down

0 comments on commit ebad750

Please sign in to comment.