WordPress.org

Making WordPress.org

Changeset 3026


Ignore:
Timestamp:
04/27/2016 06:01:49 PM (3 years ago)
Author:
obenland
Message:

Plugin Directory: Import plugin files to SVN upon approval.

We need to create an SVN repo anyway, adding the approved files also gives us
a nice baseline to compare commits to. And it saves plugin authors one more
step in the process of initially publishing the plugin.

See #1570.

Location:
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin/class-status-transitions.php

    r2996 r3026  
    8383
    8484        // Create SVN repo.
    85         $svn_dirs = array(
    86             "{$post->post_name}/",
    87             "{$post->post_name}/trunk",
    88             "{$post->post_name}/branches",
    89             "{$post->post_name}/tags",
    90             "{$post->post_name}/assets",
    91         );
    92         SVN::mkdir( $svn_dirs, array(
    93             'message' => sprintf( 'Adding %1$s by %2$s.', $post->post_title, $plugin_author->user_login ),
     85        $dir = Filesystem::temp_directory( $post->post_name );
     86        $dir = Filesystem::unzip( get_attached_file( $attachment->ID ), $dir );
     87        foreach ( array( 'assets', 'branches', 'tags', 'trunk' ) as $folder ) {
     88            mkdir( "$dir/$folder", 0777 );
     89        }
     90
     91        $plugin_root = $this->get_plugin_root( $dir );
     92        // If there is no plugin file we have nothing to commit. Bail.
     93        if ( empty( $plugin_root ) ) {
     94            return;
     95        }
     96        rename( $plugin_root, "$dir/trunk" );
     97
     98        SVN::import( $dir, 'http://plugins.svn.wordpress.org/' . $post->post_name, array(
     99            'm'        => sprintf( 'Adding %1$s by %2$s.', $post->post_title, $plugin_author->user_login ),
     100            'username' => AUTOMATTIC_SVN_TRACKER__SVN_USER,
     101            'password' => AUTOMATTIC_SVN_TRACKER__SVN_PASSWORD,
    94102        ) );
    95 
    96         // Read zip and add/commit files to svn.
    97         SVN::add( Filesystem::unzip( get_attached_file( $attachment->ID ) ) );
    98103
    99104        // Delete zip.
     
    148153        wp_mail( $email, $subject, $content, 'From: plugins@wordpress.org' );
    149154    }
     155
     156    /**
     157     * Returns the path to a plugins root directory.
     158     *
     159     * @param string $dir Directory to search in.
     160     * @return string
     161     */
     162    private function get_plugin_root( $dir ) {
     163        $plugin_root  = '';
     164        $plugin_files = Filesystem::list_files( $dir, true /* Recursive */, '!\.php$!i' );
     165
     166        foreach ( $plugin_files as $plugin_file ) {
     167
     168            // No markup/translation needed.
     169            $plugin_data = get_plugin_data( $plugin_file, false, false );
     170
     171            if ( ! empty( $plugin_data['Name'] ) ) {
     172                $plugin_root = dirname( $plugin_file );
     173                break;
     174            }
     175        }
     176
     177        return $plugin_root;
     178    }
    150179}
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/tools/class-svn.php

    r2999 r3026  
    99class SVN {
    1010
    11     public static function add( $dirs, $args = array() ) {
    12         return true;
     11    /**
     12     * Create an SVN Export of a local directory to a URL.
     13     *
     14     * Note: An exception will be thrown upon SVN error.
     15     *
     16     * @param string $path    The local folder to import into SVN.
     17     * @param string $url     The URL to import to.
     18     * @param array  $options A list of options to pass to SVN. Optional.
     19     *
     20     * @return array {
     21     *   @type bool $result   The result of the operation.
     22     *   @type int  $revision The revision imported.
     23     * }
     24     */
     25    public static function import( $path, $url, $options = array() ) {
     26        $esc_options = self::parse_esc_parameters( $options );
     27
     28        $esc_path = escapeshellarg( $path );
     29        $esc_url  = escapeshellarg( $url );
     30
     31        $output = shell_exec( "svn import $esc_options $esc_path $esc_url 2>&1" );
     32        if ( preg_match( '/Committed revision (?P<revision>\d+)[.]/i', $output, $m ) ) {
     33            $revision = (int) $m['revision'];
     34            $result   = true;
     35        } else {
     36            $result = false;
     37            $errors = self::parse_svn_errors( $output );
     38        }
     39
     40        return compact( 'result', 'revision', 'errors' );
    1341    }
    1442
     
    4068            $result = false;
    4169            $errors = self::parse_svn_errors( $output );
    42            
    4370        }
    4471
     
    84111    }
    85112
    86     public static function mkdir( $dirs, $args = array() ) {
    87         return true;
    88     }
    89 
    90113    /**
    91114     * Parse and escape the provided SVN arguements for usage on the CLI.
     
    109132                $key = '-' . ( strlen( $key ) > 2 ? '-' : '' ) . $key;
    110133            }
    111            
     134
    112135            $result[] = escapeshellarg( $key ) . ( $no_parameters ? '' : '=' . escapeshellarg( $value ) );
    113136        }
Note: See TracChangeset for help on using the changeset viewer.