Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create commit from tree SHA #571

Closed
tniessen opened this issue Feb 9, 2024 · 3 comments
Closed

Create commit from tree SHA #571

tniessen opened this issue Feb 9, 2024 · 3 comments

Comments

@tniessen
Copy link
Contributor

tniessen commented Feb 9, 2024

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
Copy link
Contributor

dmgorsky commented Mar 7, 2024

@tniessen
Copy link
Contributor Author

tniessen commented Mar 8, 2024

@dmgorsky Looks great to me! I'll test it once #597 is released!

@tniessen
Copy link
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants