Making WordPress.org

Changeset 11665


Ignore:
Timestamp:
03/11/2022 06:52:36 AM (4 years ago)
Author:
dd32
Message:

Trac: PRs: Gracefully handle API failures better.

Avoids Notices when the api_request() function fails.

File:
1 edited

Legend:

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

    r11544 r11665  
    2121        [ 'Accept: application/vnd.github.antiope-preview+json' ]
    2222    );
    23     if ( !empty( $raw_check_runs->check_runs ) ) {
     23    if ( ! empty( $raw_check_runs->check_runs ) ) {
    2424        foreach ( $raw_check_runs->check_runs as $check ) {
    2525            switch ( $check->status ) {
     
    5050    );
    5151    $reviews = [];
    52     foreach ( $_reviews as $r ) {
    53         if (
    54             in_array( $r->state, [ 'CHANGES_REQUESTED', 'APPROVED' ] ) &&
    55             ! in_array( $r->user->login, $reviews[ $r->state ] ?? [], true )
    56         ) {
    57             $reviews[ $r->state ][] = $r->user->login;
     52    if ( $_reviews ) {
     53        foreach ( $_reviews as $r ) {
     54            if (
     55                in_array( $r->state, [ 'CHANGES_REQUESTED', 'APPROVED' ] ) &&
     56                ! in_array( $r->user->login, $reviews[ $r->state ] ?? [], true )
     57            ) {
     58                $reviews[ $r->state ][] = $r->user->login;
     59            }
    5860        }
    5961    }
     
    6567        [ 'Accept: application/vnd.github.antiope-preview+json' ]
    6668    );
    67     foreach ( $_files as $f ) {
    68         if ( preg_match( '!(^tests/|/tests/)!', $f->filename ) ) {
    69             $touches_tests = true;
    70             break;
     69    if ( $_files ) {
     70        foreach ( $_files as $f ) {
     71            if ( preg_match( '!(^tests/|/tests/)!', $f->filename ) ) {
     72                $touches_tests = true;
     73                break;
     74            }
    7175        }
    7276    }
Note: See TracChangeset for help on using the changeset viewer.