octocrab icon indicating copy to clipboard operation
octocrab copied to clipboard

Add method for downloading job logs

Open raine opened this issue 2 years ago • 4 comments

The existing download_workflow_run_logs method in actions() allows downloading logs for the full run.

It would be great to be able to download logs for a job: https://api.github.com/repos/:owner/:repo/actions/jobs/:job_id/logs

raine avatar Jun 11 '23 07:06 raine

My workaround:

pub async fn get_job_logs(repo: &Repository, job_id: u64) -> Result<hyper::body::Bytes> {
    let client = octocrab::instance();
    let route = format!(
        "/repos/{owner}/{repo}/actions/jobs/{job_id}/logs",
        owner = repo.owner,
        repo = repo.name,
        job_id = job_id,
    );
    let uri = Uri::builder().path_and_query(route).build()?;
    let data_response = client
        .follow_location_to_data(client._get(uri).await?)
        .await?;
    let body = data_response.into_body();
    body::to_bytes(body).await.map_err(Into::into)
}

Good thing the internal methods like _get and follow_location_to_data are exposed.

raine avatar Jun 11 '23 07:06 raine

Thank you for your issue! I don't have time to add this myself, but I'd be happy to review and accept a PR adding it (generally the convention should follow octokit.js)

Good thing the internal methods like _get and follow_location_to_data are exposed.

Yes, this is an intentional design decision so that you never have to fork Octocrab to add a method that might be new or missing.

XAMPPRocky avatar Jun 11 '23 09:06 XAMPPRocky

Hi, I'd like to work on this one if you don't mind @XAMPPRocky

kon3gor avatar Jun 14 '23 18:06 kon3gor

Feel free to make a PR 🙂

XAMPPRocky avatar Jun 15 '23 04:06 XAMPPRocky