octocrab icon indicating copy to clipboard operation
octocrab copied to clipboard

create_workflow_dispatch failed with GitHubError

Open siisee11 opened this issue 1 year ago • 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

siisee11 avatar Apr 02 '24 06:04 siisee11

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,

siisee11 avatar Apr 02 '24 07:04 siisee11

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?

XAMPPRocky avatar Apr 02 '24 08:04 XAMPPRocky

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

aarchangel64 avatar Sep 15 '24 21:09 aarchangel64

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

siisee11 avatar Sep 16 '24 15:09 siisee11