From 92633172345fb60bcd452d8f0d5ca9bbe212d196 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 12 Mar 2026 08:23:57 +0000 Subject: [PATCH 1/2] Initial plan From d1da369d7bdc0cd329db63057db014a63d5dec85 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 12 Mar 2026 08:32:03 +0000 Subject: [PATCH 2/2] Fix incorrect version number used when creating zip archive Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- features/dist-archive.feature | 24 ++++++++++ src/Dist_Archive_Command.php | 83 ++--------------------------------- 2 files changed, 28 insertions(+), 79 deletions(-) diff --git a/features/dist-archive.feature b/features/dist-archive.feature index 279829b..9c0981f 100644 --- a/features/dist-archive.feature +++ b/features/dist-archive.feature @@ -266,6 +266,30 @@ Feature: Generate a distribution archive of a project And the wp-content/plugins/hello-world/.circleci/config.yml file should not exist And the wp-content/plugins/hello-world/bin directory should not exist + Scenario: Uses plugin Version header, not PHPdoc @version tag, for archive name + Given an empty directory + And a my-plugin/my-plugin.php file: + """ + get_version_in_code( $contents ); - if ( ! empty( $ver ) ) { - $version = trim( $ver ); + $contents = str_replace( "\r", "\n", $contents ); + $pattern = '/^[ \t\/*#@]*Version:(.*)$/mi'; + if ( preg_match( $pattern, $contents, $match ) && $match[1] ) { + $version = trim( (string) preg_replace( '/\s*(?:\*\/|\?>).*/', '', $match[1] ) ); break; } } @@ -340,82 +341,6 @@ private function maybe_create_directory( $destination_dir_path ) { } } - /** - * Gets the content of a version tag in any doc block in the given source code string. - * - * The version tag might be specified as "@version x.y.z" or "Version: x.y.z" and it can - * be preceded by an asterisk (*). - * - * @param string $code_str The source code string to look into. - * @return null|string The detected version string. - */ - private function get_version_in_code( $code_str ) { - $tokens = array_values( - array_filter( - token_get_all( $code_str ), - function ( $token ) { - return ! is_array( $token ) || T_WHITESPACE !== $token[0]; - } - ) - ); - foreach ( $tokens as $token ) { - if ( T_DOC_COMMENT === $token[0] ) { - $version = $this->get_version_in_docblock( $token[1] ); - if ( null !== $version ) { - return $version; - } - } - } - return null; - } - - /** - * Gets the content of a version tag in a docblock. - * - * @param string $docblock Docblock to parse. - * @return null|string The content of the version tag. - */ - private function get_version_in_docblock( $docblock ) { - $docblocktags = $this->parse_doc_block( $docblock ); - if ( isset( $docblocktags['version'] ) ) { - return $docblocktags['version']; - } - return null; - } - - /** - * Parses a docblock and gets an array of tags with their values. - * - * The tags might be specified as "@version x.y.z" or "Version: x.y.z" and they can - * be preceded by an asterisk (*). - * - * This code is based on the 'phpactor' package. - * @see https://github.com/phpactor/docblock/blob/master/lib/Parser.php - * - * @param string $docblock Docblock to parse. - * @return array Associative array of parsed data. - */ - private function parse_doc_block( $docblock ) { - $tag_documentor = '{@([a-zA-Z0-9-_\\\]+)\s*?(.*)?}'; - $tag_property = '{\s*\*?\s*(.*?):(.*)}'; - $lines = explode( PHP_EOL, $docblock ); - $tags = []; - - foreach ( $lines as $line ) { - if ( 0 === preg_match( $tag_documentor, $line, $matches ) ) { - if ( 0 === preg_match( $tag_property, $line, $matches ) ) { - continue; - } - } - - $tag_name = trim( isset( $matches[1] ) ? strtolower( $matches[1] ) : '' ); - $metadata = trim( isset( $matches[2] ) ? $matches[2] : '' ); - - $tags[ $tag_name ] = $metadata; - } - return $tags; - } - /** * Run PHP's escapeshellcmd() then undo escaping known intentional characters. *