WordPress.org

Making WordPress.org

Changeset 9365


Ignore:
Timestamp:
12/19/2019 08:21:26 AM (2 years ago)
Author:
dd32
Message:

Trac: Github PRs: Properly craft the Github API request when a POST request is used, and ensure that we set the headers correctly.

See #4903.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/api.wordpress.org/public_html/dotorg/trac/pr/functions.php

    r9340 r9365  
    3939
    4040/**
     41 * Find a WordPress.org user by a Github login.
     42 */
     43function find_wporg_user_by_github( $github_user ) {
     44    global $wpdb;
     45
     46    return $wpdb->get_var( $wpdb->prepare(
     47        "SELECT u.user_login
     48            FROM {$wpdb->base_prefix}github_users g
     49                JOIN {$wpdb->users} u ON g.user_id = u.ID
     50            WHERE g.github_user = %s",
     51        $github_user
     52    ) );
     53}
     54
     55/**
    4156 * A simple wrapper to make a Github API request..
    4257 */
     
    4762    }
    4863
    49     $context = stream_context_create( $c = [ 'http' => [
     64    $context = stream_context_create( [ 'http' => [
    5065        'method'        => $method ?: ( is_null( $args ) ? 'GET' : 'POST' ),
    5166        'user_agent'    => 'WordPress.org Trac; trac.WordPress.org',
     
    5368        'timeout'       => 5,
    5469        'ignore_errors' => true,
    55         'headers'       => array_merge(
     70        'header'        => array_merge(
    5671            [
    57                 'Accept'        => 'application/json',
    58                 'Authorization' => get_authorization_token(),
     72                'Accept: application/json',
     73                'Authorization: ' . get_authorization_token(),
    5974            ],
    6075            $headers
    6176        ),
    62         'body'          => $args ?: null,
     77        'content'       => $args ?: null,
    6378    ] ] );
    6479
     
    7590function get_authorization_token() {
    7691    global $wpdb;
    77    
     92
    7893    // TODO: This needs to be switched to a Github App token.
    7994    // This works temporarily to avoid the low unauthenticated limits.
Note: See TracChangeset for help on using the changeset viewer.