Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get Github contributions to public wordpress repos #32

Open
emilse-webdev opened this issue Jun 23, 2022 · 3 comments
Open

Get Github contributions to public wordpress repos #32

emilse-webdev opened this issue Jun 23, 2022 · 3 comments

Comments

@emilse-webdev
Copy link

I'm trying to add the feature of getting contributions info from github.

@tw2113
Copy link
Owner

tw2113 commented Jun 23, 2022

Chances are we are going to need to find a way to determine how to isolate what constitutes a marked or acknowledged contribution via GitHub and how different, if at all, it'd be as compared to trac.

@emilse-webdev
Copy link
Author

emilse-webdev commented Jun 23, 2022

I did that research already, my code (still incomplete everywhere, I need to check that those are wordpress contributions thought)
`

class WDS_WP_Contributions_Github {

	function __construct() {

		global $wp_contributions;
		$wp_contributions->is_query = true;
		$wp_contributions->query->type = 'github';

	}

	/**
	 * Github public contributions for a user
	 *
	 * @param string       $action Action the API should perform for it's query.
	 * @param array $args   Optional. Arguments to serialize for the Plugin Info API.
	 * @return array|object $res response object on success, WP_Error on failure.
	 *
	 * https://docs.github.com/en/rest/activity/events#list-public-events-for-a-user
	 *
	 */
	public function github_api( $username = null ) {

		if ( $username ) {
			$url = 'https://api.github.com/users/' . $username . '/events/public';
			if ( ! wp_http_supports( array( 'ssl' ) ) ) {
				$url = str_replace( 'https://%', 'http://', $url );
			}

			$request = wp_remote_get( $url );

			if ( is_wp_error( $request ) ) {
				$res = new WP_Error( 'github_api_failed', __( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="https://wordpress.org/support/">support forums</a>.' ), $request->get_error_message() );
			} else {
				$res = maybe_unserialize( wp_remote_retrieve_body( $request ) );
				if ( ! is_object( $res ) && ! is_array( $res ) ) {
					$res = new WP_Error( 'github_api_failed', __( 'An unexpected error occurred. );
				}
			}

			return $res;
		}
	}

	/**
	 * Output the HTML for displaying a card.
	 *
	 * @param object $data The data returned from the Github API.
	 */

}
`

@emilse-webdev
Copy link
Author

I'm missing an API for tract yet, though I'd like to include it too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants