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

github:pr command #1179

Merged
merged 11 commits into from
Jun 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions .ddev/commands/web/install-magento-ce
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ if [ -x PHP_BIN ]; then
PHP_BIN="php"
fi

if [ ! -x COMPOSER_BIN ]; then
COMPOSER_BIN="/usr/local/bin/composer"
fi

if [ -x $TZ ]; then
TZ="UTC"
fi
Expand All @@ -26,7 +30,7 @@ MAGENTO_SUBDOMAIN="${MAGENTO_VERSION//[-_.]/-}"
USE_ELASTICSEARCH=$2

check_if_db_exists() {
echo "SHOW DATABASES" | mysql -hdb -udb -pdb | grep -q "$MAGENTO_DB_NAME"
echo "SHOW DATABASES" | mysql -hdb -udb -pdb | grep -qE "^$MAGENTO_DB_NAME\$"

if [ $? -eq 1 ]; then
echo "CREATE DATABASE ${MAGENTO_DB_NAME}" | mysql -hdb -uroot -proot
Expand Down Expand Up @@ -57,7 +61,7 @@ install_magento() {
check_if_db_exists

if [ ! -d $MAGENTO_ROOT_DIR ]; then
"$PHP_BIN" /usr/local/bin/composer --no-interaction create-project --repository-url=https://repo.magento.com/ magento/project-community-edition="$MAGENTO_VERSION" "$MAGENTO_ROOT_DIR"
"$PHP_BIN" $COMPOSER_BIN --no-interaction create-project --repository-url=https://repo.magento.com/ magento/project-community-edition="$MAGENTO_VERSION" "$MAGENTO_ROOT_DIR"
fi

cd $MAGENTO_ROOT_DIR
Expand Down
2 changes: 1 addition & 1 deletion .ddev/commands/web/install-magento-ce-git
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ MAGENTO_ROOT_DIR="/opt/magento-test-environments/magento_${NORMALIZED_GIT_BRANCH
MAGENTO_SUBDOMAIN="${NORMALIZED_GIT_BRANCH//[-_.]/-}"

check_if_db_exists() {
echo "SHOW DATABASES" | mysql -hdb -udb -pdb | grep -q "$MAGENTO_DB_NAME"
echo "SHOW DATABASES" | mysql -hdb -udb -pdb | grep -qE "^$MAGENTO_DB_NAME\$"

if [ $? -eq 1 ]; then
echo "CREATE DATABASE ${MAGENTO_DB_NAME}" | mysql -hdb -uroot -proot
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ RECENT CHANGES
- Add: #1177: New commands to manage sales sequences (by Jeroen Boersma)
- Add: #1176: New command to redeploy base packages (by Christian Münch)
- Add: #1226: New sys:cron:kill command (by Christian Münch)
- Imp: #1179: New github:pr command (by Christian Münch)
- Imp: #1182: Add debug output if Magento Core Commands cannot be used (by Christian Münch)
- Imp: #1185: Do less compatibility checks (by Christian Münch)
- Imp: Update 3rd party dependencies (php-cs-fixer, psysh, phpstan, phpunit, requests, symfony)
Expand Down
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1079,6 +1079,43 @@ n98-magerun2.phar integration:delete <name_or_id>

---

### Github

(experimental) Commands

### Pull Requests

Gets infos about Github Pull Requests.
If no Github Repository is defined by `---repository` (-r) option the default
Magento 2 Github Repository `magento/magento2` is used.
For the [Mage-OS](https://github.com/mage-os/mageos-magento2) repository we provide a shortcut option `--mage-os`.

If the command is executed without any options it will show infos about the PR.

```sh
# Magento 2 Open Source
n98-magerun2.phar github:pr:patch <pr-number>

# Mage-OS
n98-magerun2.phar github:pr:patch --mage-os <pr-number>
```

*Create a patch file from PR:*

```sh
n98-magerun2.phar github:pr:patch --patch <pr-number>
```

Files of the magento2-base and magento2-ee-base and b2b base packages are currently not handled by the command.

**List only the raw diff:**

```sh
n98-magerun2.phar github:pr:patch --diff <pr-number>
```

---

### Interactive Development Console

Opens PHP interactive shell with initialized Magento Admin-Store.
Expand Down
1 change: 1 addition & 0 deletions box.json.dist
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"directories": [
"src",
"res",
"vendor/rmccue/requests/certificates",
"vendor/twig/twig/src"
],
"replacements": {
Expand Down
1 change: 1 addition & 0 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ commands:
- N98\Magento\Command\GiftCard\CreateCommand
- N98\Magento\Command\GiftCard\InfoCommand
- N98\Magento\Command\GiftCard\RemoveCommand
- N98\Magento\Command\Github\PullRequestCommand
- N98\Magento\Command\Media\DumpCommand
- N98\Magento\Command\OpenBrowserCommand
- N98\Magento\Command\SearchEngine\ListCommand
Expand Down
39 changes: 39 additions & 0 deletions src/N98/Magento/Command/Github/PatchFileContent/Creator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php
/**
* @copyright Copyright (c) netz98 GmbH (https://www.netz98.de)
*
* @see PROJECT_LICENSE.txt
*/

declare(strict_types=1);

namespace N98\Magento\Command\Github\PatchFileContent;

use N98\Magento\Command\Github\PatchFileContent\Processor\AppCodeProcessor;
use N98\Magento\Command\Github\PatchFileContent\Processor\AppDesignProcessor;
use N98\Magento\Command\Github\PatchFileContent\Processor\I18nProcessor;
use N98\Magento\Command\Github\PatchFileContent\Processor\LibProcessor;

class Creator
{
/**
* @param string $diffContent
* @return string
*/
public static function create(string $diffContent): string
{
$appDesignProcessor = new AppDesignProcessor();
$diffContent = $appDesignProcessor->process($diffContent);

$appCodeProcessor = new AppCodeProcessor();
$diffContent = $appCodeProcessor->process($diffContent);

$i18nProcessor = new I18nProcessor();
$diffContent = $i18nProcessor->process($diffContent);

$libProcessor = new LibProcessor();
$diffContent = $libProcessor->process($diffContent);

return $diffContent;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
/**
* @copyright Copyright (c) netz98 GmbH (https://www.netz98.de)
*
* @see PROJECT_LICENSE.txt
*/

declare(strict_types=1);

namespace N98\Magento\Command\Github\PatchFileContent\Processor;

class AppCodeProcessor implements ProcessorInterface
{
public function process(string $diffContent): string
{
$callback = function ($matches) {
// camelcase to dash
$matches[1] = preg_replace('/([a-z])([A-Z])/', '$1-$2', $matches[1]);

return 'vendor/magento/module-' . strtolower($matches[1]) . '/';
};

return (string) preg_replace_callback('/app\/code\/Magento\/([a-zA-Z0-9_]+)\//', $callback, $diffContent);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
/**
* @copyright Copyright (c) netz98 GmbH (https://www.netz98.de)
*
* @see PROJECT_LICENSE.txt
*/

declare(strict_types=1);

namespace N98\Magento\Command\Github\PatchFileContent\Processor;

class AppDesignProcessor implements ProcessorInterface
{
public function process(string $diffContent): string
{
// preg_replace app/design/frontend/Magento/<blank>/ with vendor/magento/theme-frontend-<blank>/
$diffContent = preg_replace(
'/app\/design\/frontend\/Magento\/([a-zA-Z0-9_]+)\//',
'vendor/magento/theme-frontend-$1/',
$diffContent
);

// preg_replace app/design/adminhtml/Magento/<blank>/ with vendor/magento/theme-adminhtml-<blank>/
$diffContent = preg_replace(
'/app\/design\/adminhtml\/Magento\/([a-zA-Z0-9_]+)\//',
'vendor/magento/theme-adminhtml-$1/',
$diffContent
);

return $diffContent;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
/**
* @copyright Copyright (c) netz98 GmbH (https://www.netz98.de)
*
* @see PROJECT_LICENSE.txt
*/

declare(strict_types=1);

namespace N98\Magento\Command\Github\PatchFileContent\Processor;

class I18nProcessor implements ProcessorInterface
{
public function process(string $diffContent): string
{
$diffContent = preg_replace_callback(
'/app\/i18n\/([a-zA-Z0-9_]+)\//',
function ($matches) {
return 'vendor/magento/language-' . strtolower($matches[1]) . '/';
},
$diffContent
);

return $diffContent;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php
/**
* @copyright Copyright (c) netz98 GmbH (https://www.netz98.de)
*
* @see PROJECT_LICENSE.txt
*/

declare(strict_types=1);

namespace N98\Magento\Command\Github\PatchFileContent\Processor;

class LibProcessor implements ProcessorInterface
{
public function process(string $diffContent): string
{
// edge cases -> Message Queue is part of the framework directory but later on in an own package
$diffContent = preg_replace(
'/lib\/internal\/Magento\/Framework\/MessageQueue\/([a-zA-Z0-9_]+)\//',
'vendor/magento/framework-message-queue/$1/',
$diffContent
);

// Handle the rest of the lib/internal/Magento directory
$callback = function ($matches) {
// camelcase to dash
$matches[1] = preg_replace('/([a-z])([A-Z])/', '$1-$2', $matches[1]);

return 'vendor/magento/' . strtolower($matches[1]) . '/';
};

$diffContent = (string) preg_replace_callback(
'/lib\/internal\/Magento\/([a-zA-Z0-9_-]+)\//',
$callback,
$diffContent
);

return $diffContent;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
/**
* @copyright Copyright (c) netz98 GmbH (https://www.netz98.de)
*
* @see PROJECT_LICENSE.txt
*/

declare(strict_types=1);

namespace N98\Magento\Command\Github\PatchFileContent\Processor;

interface ProcessorInterface
{
public function process(string $diffContent): string;
}
Loading