diff --git a/bin/core/src/listener/resources.rs b/bin/core/src/listener/resources.rs index 1ca4ad749..7b0f7823b 100644 --- a/bin/core/src/listener/resources.rs +++ b/bin/core/src/listener/resources.rs @@ -132,11 +132,6 @@ impl RepoExecution for BuildRepo { } } -#[derive(Deserialize)] -pub struct RepoWebhookPath { - pub option: RepoWebhookOption, -} - #[derive(Deserialize)] #[serde(rename_all = "lowercase")] pub enum RepoWebhookOption { @@ -244,11 +239,6 @@ impl StackExecution for DeployStack { } } -#[derive(Deserialize)] -pub struct StackWebhookPath { - pub option: StackWebhookOption, -} - #[derive(Deserialize)] #[serde(rename_all = "lowercase")] pub enum StackWebhookOption { @@ -340,11 +330,6 @@ impl SyncExecution for RunSync { } } -#[derive(Deserialize)] -pub struct SyncWebhookPath { - pub option: SyncWebhookOption, -} - #[derive(Deserialize)] #[serde(rename_all = "lowercase")] pub enum SyncWebhookOption { @@ -410,7 +395,7 @@ fn procedure_locks() -> &'static ListenerLockCache { pub async fn handle_procedure_webhook( procedure: Procedure, - target_branch: String, + target_branch: &str, body: String, ) -> anyhow::Result<()> { // Acquire and hold lock to make a task queue for @@ -457,7 +442,7 @@ fn action_locks() -> &'static ListenerLockCache { pub async fn handle_action_webhook( action: Action, - target_branch: String, + target_branch: &str, body: String, ) -> anyhow::Result<()> { // Acquire and hold lock to make a task queue for diff --git a/bin/core/src/listener/router.rs b/bin/core/src/listener/router.rs index f5bfcac7e..491b69bf9 100644 --- a/bin/core/src/listener/router.rs +++ b/bin/core/src/listener/router.rs @@ -14,8 +14,8 @@ use super::{ resources::{ handle_action_webhook, handle_build_webhook, handle_procedure_webhook, handle_repo_webhook, - handle_stack_webhook, handle_sync_webhook, RepoWebhookPath, - StackWebhookPath, SyncWebhookPath, + handle_stack_webhook, handle_sync_webhook, RepoWebhookOption, + StackWebhookOption, SyncWebhookOption, }, CustomSecret, VerifyBranch, VerifySecret, }; @@ -26,7 +26,14 @@ struct Id { } #[derive(Deserialize)] -struct Branch { +struct IdAndOption { + id: String, + option: T, +} + +#[derive(Deserialize)] +struct IdAndBranch { + id: String, #[serde(default = "default_branch")] branch: String, } @@ -66,7 +73,7 @@ pub fn router() -> Router { .route( "/repo/:id/:option", post( - |Path(Id { id }), Path(RepoWebhookPath { option }), headers: HeaderMap, body: String| async move { + |Path(IdAndOption:: { id, option }), headers: HeaderMap, body: String| async move { let repo = auth_webhook::(&id, headers, &body).await?; tokio::spawn(async move { @@ -92,7 +99,7 @@ pub fn router() -> Router { .route( "/stack/:id/:option", post( - |Path(Id { id }), Path(StackWebhookPath { option }), headers: HeaderMap, body: String| async move { + |Path(IdAndOption:: { id, option }), headers: HeaderMap, body: String| async move { let stack = auth_webhook::(&id, headers, &body).await?; tokio::spawn(async move { @@ -118,7 +125,7 @@ pub fn router() -> Router { .route( "/sync/:id/:option", post( - |Path(Id { id }), Path(SyncWebhookPath { option }), headers: HeaderMap, body: String| async move { + |Path(IdAndOption:: { id, option }), headers: HeaderMap, body: String| async move { let sync = auth_webhook::(&id, headers, &body).await?; tokio::spawn(async move { @@ -144,19 +151,19 @@ pub fn router() -> Router { .route( "/procedure/:id/:branch", post( - |Path(Id { id }), Path(Branch { branch }), headers: HeaderMap, body: String| async move { + |Path(IdAndBranch { id, branch }), headers: HeaderMap, body: String| async move { let procedure = auth_webhook::(&id, headers, &body).await?; tokio::spawn(async move { let span = info_span!("ProcedureWebhook", id); async { let res = handle_procedure_webhook::

( - procedure, branch, body, + procedure, &branch, body, ) .await; if let Err(e) = res { warn!( - "Failed at running webhook for procedure {id} | {e:#}" + "Failed at running webhook for procedure {id} | target branch: {branch} | {e:#}" ); } } @@ -170,19 +177,19 @@ pub fn router() -> Router { .route( "/action/:id/:branch", post( - |Path(Id { id }), Path(Branch { branch }), headers: HeaderMap, body: String| async move { + |Path(IdAndBranch { id, branch }), headers: HeaderMap, body: String| async move { let action = auth_webhook::(&id, headers, &body).await?; tokio::spawn(async move { let span = info_span!("ActionWebhook", id); async { let res = handle_action_webhook::

( - action, branch, body, + action, &branch, body, ) .await; if let Err(e) = res { warn!( - "Failed at running webhook for action {id} | {e:#}" + "Failed at running webhook for action {id} | target branch: {branch} | {e:#}" ); } } diff --git a/client/core/ts/src/types.ts b/client/core/ts/src/types.ts index 99eed357b..148165e60 100644 --- a/client/core/ts/src/types.ts +++ b/client/core/ts/src/types.ts @@ -1,5 +1,5 @@ /* - Generated by typeshare 1.11.0 + Generated by typeshare 1.12.0 */ export interface MongoIdObj { diff --git a/docsite/docs/webhooks.md b/docsite/docs/webhooks.md index 24bd20b54..cf5515339 100644 --- a/docsite/docs/webhooks.md +++ b/docsite/docs/webhooks.md @@ -30,7 +30,7 @@ https://${HOST}/listener/${AUTH_TYPE}/${RESOURCE_TYPE}/${ID_OR_NAME}/${EXECUTION - **`EXECUTION`**: - Which executions are available depends on the `RESOURCE_TYPE`. Builds only have the `/build` action. Repos can select between `/pull`, `/clone`, or `/build`. Stacks have `/deploy` and `/refresh`, and Resource Syncs have `/sync` and `/refresh`. - - For **Procedures and Actions**, this will be the **branch to listen to for pushes**, or `__ALL__` to trigger + - For **Procedures and Actions**, this will be the **branch to listen to for pushes**, or `__ANY__` to trigger on pushes to any branch. ## Create the webhook on the Git Provider diff --git a/frontend/public/client/types.js b/frontend/public/client/types.js index ea96da7eb..b7c09b6b2 100644 --- a/frontend/public/client/types.js +++ b/frontend/public/client/types.js @@ -1,5 +1,5 @@ /* - Generated by typeshare 1.11.0 + Generated by typeshare 1.12.0 */ /** The levels of permission that a User or UserGroup can have on a resource. */ export var PermissionLevel; diff --git a/frontend/src/components/resources/action/config.tsx b/frontend/src/components/resources/action/config.tsx index 6ea844a00..0389d3213 100644 --- a/frontend/src/components/resources/action/config.tsx +++ b/frontend/src/components/resources/action/config.tsx @@ -118,17 +118,17 @@ export const ActionConfig = ({ id }: { id: string }) => { value={branch} onChange={(e) => setBranch(e.target.value)} className="w-[200px]" - disabled={branch === "__ALL__"} + disabled={branch === "__ANY__"} />

All branches:
{ if (checked) { - setBranch("__ALL__"); + setBranch("__ANY__"); } else { setBranch("main"); } diff --git a/frontend/src/components/resources/procedure/config.tsx b/frontend/src/components/resources/procedure/config.tsx index 11ed470fe..3a28093ea 100644 --- a/frontend/src/components/resources/procedure/config.tsx +++ b/frontend/src/components/resources/procedure/config.tsx @@ -238,17 +238,17 @@ const ProcedureConfigInner = ({ value={branch} onChange={(e) => setBranch(e.target.value)} className="w-[200px]" - disabled={branch === "__ALL__"} + disabled={branch === "__ANY__"} />
All branches:
{ if (checked) { - setBranch("__ALL__"); + setBranch("__ANY__"); } else { setBranch("main"); }