Skip to content

Commit 5f5fb60

Browse files
committed
rust: use octocrab API for fetching artifacts
The important change here is we consume all pages. Previously, we only consumed the first page and were missing artifacts.
1 parent c99baf7 commit 5f5fb60

File tree

1 file changed

+13
-32
lines changed

1 file changed

+13
-32
lines changed

src/github.rs

Lines changed: 13 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ use {
66
anyhow::{anyhow, Result},
77
clap::ArgMatches,
88
futures::StreamExt,
9-
octocrab::{Octocrab, OctocrabBuilder},
9+
octocrab::{models::workflows::WorkflowListArtifact, Octocrab, OctocrabBuilder},
1010
once_cell::sync::Lazy,
11-
serde::Deserialize,
1211
std::{
1312
collections::{BTreeMap, BTreeSet},
1413
io::Read,
@@ -50,30 +49,10 @@ static SUFFIXES_BY_TRIPLE: Lazy<BTreeMap<&'static str, Vec<&'static str>>> = Laz
5049
h
5150
});
5251

53-
#[derive(Clone, Debug, Deserialize)]
54-
struct Artifact {
55-
archive_download_url: String,
56-
created_at: String,
57-
expired: bool,
58-
expires_at: String,
59-
id: u64,
60-
name: String,
61-
node_id: String,
62-
size_in_bytes: u64,
63-
updated_at: String,
64-
url: String,
65-
}
66-
67-
#[derive(Clone, Debug, Deserialize)]
68-
struct Artifacts {
69-
artifacts: Vec<Artifact>,
70-
total_count: u64,
71-
}
72-
73-
async fn fetch_artifact(client: &Octocrab, artifact: Artifact) -> Result<bytes::Bytes> {
52+
async fn fetch_artifact(client: &Octocrab, artifact: WorkflowListArtifact) -> Result<bytes::Bytes> {
7453
println!("downloading {}", artifact.name);
7554
let res = client
76-
.execute(client.request_builder(&artifact.archive_download_url, reqwest::Method::GET))
55+
.execute(client.request_builder(artifact.archive_download_url, reqwest::Method::GET))
7756
.await?;
7857

7958
Ok(res.bytes().await?)
@@ -125,17 +104,19 @@ pub async fn command_fetch_release_distributions(args: &ArgMatches<'_>) -> Resul
125104
let mut fs = vec![];
126105

127106
for run in runs {
128-
let res = client
129-
.execute(client.request_builder(run.artifacts_url, reqwest::Method::GET))
107+
let page = client
108+
.actions()
109+
.list_workflow_run_artifacts(org, repo, run.id)
110+
.send()
130111
.await?;
131112

132-
if !res.status().is_success() {
133-
return Err(anyhow!("non-HTTP 200 fetching artifacts"));
134-
}
135-
136-
let artifacts: Artifacts = res.json().await?;
113+
let artifacts = client
114+
.all_pages::<octocrab::models::workflows::WorkflowListArtifact>(
115+
page.value.expect("untagged request should have page"),
116+
)
117+
.await?;
137118

138-
for artifact in artifacts.artifacts {
119+
for artifact in artifacts {
139120
if matches!(
140121
artifact.name.as_str(),
141122
"pythonbuild" | "sccache" | "toolchain"

0 commit comments

Comments
 (0)