PHP code example of cromero / composer-mr-patches-commit-lock

1. Go to this page and download the library: Download cromero/composer-mr-patches-commit-lock library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

cromero / composer-mr-patches-commit-lock example snippets




namespace MyProject\GitProvider;

use Cromero\Composer\PatchesCommitLock\GitProvider\AbstractGitProvider;
use Composer\IO\IOInterface;

class CustomGitLabProvider extends AbstractGitProvider
{
    public function getName(): string
    {
        return 'Custom GitLab';
    }

    public function getIdentifier(): string
    {
        return 'custom-gitlab';
    }

    protected function extractIssueNumber(string $url): ?string
    {
        if (preg_match('#^https?://gitlab\.mycompany\.com/([^/]+)/([^/]+)/merge_requests/(\d+)\.patch$#i', $url, $matches)) {
            return $matches[1] . '/' . $matches[2] . '#' . $matches[3];
        }
        return null;
    }

    protected function buildApiUrl(string $issueNumber): string
    {
        [$project, $mrId] = explode('#', $issueNumber);
        return "https://gitlab.mycompany.com/api/v4/projects/" . urlencode($project) . "/merge_requests/{$mrId}";
    }

    protected function extractCommitHash(array $response): ?string
    {
        return $response['sha'] ?? null;
    }

    protected function buildPatchUrl(string $originalUrl, string $commitHash): ?string
    {
        return "https://gitlab.mycompany.com/..."; // Your patch URL format
    }
}