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

Conversation

cmuench
Copy link
Member

@cmuench cmuench commented Apr 10, 2023

Magerun pull-request check-list:

  • Pull request against develop branch (if not, just close and create a new one against it)
  • README.md reflects changes (if any)
  • phar fuctional test (in tests/phar-test.sh)

Summary: Add a new command to work with Github PRs

Features of the new command

  • Dump info of the PR
  • Support Mage-OS
  • Create a patch file from PR number which can be applied to Magento

@github-actions
Copy link

github-actions bot commented Apr 10, 2023

Download the artifacts for this pull request:

@amenk
Copy link
Contributor

amenk commented Apr 10, 2023

Very cool.

Does it support auto discovery i.e. adding @package and @level tags in the patch file?

@cmuench
Copy link
Member Author

cmuench commented Apr 10, 2023

Very cool.

Does it support auto discovery i.e. adding @package and @level tags in the patch file?

I currently replace only paths.
Can you describe what you need? I am not aware of the feature.

@amenk
Copy link
Contributor

amenk commented Apr 10, 2023

See https://github.com/vaimo/composer-patches#usage-embedded-metadata

Basically the package to patch and the level of directories to remove is added to the patch file. Together with the search path defined once in the composer.json, the patches should just work without any additional manual changes, if this is implemented

@amenk
Copy link
Contributor

amenk commented Apr 10, 2023

But looking closer at the path replacement you are doing, this might not be needed. We usually use the diff as is from github and set the level and package accordingly.

@cmuench cmuench force-pushed the feature/github-patch-command branch 2 times, most recently from 21de1ad to 96bfd83 Compare April 13, 2023 08:20
public static function create(string $diffContent): string
{
$diffContent = self::processAppCode($diffContent);
$diffContent = self::processAppDesign($diffContent);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll probably still need to handle magento/framework and magento/magento2-base directories as well?

The latter doesn't need adjustments in the path I think, but the first one needs to be stripped from lib/internal/Magento/Framework

Some examples:

->addOption('diff', null, InputOption::VALUE_NONE, 'Raw diff download')
->addOption('json', null, InputOption::VALUE_NONE, 'Show pull request data as json')
->setDescription('Download patch from github merge request <comment>(experimental)</comment>');
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice to have an option to specify to which directory it should write the patch file(s)

}

$output->writeln(sprintf('<info>Patch file created:</info> <comment>%s</comment>', $filename));
}
Copy link
Contributor

@hostep hostep Apr 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this method handle generating multiple patch files, for each module separately? It's a bit hard to check by just reading the code, but I think it doesn't?

For example: magento/magento2#34360, should (in my opinion, but some people disagree) be splitted in 2 patches, for:

  • magento/magento2-base
  • magento/module-quote-graph-ql

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's maybe a better example: magento/magento2#27850
Involves:

  • magento/framework-message-queue (fun edge case for your code, why Adobe didn't put this in magento/framework is beyond me, but hey ...)
  • magento/magento2-base
  • magento/module-asynchronous-operations
  • magento/module-message-queue

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. PR is not ready to merge and some stuff is currently not handled. I guess we have also to manage the language packs here.

The magento/framework-message-queue package was initially part of the Enterprise Edition. Maybe that's why it's not part of the framework.

Is splitting in different patch files a good idea?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Splitting is in my eyes necessary because you need to specify to which module a patch should apply, and if you specify from one module that some patch should apply to another module it will not work if you change the paths.

Unless you don't change the paths and then specify a very high patch level (I think it's 4 for Magento?).
Also found this super old discussion from years ago about this: cweagans/composer-patches#76 (comment)

I'd say, give it a try with a complex PR like I specified above and see how well it works.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If someone uses ": "cweagans/composer-patches" then... we e.g. do not use it in Magento projects. The Quality Patches are also not splitted.

Copy link
Member Author

@cmuench cmuench Apr 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My current plan is not to split. Splitting sounds for that we will face a lot of possible issues.

Copy link
Contributor

@hostep hostep Apr 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem, looking through the code again, it looks like I may have misunderstood what you are tying to do.
So you can ignore this comment 🙂

Out of curiosity: what method of applying patches do you use? I think that the majority of Magento devs use either cweagans/composer-patches or vaimo/composer-patches (and both probably can work with the format of patches you are creating here)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At netz98 we have an own patch repository with a apply-patch.sh script (in the patch repo). This is then called via post-install-script/post-update-script in the composer.json.
Super simple solution.
Similar to the Quality Patches of Adobe.

For n98-magerun2 we should find a useful way for everyone. We use cweagans/composer-patches in other PHP projects, too. For Magento projects I do not like this splitting. IMHO it's a over-complication.
This does not mean that we should not support it (if it's possible).

I have not used the vaimo/composer-patches package. On the first look it looks for me that a standard (not splitted patch) can be used.

@cmuench cmuench marked this pull request as draft April 13, 2023 10:49
@cmuench cmuench force-pushed the feature/github-patch-command branch from 96bfd83 to cff6763 Compare April 13, 2023 14:15
@cmuench cmuench force-pushed the feature/github-patch-command branch from cff6763 to 50bbd63 Compare June 20, 2023 09:31
@cmuench
Copy link
Member Author

cmuench commented Jun 20, 2023

@hostep The Message Queue edge case is now handled and we have support for app/i18n.
I refactored the whole stuff by creating processors which can easily be tested (Tests are already provided).

@cmuench cmuench force-pushed the feature/github-patch-command branch from 9c53dc9 to 33522fd Compare June 20, 2023 11:07
@cmuench cmuench marked this pull request as ready for review June 20, 2023 12:00
@cmuench cmuench merged commit 5159d52 into netz98:develop Jun 20, 2023
11 checks passed
@cmuench cmuench deleted the feature/github-patch-command branch July 31, 2023 07:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants