Filter uncanny-automator-pro

automator_github_pro_event_repo_conditional_tokens

Filter GitHub conditional tokens based on the event type selection. Filters GitHub conditional tokens available for a specific GitHub event type.

add_filter( 'automator_github_pro_event_repo_conditional_tokens', $callback, 10, 2 );

Description

Filters GitHub conditional tokens for repository events before they are returned. Developers can modify the `$tokens` array to add, remove, or alter tokens available for conditional logic based on the specific `$event` type, enabling fine-grained control over automations.


Usage

add_filter( 'automator_github_pro_event_repo_conditional_tokens', 'your_function_name', 10, 2 );

Parameters

$tokens (array)
The currently registered tokens @property tokenId - The token ID @property tokenName - The token name @property tokenType - The token type @property tokenIdentifier - EVENT_OCCURS_IN_REPO
$event (string)
The event type

Return Value

array The enhanced tokens array


Examples

// Add a token for the commit message for 'push' events.
add_filter( 'automator_github_pro_event_repo_conditional_tokens', function( $registered_tokens, $event ) {
    if ( 'push' === $event ) {
        $registered_tokens[] = array(
            'tokenId'   => 'GITHUB_COMMIT_MESSAGE',
            'tokenName' => esc_html_x( 'Commit Message', 'GitHub', 'uncanny-automator-pro' ),
            'tokenType' => 'text',
            'tokenIdentifier' => 'EVENT_OCCURS_IN_REPO', // This seems to be a required identifier from the hook description
        );
    }
    return $registered_tokens;
}, 10, 2 );

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:311

public static function maybe_add_conditional_tokens( $tokens = array(), $args = array() ) {

		// Determine the selected event type.
		$trigger_meta = $args['triggers_meta'] ?? array();
		$event        = $trigger_meta[ self::EVENT_TYPE_META ] ?? '';

		if ( empty( $event ) ) {
			return $tokens;
		}

		// Add pull request tokens if the event is a pull request event.
		if ( self::is_pull_request_event( $event ) ) {
			// Get PR tokens and add class identifier.
			$pr_tokens = GitHub_Pro_Tokens::get_pull_request_token_definitions();
			$pr_tokens = GitHub_Pro_Tokens::add_class_identifier( $pr_tokens, 'EVENT_OCCURS_IN_REPO' );
			$tokens    = array_merge( $tokens, $pr_tokens );
		}

		// TODO : Add other conditional tokens based on the event type selection.

		/**
		 * Filter GitHub conditional tokens based on the event type selection.
		 *
		 * @param array $tokens The currently registered tokens
		 * @property tokenId - The token ID
		 * @property tokenName - The token name
		 * @property tokenType - The token type
		 * @property tokenIdentifier - EVENT_OCCURS_IN_REPO
		 * @param string $event The event type
		 *
		 * @return array The enhanced tokens array
		 *
		 * @example:
		 * add_filter( 'automator_github_pro_event_repo_conditional_tokens', function( $registered_tokens, $event ) {
		 *     if ( 'pull_request' === $event ) {
		 *         $registered_tokens[] = array(
		 *             'tokenId'   => 'GITHUB_PULL_REQUEST_ID',
		 *             'tokenName' => esc_html_x( 'Pull request ID', 'GitHub', 'uncanny-automator-pro' ),
		 *             'tokenType' => 'text',
		 *         );
		 *     }
		 *     return $registered_tokens;
		 * }, 10, 2 );
		 */
		$tokens = apply_filters( 'automator_github_pro_event_repo_conditional_tokens', $tokens, $event );

		return $tokens;
	}

Internal Usage

Found in uncanny-automator-pro/src/integrations/github/triggers/event-occurs-in-repo.php:300:

* add_filter( 'automator_github_pro_event_repo_conditional_tokens', function( $registered_tokens, $event ) {
Scroll to Top