XAMPPRocky/octocrab

create_workflow_dispatch failed with GitHubError

Opened this issue · 4 comments

   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

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,

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?

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?;

@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?;