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

Use new GitHub Teams API #205

Merged
merged 13 commits into from
Feb 9, 2022
Merged
Prev Previous commit
Next Next commit
Update vipgoci_option_teams_handle() to handle team slugs.
  • Loading branch information
gudmdharalds committed Aug 27, 2021
commit c699f61fcc2cfec077e77df4cb9231d54233610c
65 changes: 23 additions & 42 deletions options.php
Original file line number Diff line number Diff line change
Expand Up @@ -988,17 +988,15 @@ function vipgoci_option_url_handle(
}

/*
* Handle parameter that we expect to contain teams,
* either as an ID (numeric) or a string (slug).
* Handle parameter that we expect to contain team slugs.
*
* Will check if the teams are valid, removing invalid ones,
* transforming strings into IDs, and reconstruct the option
* afterwards.
* Will check if the teams are valid, removing invalid ones
* and reconstructing the option afterwards.
*/

function vipgoci_option_teams_handle(
&$options,
$option_name
array &$options,
string $option_name
) {
if (
( ! isset( $options[ $option_name ] ) ) ||
Expand Down Expand Up @@ -1026,55 +1024,38 @@ function vipgoci_option_teams_handle(

foreach(
$options[ $option_name ] as
$team_id_key => $team_id_value
$team_slug_key => $team_slug_value
) {
$team_id_value_original = $team_id_value;

/*
* If a string, transform team_id_value into integer ID
* for team.
*/
if (
( ! is_numeric( $team_id_value ) ) &&
( ! empty( $teams_info[ $team_id_value ] ) )
) {
$team_id_value = $teams_info[ $team_id_value ][0]->id;
}
$team_slug_value_original = $team_slug_value;

/*
* If $team_id_value is a numeric,
* the team exists, so put in
* the integer-value in the options.
* If the team slug provided by user is valid,
* it should be in list of slugs returned by API.
gudmdharalds marked this conversation as resolved.
Show resolved Hide resolved
* Ensure this is the case.
*/
if ( is_numeric( $team_id_value ) ) {
$options
[ $option_name ]
[ $team_id_key ] = (int) $team_id_value;
if ( ! empty( $teams_info[ $team_slug_value ] ) ) {
gudmdharalds marked this conversation as resolved.
Show resolved Hide resolved
gudmdharalds marked this conversation as resolved.
Show resolved Hide resolved
$team_slug_value = $teams_info[ $team_slug_value ][0]->slug;
}

/*
* Something failed; we might have
* failed to transform $team_id_value into
* a numeric representation (ID) and/or
* it may have been invalid, so remove
* it from the options array.
*/

else {
/*
* Something failed; slug may have been invalid so
* remove it from the options array.
*/
vipgoci_log(
'Invalid team ID found in ' .
'Invalid team slug found in ' .
'--' . $option_name .
' parameter; ignoring it.',
array(
'team_id' => $team_id_value,
'team_id_original' => $team_id_value_original,
'team_slug' => $team_slug_value,
'team_slug_original' => $team_slug_value_original,
)
);

unset(
$options
[ $option_name ]
[ $team_id_key ]
[ $team_slug_key ]
);
}
}
Expand All @@ -1086,9 +1067,9 @@ function vipgoci_option_teams_handle(
) );

unset( $teams_info );
unset( $team_id_key );
unset( $team_id_value );
unset( $team_id_value_original );
unset( $team_slug_key );
unset( $team_slug_value );
unset( $team_slug_value_original );
}


Expand Down