Skip to content

Commit

Permalink
github action: fix event payload type of repository dispatch, because…
Browse files Browse the repository at this point in the history
… toml value cannot and won't accept null value. see toml-lang/toml#30 (comment)
  • Loading branch information
umegaya committed Aug 26, 2022
1 parent 1d6a980 commit 5d5f78d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
4 changes: 2 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@
]
},
{
"name": "Start",
"name": "Boot",
"type": "lldb",
"request": "launch",
"program": "${workspaceFolder}/target/debug/cli",
"args": [
"-v=3", "start", "-r=nightly", "-w=integrate"
"-v=3", "boot", "-p=payload.json"
]
},
{
Expand Down
17 changes: 6 additions & 11 deletions core/src/ci/ghaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use chrono::{Utc, Duration};
use log;
use maplit::hashmap;
use serde::{Deserialize, Serialize};
use serde_json::{Value as JsonValue};

use crate::config;
use crate::ci;
Expand All @@ -34,7 +35,7 @@ enum EventPayload {
// to avoid wrongly being matched as 'Repository' variant.
RepositoryDispatch {
action: String,
client_payload: config::AnyValue
client_payload: JsonValue
},
Repository {
action: Option<String>
Expand Down Expand Up @@ -601,22 +602,16 @@ impl<S: shell::Shell> ci::CI for GhAction<S> {
_ => {}
},
// repository_dispatch has a few possibility.
// config::DEPLO_REMOTE_JOB_EVENT_TYPE => should contain workflow_name in client_payload
// config::DEPLO_REMOTE_JOB_EVENT_TYPE => should contain workflow name in client_payload["name"]
// config::DEPLO_MODULE_EVENT_TYPE => Module workflow invocation
// others => Repository workflow invocation
"repository_dispatch" => if let EventPayload::RepositoryDispatch{
action, client_payload
} = &workflow_event.event {
if action == config::DEPLO_REMOTE_JOB_EVENT_TYPE {
match client_payload.index("workflow_name") {
Some(n) => match n.as_str() {
Some(s) => matched_names.push(s.to_string()),
None => panic!(
"{}: event payload invalid {}",
config::DEPLO_REMOTE_JOB_EVENT_TYPE, client_payload
)
},
None => panic!(
match &client_payload["name"] {
JsonValue::String(s) => matched_names.push(s.to_string()),
_ => panic!(
"{}: event payload invalid {}",
config::DEPLO_REMOTE_JOB_EVENT_TYPE, client_payload
)
Expand Down
8 changes: 7 additions & 1 deletion core/src/config/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,13 @@ pub struct Any {
impl<'de> Deserialize<'de> for Any {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de> {
let any = AnyValue::deserialize(deserializer)?;
let any = match AnyValue::deserialize(deserializer) {
Ok(v) => v,
Err(e) => {
log::error!("deserialize error: {}", e);
return Err(e);
}
};
return match any {
AnyValue::String(ref v) => {
let (value, resolver) = detect_value_ref(v);
Expand Down

0 comments on commit 5d5f78d

Please sign in to comment.