After running composer install/update, let's patch some packages.

@param \Composer\Script\Event $event

@throws \Exception
181925
public function postOperation(Event $event)
    {
        $this->refreshPatchCollection();
        $patchCollection = $this->getPatchCollection();
        if ($patchCollection->isEmpty()) {
            $this->io->write('<info>No patches supplied.</info>');

            return;
        }
        $packages = $this->getLocalRepositoryPackages();
        foreach ($packages as $package) {
            if ($this->mustInstallPatchesForPackage($package)) {
                $this->installPatchesForPackage($package);
            }
        }
    }
1256738
public static function postAutoloadDump(Event $event): void
    {
        $event->getIO()->write('<info>    Packages Auto-Discovery [Executed]</info>');
        $vendorPath = $event->getComposer()->getConfig()->get('vendor-dir');
        $manifestPath = $vendorPath . '/../bootstrap/cache/packages.php';

        self::discoverPackages($vendorPath, $manifestPath);
    }
408556
public static function setup(Event $event)
    {
        $consoleDir = ComposerHelper::getConsoleDir();
        if (null === $consoleDir) {
            throw new \RuntimeException('Console not found');
        }

        /* Doctrine Migrations */
        if (true === class_exists(DoctrineMigrationsBundle::class)) {
            ComposerHelper::write($event, 'DoctrineMigrationsBundle exist. Start migrations.');

            ComposerHelper::executeCommand($event, $consoleDir, 'doctrine:migrations:migrate', 600);
        }
    }
22179
public function onPostPackageEvent(PackageEvent $event) {
    // Get the effected package from the Event.
    $installed_package = NULL;
    $operation = $event->getOperation();
    if ($operation instanceof UpdateOperation) {
      $installed_package = $operation->getTargetPackage();
    }
    else {
      $installed_package = $operation->getPackage();
    }
    $package_extra = $installed_package->getExtra();

    // If the effected package has installers, reset cached installers.
    if (isset($package_extra) && isset($package_extra['installer-paths'])) {
      $composer = $event->getComposer();
      $composer->getInstallationManager()->removeInstaller($this->installer);
      $composer->getInstallationManager()->addInstaller($this->installer);
      $this->installer->clearCache();
    }
  }
29850
public function preAutoloadDump(Event $event) {
    $root = $this->getBuildRoot();
    $autoload = $this->package->getDevAutoload();
    $autoload['psr-0']["Drupal\\Tests"] = $root . "/core/tests";
    $autoload['psr-0']["Drupal\\KernelTests"] = $root . "/core/tests";
    $autoload['psr-0']["Drupal\\FunctionalTests"] = $root . "/core/tests";
    $autoload['psr-0']["Drupal\\FunctionalJavascriptTests"] = $root . "/core/tests";
    $autoload['psr-4']["Drupal\\simpletest\\"] = $root . "/core/modules/simpletest/src";
    $this->package->setDevAutoload($autoload);
  }
40381
public static function postUpdateAndInstall(Event $event)
    {
        if (!defined('FLOW_PATH_ROOT')) {
            define('FLOW_PATH_ROOT', Files::getUnixStylePath(getcwd()) . '/');
        }

        if (!defined('FLOW_PATH_PACKAGES')) {
            define('FLOW_PATH_PACKAGES', Files::getUnixStylePath(getcwd()) . '/Packages/');
        }

        if (!defined('FLOW_PATH_CONFIGURATION')) {
            define('FLOW_PATH_CONFIGURATION', Files::getUnixStylePath(getcwd()) . '/Configuration/');
        }
        if (!defined('FLOW_PATH_TEMPORARY_BASE')) {
            define('FLOW_PATH_TEMPORARY_BASE', Files::getUnixStylePath(getcwd()) . '/Data/Temporary');
        }

        Files::createDirectoryRecursively('Configuration');
        Files::createDirectoryRecursively('Data');

        Files::copyDirectoryRecursively('Packages/Framework/Neos.Flow/Resources/Private/Installer/Distribution/Essentials', './', false, true);
        Files::copyDirectoryRecursively('Packages/Framework/Neos.Flow/Resources/Private/Installer/Distribution/Defaults', './', true, true);
        $packageManager = new PackageManager(PackageManager::DEFAULT_PACKAGE_INFORMATION_CACHE_FILEPATH, FLOW_PATH_PACKAGES);
        $packageManager->rescanPackages();

        chmod('flow', 0755);
    }
859644
public function onInstalled(InstalledEvent $event)
    {
        if ($event->getPackage()->getType() == self::PLUGIN_TYPE) {
            $this->addPackage($event->getPackage());
        }
    }
1164858
public function listen(Event $event)
    {
        // Plugin has been uninstalled
        if (!file_exists(__FILE__) || !file_exists(__DIR__.'/PuliPluginImpl.php')) {
            return;
        }

        // Load the implementation only after updating Composer so that we get
        // the new version of the plugin when a new one was installed
        if (null === $this->impl) {
            $this->impl = new PuliPluginImpl($event);
        }

        switch ($event->getName()) {
            case ScriptEvents::PRE_AUTOLOAD_DUMP:
                $this->impl->preAutoloadDump();
                break;
            case ScriptEvents::POST_AUTOLOAD_DUMP:
                $this->impl->postAutoloadDump();
                break;

            case ScriptEvents::POST_INSTALL_CMD:
            case ScriptEvents::POST_UPDATE_CMD:
                $this->impl->postInstall();
                break;
        }
    }
979788
public function onPostInstall(Event $event)
    {
        $lockFile = new JsonFile($this->lockFile);
        if ($lockFile->exists()) {
            $this->loadPackages($lockFile);
        } else {
            $this->scanPackages();
        }
        $this->runAction('install');
    }
668922
public function cleanupProject(Event $event)
    {
        $file = new JsonFile(Factory::getComposerFile());
        $data = $file->read();

        // Remove project and public files from project
        unset($data['extra'][self::PROJECT_FILES]);
        unset($data['extra'][self::PUBLIC_FILES]);

        // Remove redundant empty extra
        if (empty($data['extra'])) {
            unset($data['extra']);
        }

        // Save back to composer.json
        $file->write($data);
    }
961615
public function buildLogs($event)
    {
        $refPath  = '/composer/installed.json';
        $packages = [];

        if (file_exists($path = "{$this->vendorPath}{$refPath}")) {
            $packages = json_decode(file_get_contents($path), true);
        }

        $no_log = true;

        foreach ($packages as $one) {
            if (isset($one['extra']['changeLog'])) {
                $name           = $this->format($one['name']);
                $log_path       = $one['extra']['changeLog'];
                $version        = $one['version'];
                $package_path   = "$this->vendorPath/{$name}";
                $log_file       = glob("$package_path/$log_path/$version.*");

                if (!$log_file) {
                    continue;
                }

                $no_log      = false;
                $log_content = file_get_contents($log_file[0]);

                $this->alert("\"$name\" {$version} ChangeLog:", $event);
                $this->info($log_content, $event);

                // rename file so we dont display it again
                rename($log_file[0], "$package_path/$log_path/$version");
            }
        }

        if ($no_log) {
            $this->alert('No Available ChangeLogs At The Moment', $event);
        }
    }
490295
public function postPackageInstall(PackageEvent $event)
    {
        /** @var InstallOperation $operation */
        $operation = $event->getOperation();
        $package = $operation->getPackage();

        if (!$this->guardIsGrumPhpPackage($package)) {
            return;
        }

        // Schedule init when command is completed
        $this->configureScheduled = true;
        $this->initScheduled = true;
    }
167662
public function onPackageAfterExecute(Event $event)
    {
        /**
         * @var AbstractPackage    $package
         * @var AbstractController $controller
         */
        $package    = $event['package'];
        $controller = $event['controller'];

        /**
         * @var Container $container
         * @var Collector $collector
         * @var Profiler  $profiler
         */
        $container = $package->getContainer();
        $collector = $container->get('debugger.collector');
        $profiler  = $container->get('profiler');

        $collector['controller.main'] = get_class($controller);

        $collector->push('controller.executed', [
            'controller' => get_class($controller),
            'task' => $event['task'],
            'input' => $controller->getInput()->toArray(),
            'variables' => $event['variables'],
        ]);

        $name = $package->getName();

        $profiler->mark(__FUNCTION__ . ' / ' . $name . ' (' . uniqid() . ')', [
            'tag' => 'package.process',
        ]);
    }
482864
public function onPostPackageEvent(\Composer\Installer\PackageEvent $event)
    {
        $package = $this->getDrupalPackage($event->getOperation());
        if ($package) {
            if (!$this->isPackageSupported($package)) {
                $this->unsupportedPackages[$package->getName()] = $package;
            }
        }
    }
34460
public static function postInstall(Event $event)
    {
        require_once $event->getComposer()->getConfig()->get('vendor-dir').'/autoload.php';

        static::clearCompiled();
        static::artisanOptimize();
        static::artisanLangJS();
    }
1322757
public static function prePackageUninstall(PackageEvent $event) {
		
		// make sure the postUpdateCmd doesnt actually do anything
		self::setPackagesRemove();
		
		// get the basic package info
		$package      = $event->getOperation()->getPackage();
		$packageType  = $package->getType();
		$packageInfo  = array();
		
		// make sure we're only evaluating pattern lab packages. remove attributes related to them.
		if (strpos($packageType,"patternlab-") !== false) {
			
			$packageInfo["name"]     = $package->getName();
			$packageInfo["type"]     = $packageType;
			$packageInfo["pathBase"] = $event->getComposer()->getInstallationManager()->getInstallPath($package);
			
			InstallerUtil::packageRemove($packageInfo);
			
		}
		
	}
1067729
public function autoRequirePackagesPreUpdate(Event $event)
    {   
        $companyPackages = [];
        $packages = $this->composer->getPackage()->getRequires();
        foreach($packages as $packageName => $package) {
            if($this->startsWith($packageName, $this->vendorName)) {
                $companyPackages[$packageName] = $package;
            }
        }
        $repository = $this->composer->getRepositoryManager();
        foreach($companyPackages as $packageName => $package) {
            if($repository->findPackage($packageName, '*')) {
                unset($companyPackages[$packageName]);
            }
        }
        foreach($companyPackages as $packageName => $package) {
            $name = explode('/', $packageName)[1];
            $url = 'git@github.com:' . $this->vendorName . '/'. $this->vendorName . '.' . $name . '.git';
            $repository->addRepository($repository->createRepository('vcs', ['url' => $url], $packageName)); 
        }
    }