XAMPPRocky / octocrab

A modern, extensible GitHub API Client for Rust.
Other
1.06k stars 258 forks source link

Create commit from tree SHA #571

Closed tniessen closed 5 months ago

tniessen commented 7 months ago

I'm trying to migrate from octokit to octocrab and I am using this workaround to create a commit from an existing tree SHA without updating any git references:

#[derive(Deserialize)]
#[serde(rename_all = "snake_case")]
#[non_exhaustive]
struct CreatedCommit {
    pub sha: String,
}

async fn create_commit(
    octocrab: &octocrab::Octocrab,
    owner: &str,
    repo: &str,
    message: &str,
    tree_sha: &str,
) -> octocrab::Result<CreatedCommit> {
    let route = format!("/repos/{owner}/{repo}/git/commits");

    octocrab
        .post(
            route,
            Some(&serde_json::json!({
                "message": message,
                "tree": tree_sha
            })),
        )
        .await
}

However, it would be great if octocrab had a built-in function to do this, including all relevant parameters and result fields, similar to octokit. (Perhaps it already exists and I simply haven't found it yet!)

dmgorsky commented 6 months ago

like this? https://github.com/XAMPPRocky/octocrab/pull/600/files#diff-535bb8ce6289b0a73b9e48df5f082035643112bf1bb868100dd2923d6bbbbdb5R704 @tniessen

tniessen commented 6 months ago

@dmgorsky Looks great to me! I'll test it once https://github.com/XAMPPRocky/octocrab/pull/597 is released!

tniessen commented 5 months ago

@dmgorsky Works like a charm as far as I can tell, thank you!