automator_github_sender_email
Filter to allow custom email extraction logic This filter allows advanced users to implement their own email extraction strategies, such as API calls, database lookups, or custom mapping logic. Filters the extracted email from a GitHub webhook payload, allowing custom logic for finding the sender's email.
add_filter( 'automator_github_sender_email', $callback, 10, 2 );
Description
Fires when Uncanny Automator processes a GitHub webhook to find the sender's email. Developers can use this filter to override default email extraction, allowing custom logic like API calls or database lookups to determine the sender's email from the webhook payload. Returns the found email, or an empty string if none is identified.
Usage
add_filter( 'automator_github_sender_email', 'your_function_name', 10, 2 );
Parameters
-
$email(string) - The email address found (empty if none found)
-
$payload(array) - The full GitHub webhook payload
Return Value
string The email address to use.
Examples
<?php
/**
* Filter the sender's email address from a GitHub webhook payload.
*
* This example prioritizes finding an email address from the 'sender.email' field
* in the payload. If that's not available, it checks the 'sender.login' as a
* fallback, attempting to construct a common email format.
*
* @param string $email The current email address (initially empty).
* @param array $payload The full GitHub webhook payload.
*
* @return string The determined sender email address.
*/
add_filter( 'automator_github_sender_email', 'my_automator_custom_github_email', 10, 2 );
function my_automator_custom_github_email( $email, $payload ) {
// If an email is already set, we can assume a previous filter or default logic handled it.
if ( ! empty( $email ) ) {
return $email;
}
// Prioritize the 'sender.email' field if it exists.
if ( isset( $payload['sender']['email'] ) && ! empty( $payload['sender']['email'] ) ) {
return $payload['sender']['email'];
}
// Fallback: try to construct an email from 'sender.login'.
// This is a common convention, but might not always be accurate.
if ( isset( $payload['sender']['login'] ) && ! empty( $payload['sender']['login'] ) ) {
// Assuming a common domain, e.g., @github.com, for fallback.
// In a real-world scenario, you might have a more robust way to handle this.
return strtolower( $payload['sender']['login'] ) . '@github.com';
}
// If no email can be determined, return an empty string.
return '';
}
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/tokens/github-tokens.php:153
private static function get_sender_email( $payload ) {
// Define email paths to check in order of preference
$email_paths = array(
'sender.email', // Most common for some events
'pusher.email', // Push events
'comment.user.email', // Comment events
'issue.user.email', // Issue events
'pull_request.user.email', // PR events
'release.author.email', // Release events
'forkee.owner.email', // Fork events
'deployment.creator.email', // Deployment events
'workflow_run.actor.email', // Workflow run events
);
foreach ( $email_paths as $path ) {
$email = self::get_value( $payload, $path );
if ( ! empty( $email ) ) {
return $email;
}
}
/**
* Filter to allow custom email extraction logic
*
* This filter allows advanced users to implement their own email
* extraction strategies, such as API calls, database lookups, or
* custom mapping logic.
*
* @param string $email The email address found (empty if none found)
* @param array $payload The full GitHub webhook payload
*
* @return string The email address to use.
*/
$email = apply_filters( 'automator_github_sender_email', '', $payload );
// If no email found, return empty string
return $email;
}