XAMPPRocky / octocrab

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

create_workflow_dispatch failed with GitHubError #622

Open siisee11 opened 6 months ago

siisee11 commented 6 months ago
   octocrab
        .actions()
        .create_workflow_dispatch("owner", "repo", workflow_id, "develop")
        .send()
        .await?;

create_workflow_dispatch failed with GitHubError

Error message is Invalid request.\n\nFor 'properties/inputs', nil is not an object

siisee11 commented 6 months ago

https://github.com/XAMPPRocky/octocrab/blob/505befed0e40faa15321772009a814f6f510f614/src/models/workflows.rs#L154C1-L159C2

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default)]
#[non_exhaustive]
pub struct WorkflowDispatch {
    pub r#ref: String,
    pub inputs: serde_json::Value,
}

Maybe should be changed to

    pub ref: String,
XAMPPRocky commented 6 months ago

Thank you for your issue!

Maybe should be changed to

   pub ref: String,

Not possible, ref is a keyword in Rust, so it has to be r#ref. Are you sure that's what's causing the issue and not that inputs is Value::Null instead of Value::Object?

aarchangel64 commented 3 weeks ago

I'm also having this issue. I was able to fix it by adding inputs as a workaround, but it's not ideal to need this:

   octocrab
        .actions()
        .create_workflow_dispatch("owner", "repo", workflow_id, "develop")
        .inputs(serde_json::json!({}))
        .send()
        .await?;
siisee11 commented 2 weeks ago

@XAMPPRocky Sorry, I didn't see the notification earlier. It's been a while, so I don't remember exactly what the issue was. I'm not very familiar with Rust, but I'll share the workaround I came up with.

let route = format!(
        "https://api.github.com/repos/{owner}/{repo}/actions/workflows/{workflow_id}/dispatches",
        owner = owner,
        repo = repo_name,
        workflow_id = workflow_id
    );

let res = octocrab
        ._post(route, Some(&serde_json::json!({ "ref": "develop"})))
        .await?;