XAMPPRocky/octocrab

Create commit from tree SHA

Closed this issue · 3 comments

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 Looks great to me! I'll test it once #597 is released!

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