<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[12671] sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-github-invite: Make: Allow Make teams to invite new GitHub members to the WordPress organisation in certain teams.</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { white-space: pre-line; overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="http://meta.trac.wordpress.org/changeset/12671">12671</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"http://meta.trac.wordpress.org/changeset/12671","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>dd32</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2023-06-21 05:21:18 +0000 (Wed, 21 Jun 2023)</dd>
</dl>
<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>Make: Allow Make teams to invite new GitHub members to the WordPress organisation in certain teams.
See <a href="http://meta.trac.wordpress.org/ticket/7802">#7802</a>.</pre>
<h3>Added Paths</h3>
<ul>
<li>sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-github-invite/</li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginswporggithubinviteadminpostphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-github-invite/admin-post.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginswporggithubinviteadminphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-github-invite/admin.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginswporggithubinviteapiphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-github-invite/api.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginswporggithubinvitewporggithubinvitephp">sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-github-invite/wporg-github-invite.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginswporggithubinviteadminpostphp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-github-invite/admin-post.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-github-invite/admin-post.php (rev 0)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-github-invite/admin-post.php 2023-06-21 05:21:18 UTC (rev 12671)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,142 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+namespace WordPressdotorg\GitHub\MakeInviter;
+use WordPressdotorg\MU_Plugins\Utilities\Github_App_Authorization;
+use WP_Error;
+
+/**
+ * Process the invitation.
+ */
+add_action( 'admin_post_github_invite', function() {
+ global $wpdb;
+
+ if ( ! current_user_can( PERMISSION ) ) {
+ wp_die( 'You do not have permission to do this' );
+ }
+
+ check_admin_referer( 'github_invite' );
+
+ $input = wp_unslash( $_POST['invite'] );
+ $team_ids = (array) wp_unslash( $_POST['team_id'] );
+ $team_ids = array_intersect( $team_ids, get_allowed_teams() );
+ $team_ids = array_map( 'intval', $team_ids );
+
+ $updated = 'success';
+ $message = null;
+ $invite = false;
+
+ if ( ! $team_ids ) {
+ $updated = 'error';
+ $message = 'No teams selected';
+ } elseif (
+ preg_match( '!^https://profiles.wordpress.org/(?<slug>[^/]+)!i', $input, $m ) ||
+ ! is_email( $input )
+ ) {
+ $user = get_user_by( 'slug', $m['slug'] ?? $input );
+ $github_details = json_decode( $wpdb->get_var( $wpdb->prepare(
+ 'SELECT user_details FROM wporg_github_users WHERE user_id = %d',
+ $user->ID
+ ) ) );
+
+ if ( ! $user || ! $github_details ) {
+ $updated = 'no-github';
+ } else {
+ $invite = $github_details->id;
+ }
+ } elseif ( is_email( $input ) ) {
+ $invite = $input;
+ } else {
+ $updated = 'error';
+ }
+
+ if ( $invite ) {
+ $result = invite_member( $invite, $team_ids );
+
+ if ( $result->id ) {
+ // Note that it was invited via this site..
+ $invited_gh_users = get_option( 'invited_gh_users', [] );
+ $invited_gh_users[] = $result->id;
+ update_option( 'invited_gh_users', $invited_gh_users );
+
+ delete_site_transient( 'gh_invites' );
+
+ // Log it to Slack.
+ $teams = get_teams();
+ $readable_teams = array_map( static function( $id ) use( $teams ) {
+ return array_values( wp_list_filter( $teams, [ 'id' => $id ] ) )[0]->name ?? $id;
+ }, $team_ids );
+
+ $log = sprintf(
+ '`%s` invited to organisation by `%s` to team(s) `%s`',
+ $result->login ?: $result->email,
+ wp_get_current_user()->user_login,
+ implode( ', ', $readable_teams )
+ );
+
+ function_exists( 'slack_dm' ) && slack_dm( $log, SLACK_CHANNEL );
+ }
+
+ if ( isset( $result->errors ) ) {
+ $updated = 'error';
+ $message = $result->errors[0]->message ?? '';
+ } elseif ( $result->login ?: $result->email ) {
+ $message = sprintf( 'Invited User: %s', $result->login ?: $result->email );
+ }
+ }
+
+ wp_safe_redirect(
+ add_query_arg(
+ compact( 'updated', 'message' ),
+ admin_url( 'tools.php?page=gh_invite_collaborator' )
+ )
+ );
+ die();
+} );
+
+/**
+ * Cancel an invitation.
+ */
+add_action( 'admin_post_github_cancel_invite', function() {
+ if ( ! current_user_can( PERMISSION ) ) {
+ wp_die( 'You do not have permission to do this' );
+ }
+
+ $id = (int) wp_unslash( $_GET['invite'] );
+
+ check_admin_referer( 'github_cancel_invite_' . $id );
+
+ $invite = array_values( wp_list_filter( get_pending_invites(), [ 'id' => $id ] ) )[0] ?? null;
+
+ cancel_invite( $id );
+
+ // Log it to Slack.
+ $log = sprintf(
+ '`%s` invite canceled by `%s`.',
+ $invite->login ?: $invite->email,
+ wp_get_current_user()->user_login
+ );
+ function_exists( 'slack_dm' ) && slack_dm( $log, SLACK_CHANNEL );
+
+ delete_site_transient( 'gh_invites' );
+
+ wp_safe_redirect( admin_url( 'tools.php?page=gh_invite_collaborator&updated=canceled' ) );
+ die();
+} );
+
+/**
+ * Allow a super-admin to specify which teams a user may be invited to from this site.
+ */
+add_action( 'admin_post_github_invite_settings', function() {
+ if ( ! is_super_admin() || ! current_user_can( PERMISSION ) ) {
+ wp_die( 'You do not have permission to do this' );
+ }
+
+ check_admin_referer( 'github_invite_settings' );
+
+ $team_ids = wp_unslash( $_POST['team_id'] );
+ $team_ids = array_map( 'intval', $team_ids );
+
+ update_option( 'gh_invite_allowed_teams', $team_ids );
+
+ wp_safe_redirect( admin_url( 'tools.php?page=gh_invite_collaborator&updated=settings' ) );
+ die();
+} );
</ins><span class="cx" style="display: block; padding: 0 10px">Property changes on: sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-github-invite/admin-post.php
</span><span class="cx" style="display: block; padding: 0 10px">___________________________________________________________________
</span></span></pre></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: svn:eol-style</h4></div>
<ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+native
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of property
</span><a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginswporggithubinviteadminphp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-github-invite/admin.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-github-invite/admin.php (rev 0)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-github-invite/admin.php 2023-06-21 05:21:18 UTC (rev 12671)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,201 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+namespace WordPressdotorg\GitHub\MakeInviter;
+
+function render() {
+ $allowed_teams = get_allowed_teams();
+ $all_teams = get_teams();
+ $teams = [];
+
+ foreach ( $allowed_teams as $id ) {
+ $team = wp_list_filter( $all_teams, [ 'id' => $id ] );
+ if ( ! $team ) {
+ continue;
+ }
+ $team = array_shift( $team );
+
+ // Add the parent..
+ if ( isset( $team->parent ) ) {
+ $teams[ $team->parent->id ] = $team->parent;
+ }
+
+ $teams[ $team->id ] = $team;
+ }
+
+ // Add any sub-teams that are not allowed to be selected..
+ foreach ( $teams as $team ) {
+ foreach ( $all_teams as $t ) {
+ if ( $t->parent && $t->parent->id === $team->id && ! in_array( $t->id, $allowed_teams, true ) ) {
+ $teams[ $t->id ] = clone $t;
+ }
+ }
+ }
+
+ // Mark any as disabled as needed.
+ foreach ( $teams as $team ) {
+ $team->disabled = ! in_array( $team->id, $allowed_teams, true );
+ }
+
+ if ( isset( $_GET['updated'] ) ) {
+ $class = 'success';
+ $message = '';
+ switch ( $_GET['updated'] ) {
+ case 'success':
+ $message = 'Success, invitation sent!';
+ break;
+ case 'canceled':
+ $message = 'Invitation canceled';
+ break;
+ case 'error':
+ $class = 'error';
+ $message = 'An error occurred inviting this collaborator!';
+ break;
+ case 'settings':
+ $message = 'Settings updated';
+ break;
+ case 'no-github':
+ $class = 'error';
+ $message = 'The specified WordPress.org account does not have a linked GitHub account.';
+ break;
+ }
+
+ if ( $message && isset( $_GET['message'] ) ) {
+ $message .= '<br><em>' . esc_html( $_GET['message'] ) . '</em>';
+ }
+
+ if ( $message ) {
+ printf(
+ '<div class="notice notice-%s is-dismissable"><p>%s</p></div>',
+ $class,
+ $message
+ );
+ }
+ }
+
+ ?>
+ <div class="wrap" id="wp_learn_admin">
+ <h1>Invite GitHub Member</h1>
+ <form method="post" action="<?php echo admin_url( 'admin-post.php' ) ?>">
+ <input type="hidden" name="action" value="github_invite">
+ <?php wp_nonce_field( 'github_invite' ); ?>
+ <table class="form-table">
+ <tr>
+ <th scope="row"><label for="invite">GitHub Email, WordPress.org user slug, or WordPress.org Profile URL</label></th>
+ <td><input type="text" name="invite" id="invite" class="regular-text" placeholder="https://profiles.wordpress.org/<?php echo wp_get_current_user()->user_nicename; ?>/"></td>
+ </tr>
+ <tr>
+ <th scope="row"><label for="team">Teams</label></th>
+ <td>
+ <?php
+ if ( ! $teams ) {
+ echo '<em>No teams have been configured. Please ask a super-admin via #meta to enable at least one team.</em>';
+ }
+
+ render_team_list( $teams );
+ ?>
+ </td>
+ </tr>
+ </table>
+ <?php submit_button( 'Invite Collaborator' ); ?>
+ </form>
+
+ <h1>Pending Invites</h1>
+ <form>
+ <table class="form-table">
+ <tr>
+ <th scope="row">Pending Invitations</th>
+ <td>
+ <?php
+ $pending_invites = get_pending_invites();
+ if ( ! $pending_invites ) {
+ echo '<em>No pending invitations</em>';
+ }
+
+ foreach ( $pending_invites as $pending ) {
+ $can_cancel = in_array( $pending->id, get_option( 'invited_gh_users', [] ), true ) || is_super_admin();
+ $cancel_url = $can_cancel ? wp_nonce_url( admin_url( 'admin-post.php?action=github_cancel_invite&invite=' . $pending->id ), 'github_cancel_invite_' . $pending->id ) : false;
+ printf(
+ '<p>
+ <strong><code>%s</code></strong>
+ <em>%s ago</em>
+ %s
+ </p>',
+ $pending->login ?: $pending->email,
+ human_time_diff( strtotime( $pending->created_at ) ),
+ $cancel_url ? '<a class="button" href="' . esc_url( $cancel_url ) . '">Cancel</a>' : ''
+ );
+ }
+ ?>
+ </td>
+ </tr>
+ </table>
+ </form>
+ <?php
+
+ // Allow super-admins to set the teams the site users can invite for.
+ if ( is_super_admin() ) {
+ ?>
+ <hr>
+ <h1>Settings</h1>
+ <form method="post" action="<?php echo admin_url( 'admin-post.php' ) ?>">
+ <input type="hidden" name="action" value="github_invite_settings">
+ <?php wp_nonce_field( 'github_invite_settings' ); ?>
+ <table class="form-table">
+ <tr>
+ <th scope="row"><label for="team">Allowed Team(s) for this site <span style="color: red">(super-admin only)</span></label></th>
+ <td>
+ <?php render_team_list( $all_teams, $allowed_teams ); ?>
+ </td>
+ </tr>
+ </table>
+ <?php submit_button( 'Save Settings' ); ?>
+ </form>
+ <?php
+ }
+}
+
+/**
+ * Render the team list.
+ */
+function render_team_list( $teams, $checked = array(), $for_parent = 0 ) {
+ if ( $for_parent ) {
+ $teams = array_filter( $teams, function( $t ) use ( $for_parent ) {
+ return $for_parent === $t->parent->id ?? 0;
+ } );
+
+ if ( ! $teams ) {
+ return false;
+ }
+
+ echo '<div class="childen" style="margin-left: 1em">';
+ }
+
+ foreach ( $teams as $team ) {
+ if ( isset( $team->parent ) && ! $for_parent ) {
+ continue;
+ }
+
+ ?>
+ <div>
+ <label>
+ <input
+ type="checkbox"
+ name="team_id[]"
+ value="<?php echo esc_attr( $team->id ) ?>"
+ <?php
+ checked( in_array( $team->id, $checked ) );
+ disabled( ! empty( $team->disabled ) || in_array( $team->id, get_never_teams() ) );
+ ?>
+ />
+ <?php echo esc_html( $team->name ) ?>
+ </label>
+ <?php
+ // Any child teams of this team?
+ render_team_list( $teams, $checked, $team->id );
+ ?>
+ </div>
+ <?php }
+
+ if ( $for_parent ) {
+ echo '</div>';
+ }
+}
</ins><span class="cx" style="display: block; padding: 0 10px">Property changes on: sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-github-invite/admin.php
</span><span class="cx" style="display: block; padding: 0 10px">___________________________________________________________________
</span></span></pre></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: svn:eol-style</h4></div>
<ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+native
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of property
</span><a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginswporggithubinviteapiphp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-github-invite/api.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-github-invite/api.php (rev 0)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-github-invite/api.php 2023-06-21 05:21:18 UTC (rev 12671)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,136 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+namespace WordPressdotorg\GitHub\MakeInviter;
+use WordPressdotorg\MU_Plugins\Utilities\Github_App_Authorization;
+use WP_Error;
+
+/**
+ * Get the allowed teams for this site.
+ */
+function get_allowed_teams() {
+ $allowed_teams = array_map( 'intval', get_option( 'gh_invite_allowed_teams', array() ) );
+
+ return array_diff( $allowed_teams, get_never_teams() );
+}
+
+/**
+ * A list of teams that should never be selected.
+ */
+function get_never_teams() {
+ return [
+ 1114244, // Security team.
+ 80104, // Another special team
+ ];
+}
+
+/**
+ * Fetch the teams from the WordPress GitHub organization
+ */
+function get_teams() {
+ $teams = get_site_transient( 'gh_teams', false );
+ if ( false === $teams ) {
+ $teams = api( '/orgs/{ORG}/teams?per_page=100' );
+
+ set_site_transient( 'gh_teams', $teams, 5 * MINUTE_IN_SECONDS );
+ }
+
+ if ( is_wp_error( $teams ) ) {
+ return [];
+ }
+
+ return $teams;
+}
+
+/**
+ * Fetch the pending invites from the WordPress GitHub organization
+ */
+function get_pending_invites() {
+ $invites = get_site_transient( 'gh_invites', false );
+ if ( false === $invites ) {
+ $invites = api( '/orgs/{ORG}/invitations' );
+
+ set_site_transient( 'gh_invites', $invites, 5 * MINUTE_IN_SECONDS );
+ }
+
+ if ( is_wp_error( $invites ) ) {
+ return [];
+ }
+
+ return $invites;
+}
+
+/**
+ * Invite a member to the organisation, with specific Teams.
+ *
+ * @param int|string $who The GitHub user ID, or email of the user to invite.
+ */
+function invite_member( $who, array $team_ids ) {
+ $args = [
+ 'role' => 'direct_member',
+ 'team_ids' => $team_ids
+ ];
+
+ if ( is_int( $who ) ) {
+ $args['invitee_id'] = $who;
+ } else {
+ $args['email'] = $who;
+ }
+
+ return api(
+ '/orgs/{ORG}/invitations',
+ $args
+ );
+}
+
+/**
+ * Cancel an invitation by ID
+ */
+function cancel_invite( $id ) {
+ return api(
+ '/orgs/{ORG}/invitations/' . $id,
+ [],
+ 'DELETE'
+ );
+}
+
+
+/**
+ * Quick GitHub API method.
+ *
+ * @param string $endpoint The API endpoint to call.
+ * @param mixed $body The body to send with the request.
+ */
+function api( $endpoint, $body = false, $method = null ) {
+ static $github_app = null;
+
+ // Setup the App if needed.
+ $github_app ??= new Github_App_Authorization( APP_ID, KEY );
+ $method ??= $body ? 'POST' : 'GET';
+
+ $args = array(
+ 'method' => $method,
+ 'headers' => array(
+ 'Accept' => 'application/vnd.github+json',
+ 'Content-Type' => 'application/json',
+ 'X-GitHub-Api-Version' => '2022-11-28'
+ ),
+ );
+
+ if ( $body ) {
+ $args['body'] = json_encode( $body );
+ }
+
+ $response = $github_app->request( $endpoint, $args );
+
+ if ( is_wp_error( $response ) ) {
+ // Includes the HTTP response code only due to privacy concerns.
+ return new WP_Error( 'http_error', 'GitHub API error: ' . wp_remote_retrieve_response_code( $response ) );
+ }
+
+ $json = json_decode( $response['body'] );
+
+ if ( 200 != wp_remote_retrieve_response_code( $response ) && isset( $json->message ) ) {
+ return new WP_Error( 'api_error', 'GitHub API error: ' . $json->message, $json );
+ }
+
+ return $json;
+}
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of file
</span><span class="cx" style="display: block; padding: 0 10px">Property changes on: sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-github-invite/api.php
</span><span class="cx" style="display: block; padding: 0 10px">___________________________________________________________________
</span></span></pre></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: svn:eol-style</h4></div>
<ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+native
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of property
</span><a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginswporggithubinvitewporggithubinvitephp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-github-invite/wporg-github-invite.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-github-invite/wporg-github-invite.php (rev 0)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-github-invite/wporg-github-invite.php 2023-06-21 05:21:18 UTC (rev 12671)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,41 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+namespace WordPressdotorg\GitHub\MakeInviter;
+
+/**
+ * Plugin Name: GitHub Invite Member
+ * Description: Invite Members to the WordPress organization.
+ * Requires at least: 6.1
+ * Requires PHP: 7.4
+ * Version: 1.0.0
+ * Author: the WordPress.org Community.
+ * License: GPL-2.0-or-later
+ * License URI: https://www.gnu.org/licenses/gpl-2.0.html
+ *
+ * @package WordPressdotorg\GitHub\MakeInviter
+ *
+ * Hat-tip to Jonathan Bossenger for the original plugin code.
+ */
+
+const APP_ID = \GH_INVITE_APP_ID;
+const KEY = \GH_INVITE_KEY;
+const SLACK_CHANNEL = \GH_INVITE_SLACK_GITHUBADMINS;
+const PERMISSION = 'manage_options'; // Administrators only.
+
+// Add the menu item.
+add_action( 'admin_menu', function() {
+ add_submenu_page(
+ 'tools.php',
+ 'Invite Github Member',
+ 'Invite Github Member',
+ 'manage_options',
+ 'gh_invite_collaborator',
+ __NAMESPACE__ . '\render'
+ );
+} );
+
+// Load the plugin.
+add_action( 'admin_init', function() {
+ require_once __DIR__ . '/api.php';
+ require_once __DIR__ . '/admin.php';
+ require_once __DIR__ . '/admin-post.php';
+} );
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of file
</span><span class="cx" style="display: block; padding: 0 10px">Property changes on: sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-github-invite/wporg-github-invite.php
</span><span class="cx" style="display: block; padding: 0 10px">___________________________________________________________________
</span></span></pre></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: svn:eol-style</h4></div>
<ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+native
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of property
</span></div>
</body>
</html>