automator_github_pro_event_repo_conditional_tokens_hydrate
Filter GitHub conditional token hydration based on the event type selection. Filters GitHub conditional tokens before hydration, allowing modification based on event type.
add_filter( 'automator_github_pro_event_repo_conditional_tokens_hydrate', $callback, 10, 3 );
Description
Filters GitHub conditional tokens for the "Event occurs in repo" trigger before they are hydrated. Developers can add or modify tokens based on the specific GitHub event type, like `pull_request`, using the provided webhook payload and event string. This allows for dynamic token availability.
Usage
add_filter( 'automator_github_pro_event_repo_conditional_tokens_hydrate', 'your_function_name', 10, 3 );
Parameters
-
$tokens(array) - The currently hydrated tokens
-
$payload(array) - The GitHub webhook payload
-
$event(string) - The event type
Return Value
array The enhanced hydrated tokens array
Examples
// Add a token for the commit SHA when the event is a 'push'
add_filter( 'automator_github_pro_event_repo_conditional_tokens_hydrate', function( $tokens, $payload, $event ) {
if ( 'push' === $event ) {
$tokens['GITHUB_COMMIT_SHA'] = $payload['after'] ?? '';
}
return $tokens;
}, 10, 3 );
Placement
This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.
Source Code
uncanny-automator-pro/src/integrations/github/triggers/event-occurs-in-repo.php:219
public function hydrate_tokens( $completed_trigger, $hook_args ) {
$payload = $hook_args[0]; // GitHub payload
$event = $hook_args[1]; // Event type
// Set the webhooks reference for the token helper.
GitHub_Pro_Tokens::set_webhooks( $this->webhooks );
// Get action value - for push events, use the event type as action.
$action = $payload['action'] ?? $event;
// Hydrate tokens default values.
$tokens = array_merge(
GitHub_Pro_Tokens::hydrate_repository_tokens( $payload ),
GitHub_Pro_Tokens::hydrate_sender_tokens( $payload ),
array(
'GITHUB_EVENT_TYPE' => $event, // review - get readable name of event type.
'GITHUB_ACTION' => $action,
'GITHUB_PAYLOAD' => wp_json_encode( $payload ),
),
);
// Add conditional tokens.
if ( self::is_pull_request_event( $event ) ) {
$tokens = array_merge( $tokens, GitHub_Pro_Tokens::hydrate_pull_request_tokens( $payload ) );
}
/**
* Filter GitHub conditional token hydration based on the event type selection.
*
* @param array $tokens The currently hydrated tokens
* @param array $payload The GitHub webhook payload
* @param string $event The event type
*
* @return array The enhanced hydrated tokens array
*
* @example:
* add_filter( 'automator_github_pro_event_repo_conditional_tokens_hydrate', function( $tokens, $payload, $event ) {
* if ( 'pull_request' === $event ) {
* $tokens['GITHUB_PULL_REQUEST_ID'] = $payload['pull_request']['id'] ?? '';
* }
* return $tokens;
* }, 10, 3 );
*/
$tokens = apply_filters( 'automator_github_pro_event_repo_conditional_tokens_hydrate', $tokens, $payload, $event );
return $tokens;
}
Internal Usage
Found in uncanny-automator-pro/src/integrations/github/triggers/event-occurs-in-repo.php:212:
* add_filter( 'automator_github_pro_event_repo_conditional_tokens_hydrate', function( $tokens, $payload, $event ) {