Add provider factory with meta + option wiring

This commit is contained in:
Keith Solomon
2026-08-09 23:02:20 -05:00
parent 62a20ed514
commit e3b27e8974
2 changed files with 102 additions and 0 deletions
@@ -0,0 +1,36 @@
<?php
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
/**
* Provider factory: selects the right adapter for a project post.
*
* @since 1.1.0
*
* @param int $post_id
* @return Repository_Provider
*/
function projects_portfolio_get_provider( int $post_id ): Repository_Provider {
$provider_meta = (string) get_post_meta( $post_id, '_projects_portfolio_provider', true );
$provider_id = '' !== $provider_meta ? $provider_meta : 'github';
$repo_url = (string) get_post_meta( $post_id, '_projects_portfolio_repo_url', true );
if ( '' === $repo_url ) {
// Lazy fallback to legacy key.
$repo_url = (string) get_post_meta( $post_id, '_projects_portfolio_github_url', true );
}
if ( 'gitea' === $provider_id ) {
$base_url = (string) get_post_meta( $post_id, '_projects_portfolio_gitea_base_url', true );
if ( '' === $base_url ) {
$base_url = (string) get_option( 'projects_portfolio_default_gitea_base_url', 'https://codeberg.org' );
}
$token = (string) get_option( 'projects_portfolio_gitea_api_token', '' );
return new Gitea_Provider( $repo_url, $base_url, $token );
}
$token = (string) get_option( 'projects_portfolio_github_api_token', '' );
return new GitHub_Provider( $repo_url, $token );
}