diff --git a/config/services.yaml b/config/services.yaml index 654690b3..4b78a517 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -79,15 +79,15 @@ services: App\Services\GitHub\GitHubService: arguments: - $gitHubApiToken: '%app.githubApiToken%' + $apiToken: '%app.githubApiToken%' $dataFolder: '%app.dataDir%' - $gitHubUrl: '%app.githubUrl%' + $url: '%app.githubUrl%' App\Services\GitLab\GitLabService: arguments: - $gitLabApiToken: '%app.gitlabApiToken%' + $apiToken: '%app.gitlabApiToken%' $dataFolder: '%app.dataDir%' - $gitLabUrl: '%app.gitlabUrl%' + $url: '%app.gitlabUrl%' App\Repository\TranslationUpdateEntityRepository: arguments: diff --git a/src/Entity/TranslationUpdateEntity.php b/src/Entity/TranslationUpdateEntity.php index 8ae5126c..f608ff21 100644 --- a/src/Entity/TranslationUpdateEntity.php +++ b/src/Entity/TranslationUpdateEntity.php @@ -55,6 +55,13 @@ class TranslationUpdateEntity { */ protected ?string $language = null; + /** + * Subject message. + * @see getSubject() + */ + private string $subject = 'Translation update'; + + public function setAuthor(string $author): void { $this->author = $author; } @@ -112,6 +119,22 @@ public function getLanguage(): ?string { return $this->language; } + /** + * Returns a standard subject for translation updates. + * + * This can be used e.g. as commit message, pull request title or email subject. + * If defined, the language code is added as a suffix. + * + * @return string + */ + public function getSubject(): string { + $subject = $this->subject; + if ($this->language) { + $subject .= ' (' . $this->language . ')'; + } + return $subject; + } + public function setErrorMsg(string $errorMsg): void { $this->errorMsg = $errorMsg; diff --git a/src/Services/GitHostingProviderService.php b/src/Services/GitHostingProviderService.php new file mode 100644 index 00000000..4a04a0bb --- /dev/null +++ b/src/Services/GitHostingProviderService.php @@ -0,0 +1,115 @@ +url = $url; + } + + protected function getCachePool(string $dataFolder): FilesystemCachePool + { + // folders are relative to folder set here + $filesystemAdapter = new Local($dataFolder); + $filesystem = new Filesystem($filesystemAdapter); + + $pool = new FilesystemCachePool($filesystem); + $pool->setFolder('cache/' . strtolower($this->provider)); + + return $pool; + } + + /** + * Create fork in our Hosting Provider account + * + * @param string $url URL to create the fork from + * @return string Git URL of the fork + */ + abstract public function createFork(string $url): string; + + /** + * Delete fork from our Hosting Provider account + * + * @param string $remoteUrl Git url of the forked repository + */ + abstract public function deleteFork(string $remoteUrl): void; + + /** + * @param string $patchBranch name of branch with language update + * @param string $destinationBranch name of branch at remote + * @param string $url git url original upstream repository + * @param string $patchUrl remote url + * @param string $title Title for the pull request + * @param string $body Text to be inserted as description for the pull request + */ + abstract public function createPullRequest(string $patchBranch, string $destinationBranch, string $url, string $patchUrl, string $title, string $body): void; + + /** + * Get information about the open pull requests i.e. url and count + * + * @param string $urlUpstream original git clone url + * @param string $languageCode + * @return array{count: int, listURL: string, title: string} + */ + abstract public function getOpenPRListInfo(string $urlUpstream, string $languageCode): array; + + /** + * @param string $url git clone url + * @return array with user's account name, repository name + */ + protected function getUsernameAndRepositoryFromURL(string $url): array + { + $result = preg_replace($this::REGEX_REPO_USER, '$2', $url, 1, $counter); + if ($counter === 0) { + throw new $this->exceptionType('Invalid ' . $this->provider . ' clone URL: ' . $url); + } + return explode('/', $result); + } + +} diff --git a/src/Services/GitHostingProviderStatusService.php b/src/Services/GitHostingProviderStatusService.php new file mode 100644 index 00000000..ca9058f7 --- /dev/null +++ b/src/Services/GitHostingProviderStatusService.php @@ -0,0 +1,40 @@ +status === null) { + $json = file_get_contents($this::STATUS_URL); + $this->status = $this->checkResponse($json); + } + return $this->status; + } + + /** + * Returns true if response status of API Requests is good, otherwise false + * + * @param string|false $content + * @return bool + */ + abstract protected function checkResponse($content): bool; + +} diff --git a/src/Services/GitHub/GitHubService.php b/src/Services/GitHub/GitHubService.php index 612f8eff..022ae9cb 100644 --- a/src/Services/GitHub/GitHubService.php +++ b/src/Services/GitHub/GitHubService.php @@ -2,49 +2,45 @@ namespace App\Services\GitHub; -use Cache\Adapter\Filesystem\FilesystemCachePool; +use App\Services\GitHostingProviderService; use Exception; use Github\AuthMethod; use Github\Client; use Github\Exception\MissingArgumentException; use Github\Exception\RuntimeException; -use League\Flysystem\Adapter\Local; -use League\Flysystem\Filesystem; use Symfony\Component\HttpClient\HttplugClient; -class GitHubService +class GitHubService extends GitHostingProviderService { + const REGEX_REPO_USER = '#^(https://github.com/|git@.*?github.com:|git://github.com/)(.*)\.git$#'; - private Client $client; - private string $gitHubUrl; + protected string $provider = 'GitHub'; + protected string $exceptionType = GitHubServiceException::class; - public function __construct(string $gitHubApiToken, string $dataFolder, string $gitHubUrl, bool $autoStartup = true) + /** + * @var Client + */ + protected $client; + + + public function __construct(string $apiToken, string $dataFolder, string $url, bool $autoStartup = true) { - $this->gitHubUrl = $gitHubUrl; + parent::__construct($apiToken, $dataFolder, $url, $autoStartup); if (!$autoStartup) { return; } - $filesystemAdapter = new Local($dataFolder); // folders are relative to folder set here - $filesystem = new Filesystem($filesystemAdapter); - - $pool = new FilesystemCachePool($filesystem); - $pool->setFolder('cache/github'); - $this->client = Client::createWithHttpClient( new HttplugClient() ); - $this->client->addCache($pool); - $this->client->authenticate($gitHubApiToken, null, AuthMethod::ACCESS_TOKEN); + $this->client->addCache($this->getCachePool($dataFolder)); + $this->client->authenticate($apiToken, null, AuthMethod::ACCESS_TOKEN); } /** - * Create fork in our GitHub account - * - * @param string $url GitHub URL to create the fork from - * @return string Git URL of the fork + * @inheritDoc * * @throws GitHubForkException * @throws GitHubServiceException @@ -61,9 +57,7 @@ public function createFork(string $url): string } /** - * Delete fork from our GitHub account - * - * @param string $remoteUrl git url of the forked repository + * @inheritDoc * * @throws GitHubServiceException */ @@ -78,17 +72,13 @@ public function deleteFork(string $remoteUrl): void } /** - * @param string $patchBranch name of branch with language update - * @param string $destinationBranch name of branch at remote - * @param string $languageCode - * @param string $url git url original upstream repository - * @param string $patchUrl remote url + * @inheritDoc * * @throws GitHubCreatePullRequestException * @throws GitHubServiceException * @throws MissingArgumentException */ - public function createPullRequest(string $patchBranch, string $destinationBranch, string $languageCode, string $url, string $patchUrl): void + public function createPullRequest(string $patchBranch, string $destinationBranch, string $url, string $patchUrl, string $title, string $body): void { [$user, $repository] = $this->getUsernameAndRepositoryFromURL($url); [$repoName, ] = $this->getUsernameAndRepositoryFromURL($patchUrl); @@ -97,8 +87,8 @@ public function createPullRequest(string $patchBranch, string $destinationBranch $this->client->api('pull_request')->create($user, $repository, [ 'base' => $destinationBranch, 'head' => $repoName . ':' . $patchBranch, - 'title' => 'Translation update (' . $languageCode . ')', - 'body' => 'This pull request contains some translation updates.' + 'title' => $title, + 'body' => $body, ]); } catch (RuntimeException $e) { throw new GitHubCreatePullRequestException($e->getMessage() . " $user/$repository", 0, $e); @@ -106,18 +96,14 @@ public function createPullRequest(string $patchBranch, string $destinationBranch } /** - * Get information about the open pull requests i.e. url and count - * - * @param string $url original git clone url - * @param string $languageCode - * @return array{count: int, listURL: string, title: string} + * @inheritDoc * * @throws GitHubServiceException * @throws Exception only if in 'test' environment */ - public function getOpenPRListInfo(string $url, string $languageCode): array + public function getOpenPRListInfo(string $urlUpstream, string $languageCode): array { - [$user, $repository] = $this->getUsernameAndRepositoryFromURL($url); + [$user, $repository] = $this->getUsernameAndRepositoryFromURL($urlUpstream); $info = [ 'listURL' => '', @@ -144,33 +130,15 @@ public function getOpenPRListInfo(string $url, string $languageCode): array return $info; } - /** - * @param string $url git clone url - * @return array with user's account name, repository name - * - * @throws GitHubServiceException - */ - private function getUsernameAndRepositoryFromURL(string $url): array - { - $result = preg_replace( - '#^(https://github.com/|git@.*?github.com:|git://github.com/)(.*)\.git$#', - '$2', $url, 1, $counter - ); - if ($counter === 0) { - throw new GitHubServiceException('Invalid GitHub clone URL: ' . $url); - } - return explode('/', $result); - } - /** * @param string $url git clone url * @return string modified git clone url */ private function gitHubUrlHack(string $url): string { - if ($this->gitHubUrl === 'github.com') { + if ($this->url === 'github.com') { return $url; } - return str_replace('github.com', $this->gitHubUrl, $url); + return str_replace('github.com', $this->url, $url); } } diff --git a/src/Services/GitHub/GitHubStatusService.php b/src/Services/GitHub/GitHubStatusService.php index c36451d8..4dc788a4 100644 --- a/src/Services/GitHub/GitHubStatusService.php +++ b/src/Services/GitHub/GitHubStatusService.php @@ -1,47 +1,22 @@ status === null) { - $this->status = $this->checkFunctional(); - } - return $this->status; - } + protected const STATUS_URL = 'https://www.githubstatus.com/api/v2/summary.json'; - /** - * Retrieve status and check if GitHub is functional - * - * @return bool true if status is good, otherwise false - */ - private function checkFunctional(): bool - { - // more about the GitHub status api, see: https://www.githubstatus.com/api - // (same api as https://kctbh9vrtdwd.statuspage.io/api/v2/summary.json) https://www.githubstatus.com/api/v2/summary.json - $content = file_get_contents('https://www.githubstatus.com/api/v2/summary.json'); - - return $this->checkResponse($content); - } - /** - * Returns true if response status of API Requests is good, otherwise false - * - * @param string|false $content - * @return bool - */ protected function checkResponse($content): bool { if (!$content) { @@ -67,4 +42,4 @@ protected function checkResponse($content): bool return $numberOfWorkingComponents === 2; } -} \ No newline at end of file +} diff --git a/src/Services/GitLab/GitLabService.php b/src/Services/GitLab/GitLabService.php index 2179416d..7673a8cc 100644 --- a/src/Services/GitLab/GitLabService.php +++ b/src/Services/GitLab/GitLabService.php @@ -2,45 +2,44 @@ namespace App\Services\GitLab; -use Cache\Adapter\Filesystem\FilesystemCachePool; +use App\Services\GitHostingProviderService; use Exception; use Gitlab\Api\MergeRequests; use Gitlab\Client; use Gitlab\Exception\RuntimeException; use Gitlab\HttpClient\Builder; use Http\Client\Common\Plugin\LoggerPlugin; -use League\Flysystem\Adapter\Local; -use League\Flysystem\Filesystem; use Psr\Log\LoggerInterface; -class GitLabService +class GitLabService extends GitHostingProviderService { - private string $gitLabUrl; - private Client $client; + const REGEX_REPO_USER = '#^(https://gitlab.com/|git@.*?gitlab.com:|git://gitlab.com/)(.*)\.git$#'; + + protected string $provider = 'GitLab'; + protected string $exceptionType = GitLabServiceException::class; + + /** + * @var Client + */ + protected $client; + private string $projectIdFolder; - public function __construct(string $gitLabApiToken, string $dataFolder, string $gitLabUrl, LoggerInterface $httpLogger, bool $autoStartup = true) + public function __construct(string $apiToken, string $dataFolder, string $url, LoggerInterface $httpLogger, bool $autoStartup = true) { - $this->gitLabUrl = $gitLabUrl; + parent::__construct($apiToken, $dataFolder, $url, $autoStartup); if (!$autoStartup) { return; } - $filesystemAdapter = new Local($dataFolder); // folders are relative to folder set here - $filesystem = new Filesystem($filesystemAdapter); - - $pool = new FilesystemCachePool($filesystem); - $pool->setFolder('cache/gitlab'); - - $loggerPlugin = new LoggerPlugin($httpLogger); //==new Logger('http') $builder = new Builder(); - $builder->addCache($pool); + $builder->addCache($this->getCachePool($dataFolder)); $builder->addPlugin($loggerPlugin); $this->client = new Client($builder); - $this->client->authenticate($gitLabApiToken, Client::AUTH_HTTP_TOKEN); + $this->client->authenticate($apiToken, Client::AUTH_HTTP_TOKEN); } public function setProjectIdFolder(string $projectIdFolder): void @@ -69,10 +68,7 @@ private function getProjectIdOfUpstream(): int } /** - * Create fork in our GitLab account - * - * @param string $url GitLab URL to create the fork from - * @return string Git URL of the fork + * @inheritDoc * * @throws GitLabForkException * @throws GitLabServiceException @@ -91,9 +87,7 @@ public function createFork(string $url): string } /** - * Delete fork from our GitHub account - * - * @param string $remoteUrl git url of the forked repository + * @inheritDoc * * @throws GitLabServiceException */ @@ -112,16 +106,12 @@ public function deleteFork(string $remoteUrl): void /** - * @param string $patchBranch name of branch with language update - * @param string $destinationBranch name of branch at remote - * @param string $languageCode - * @param string $url git url original upstream repository - * @param string $patchUrl remote url + * @inheritDoc * * @throws GitLabCreateMergeRequestException * @throws GitLabServiceException */ - public function createPullRequest(string $patchBranch, string $destinationBranch, string $languageCode, string $url, string $patchUrl): void + public function createPullRequest(string $patchBranch, string $destinationBranch, string $url, string $patchUrl, string $title, string $body): void { [$userUpstream, $repositoryUpstream] = $this->getUsernameAndRepositoryFromURL($url); $idUpstream = $this->getProjectIdOfUpstream(); @@ -132,9 +122,9 @@ public function createPullRequest(string $patchBranch, string $destinationBranch "$userFork/$repositoryFork", $patchBranch, $destinationBranch, - "Translation update ($languageCode)", + $title, [ - 'description' => 'This pull request contains some translation updates.', + 'description' => $body, 'target_project_id' => $idUpstream, 'remove_source_branch' => true ] @@ -145,11 +135,7 @@ public function createPullRequest(string $patchBranch, string $destinationBranch } /** - * Get information about the open pull requests i.e. url and count - * - * @param string $urlUpstream original git clone url - * @param string $languageCode - * @return array{count: int, listURL: string, title: string} + * @inheritDoc * * @throws GitLabServiceException * @throws Exception only if in 'test' environment @@ -187,31 +173,15 @@ public function getOpenPRListInfo(string $urlUpstream, string $languageCode): ar return $info; } - - /** - * @param string $url git clone url - * @return array with user's account name, repository name - * - * @throws GitLabServiceException - */ - private function getUsernameAndRepositoryFromURL(string $url): array - { - $result = preg_replace('#^(https://gitlab.com/|git@.*?gitlab.com:|git://gitlab.com/)(.*)\.git$#', '$2', $url, 1, $counter); - if ($counter === 0) { - throw new GitLabServiceException('Invalid GitLab clone URL: ' . $url); - } - return explode('/', $result); - } - /** * @param string $url git clone url * @return string modified git clone url */ private function gitLabUrlHack(string $url): string { - if ($this->gitLabUrl === 'gitlab.com') { + if ($this->url === 'gitlab.com') { return $url; } - return str_replace('gitlab.com', $this->gitLabUrl, $url); + return str_replace('gitlab.com', $this->url, $url); } } \ No newline at end of file diff --git a/src/Services/GitLab/GitLabStatusService.php b/src/Services/GitLab/GitLabStatusService.php index 22dec97f..10352263 100644 --- a/src/Services/GitLab/GitLabStatusService.php +++ b/src/Services/GitLab/GitLabStatusService.php @@ -1,49 +1,28 @@ status === null) { - $this->status = $this->checkFunctional(); - } - return $this->status; - } - /** - * Retrieve status and check if GitLab is functional + * GitLab status page. * - * @return bool true if status is good, otherwise false + * The URL to retrieve the status information in JSON is documented in the + * status.io knowledge base article for the Web Status Widget. + * @see https://status.gitlab.com/ + * @see https://status.io/pages/5b36dc6502d06804c08349f7 + * @see https://kb.status.io/developers/public-status-api/ + * @see https://kb.status.io/miscellaneous/status-widget/ + * @see https://kb.status.io/developers/status-codes/ */ - private function checkFunctional(): bool - { - // GitLab status page, see: https://status.gitlab.com/ (or https://status.io/pages/5b36dc6502d06804c08349f7) - - // more about the status.io status api, see: https://kb.status.io/developers/public-status-api/ - // https://4888742015139690.hostedstatus.com/1.0/status/5b36dc6502d06804c08349f7 - $content = file_get_contents('http://hostedstatus.com/1.0/status/5b36dc6502d06804c08349f7'); - - return $this->checkResponse($content); - } + protected const STATUS_URL = 'http://hostedstatus.com/1.0/status/5b36dc6502d06804c08349f7'; + public const STATUS_OPERATIONAL = 100; - /** - * Returns true if response status of API Requests is good, otherwise false - * - * @param string|false $content - * @return bool - */ protected function checkResponse($content): bool { if (!$content) { @@ -69,4 +48,4 @@ protected function checkResponse($content): bool return $numberOfWorkingComponents === 2; } -} \ No newline at end of file +} diff --git a/src/Services/Repository/Behavior/GitHubBehavior.php b/src/Services/Repository/Behavior/GitHostingProviderBehavior.php similarity index 73% rename from src/Services/Repository/Behavior/GitHubBehavior.php rename to src/Services/Repository/Behavior/GitHostingProviderBehavior.php index 8eed9617..d4b3c806 100644 --- a/src/Services/Repository/Behavior/GitHubBehavior.php +++ b/src/Services/Repository/Behavior/GitHostingProviderBehavior.php @@ -2,7 +2,6 @@ namespace App\Services\Repository\Behavior; -use Github\Exception\MissingArgumentException; use App\Entity\LanguageNameEntity; use App\Entity\RepositoryEntity; use App\Entity\TranslationUpdateEntity; @@ -13,63 +12,74 @@ use App\Services\Git\GitPullException; use App\Services\Git\GitPushException; use App\Services\Git\GitRepository; -use App\Services\GitHub\GitHubCreatePullRequestException; -use App\Services\GitHub\GitHubForkException; -use App\Services\GitHub\GitHubService; -use App\Services\GitHub\GitHubServiceException; -use App\Services\GitHub\GitHubStatusService; +use App\Services\GitHostingProviderService; +use App\Services\GitHostingProviderStatusService; -class GitHubBehavior implements RepositoryBehavior +class GitHostingProviderBehavior implements RepositoryBehavior { + /** + * Git Service api, provider specific + */ + protected GitHostingProviderService $api; - private GitHubService $api; - private GitHubStatusService $gitHubStatus; + /** + * Service for status of the api + */ + protected GitHostingProviderStatusService $status; - public function __construct(GitHubService $api, GitHubStatusService $gitHubStatus) + /** + * Text to be inserted as description for the pull request. + * @see sendChange() + */ + protected string $prBody = <<< EOT + This pull request contains some translation updates. + EOT; + + + public function __construct(GitHostingProviderService $api, GitHostingProviderStatusService $statusService) { $this->api = $api; - $this->gitHubStatus = $gitHubStatus; + $this->status = $statusService; } /** - * Create branch and push it to remote, create subsequently pull request at Github + * Create branch and push it to the remote fork, then submit a pull request * * @param GitRepository $tempGit temporary local git repository with the patch of the language update * @param TranslationUpdateEntity $update * @param GitRepository $forkedGit git repository cloned of the forked repository * - * @throws GitHubCreatePullRequestException - * @throws GitHubServiceException * @throws GitAddException * @throws GitBranchException * @throws GitCheckoutException * @throws GitNoRemoteException * @throws GitPushException - * @throws MissingArgumentException */ public function sendChange(GitRepository $tempGit, TranslationUpdateEntity $update, GitRepository $forkedGit): void { - $remoteUrl = $forkedGit->getRemoteUrl(); - $tempGit->remoteAdd('github', $remoteUrl); + $tempGit->remoteAdd('remote_fork', $remoteUrl); $branchName = 'lang_update_' . $update->getId() . '_' . $update->getUpdated(); $tempGit->branch($branchName); $tempGit->checkout($branchName); - $tempGit->push('github', $branchName); + $tempGit->push('remote_fork', $branchName); - $this->api->createPullRequest($branchName, $update->getRepository()->getBranch(), - $update->getLanguage(), $update->getRepository()->getUrl(), $remoteUrl); + $this->api->createPullRequest( + $branchName, + $update->getRepository()->getBranch(), + $update->getRepository()->getUrl(), + $remoteUrl, + $update->getSubject(), + $this->prBody + ); } /** - * Fork original repo at Github and return url of the fork + * Fork original repo and return the fork's url. * * @param RepositoryEntity $repository * @return string Git clone URL of the fork - * - * @throws GitHubForkException - * @throws GitHubServiceException */ public function createOriginURL(RepositoryEntity $repository): string { @@ -77,11 +87,10 @@ public function createOriginURL(RepositoryEntity $repository): string } /** - * Remove the fork on GitHub + * Remove the fork. * * @param GitRepository $forkedGit git repository cloned of the forked repository * - * @throws GitHubServiceException * @throws GitNoRemoteException */ public function removeRemoteFork(GitRepository $forkedGit): void @@ -125,13 +134,13 @@ public function reset(GitRepository $forkedGit, RepositoryEntity $repository): b } /** - * Check if GitHub is functional + * Check if Git Hosting provider is functional. * * @return bool */ public function isFunctional(): bool { - return $this->gitHubStatus->isFunctional(); + return $this->status->isFunctional(); } /** @@ -140,8 +149,6 @@ public function isFunctional(): bool * @param RepositoryEntity $repository * @param LanguageNameEntity $language * @return array{count: int, listURL: string, title: string} - * - * @throws GitHubServiceException */ public function getOpenPRListInfo(RepositoryEntity $repository, LanguageNameEntity $language): array { diff --git a/src/Services/Repository/Behavior/GitLabBehavior.php b/src/Services/Repository/Behavior/GitLabBehavior.php deleted file mode 100644 index ec9632b9..00000000 --- a/src/Services/Repository/Behavior/GitLabBehavior.php +++ /dev/null @@ -1,152 +0,0 @@ -api = $api; - $this->gitLabStatus = $gitLabStatus; - } - - /** - * Create branch and push it to remote, create subsequently pull request at GitLab - * - * @param GitRepository $tempGit temporary local git repository with the patch of the language update - * @param TranslationUpdateEntity $update - * @param GitRepository $forkedGit git repository cloned of the fork - * - * @throws GitLabCreateMergeRequestException - * @throws GitLabServiceException - * @throws GitAddException - * @throws GitBranchException - * @throws GitCheckoutException - * @throws GitNoRemoteException - * @throws GitPushException - */ - public function sendChange(GitRepository $tempGit, TranslationUpdateEntity $update, GitRepository $forkedGit): void - { - $remoteUrl = $forkedGit->getRemoteUrl(); - $tempGit->remoteAdd('gitlab', $remoteUrl); - $branchName = 'lang_update_' . $update->getId() . '_' . $update->getUpdated(); - $tempGit->branch($branchName); - $tempGit->checkout($branchName); - - $tempGit->push('gitlab', $branchName); - - $this->api->createPullRequest( - $branchName, $update->getRepository()->getBranch(), - $update->getLanguage(), $update->getRepository()->getUrl(), $remoteUrl - ); - } - - /** - * Fork original repo at GitLab and return url of the fork - * - * @param RepositoryEntity $repository - * @return string git clone URL of the fork - * - * @throws GitLabForkException - * @throws GitLabServiceException - */ - public function createOriginURL(RepositoryEntity $repository): string - { - return $this->api->createFork($repository->getUrl()); - } - - - /** - * Remove the fork on GitLab - * - * @param GitRepository $forkedGit git repository cloned of the fork repository - * - * @throws GitLabServiceException - * @throws GitNoRemoteException - */ - public function removeRemoteFork(GitRepository $forkedGit): void - { - $remoteUrl = $forkedGit->getRemoteUrl(); - - $this->api->deleteFork($remoteUrl); - } - - /** - * Update from original and push to fork of translate tool - * - * @param GitRepository $forkedGit git repository cloned of the forked repository - * @param RepositoryEntity $repository - * @return bool true if the repository is changed - * - * @throws GitPullException - * @throws GitPushException - */ - public function pull(GitRepository $forkedGit, RepositoryEntity $repository): bool - { - $changed = $forkedGit->pull($repository->getUrl(), $repository->getBranch()) === GitRepository::PULL_CHANGED; - $forkedGit->push('origin', $repository->getBranch()); - return $changed; - } - - /** - * Update from original and push to fork of translate tool (assumes there are no local changes) - * - * @param GitRepository $forkedGit git repository cloned of the forked repository - * @param RepositoryEntity $repository - * @return bool true if the repository is changed - * - * @throws GitPullException - * @throws GitPushException - */ - public function reset(GitRepository $forkedGit, RepositoryEntity $repository): bool - { - $changed = $forkedGit->reset($repository->getUrl(), $repository->getBranch()) === GitRepository::PULL_CHANGED; - $forkedGit->push('origin', $repository->getBranch()); - return $changed; - } - - /** - * Check if GitLab is functional - * - * @return bool - */ - public function isFunctional(): bool - { - return $this->gitLabStatus->isFunctional(); - } - - /** - * Get information about the open pull requests i.e. url and count - * - * @param RepositoryEntity $repository - * @param LanguageNameEntity $language - * @return array{count: int, listURL: string, title: string} - * - * @throws GitLabServiceException - */ - public function getOpenPRListInfo(RepositoryEntity $repository, LanguageNameEntity $language): array - { - return $this->api->getOpenPRListInfo($repository->getUrl(), $language->getCode()); - } - -} \ No newline at end of file diff --git a/src/Services/Repository/Behavior/PlainBehavior.php b/src/Services/Repository/Behavior/PlainBehavior.php index 6be7bde2..bffeec32 100644 --- a/src/Services/Repository/Behavior/PlainBehavior.php +++ b/src/Services/Repository/Behavior/PlainBehavior.php @@ -38,7 +38,7 @@ public function sendChange(GitRepository $tempGit, TranslationUpdateEntity $upda $this->mailService->sendPatchEmail( $update->getRepository()->getEmail(), - 'Language Update', + $update->getSubject(), $patch, 'mail/languageUpdate.txt.twig', ['update' => $update] diff --git a/src/Services/Repository/Repository.php b/src/Services/Repository/Repository.php index a383854c..8d856a56 100644 --- a/src/Services/Repository/Repository.php +++ b/src/Services/Repository/Repository.php @@ -500,8 +500,9 @@ private function createAndSendPatchWithException(TranslationUpdateEntity $update // add files to local temporary git repository $this->applyChanges($tmpGit, $tmpDir, $update); // commit files to local temporary git repository + $message = $update->getSubject(); $author = $this->prepareAuthor($update); - $tmpGit->commit('translation update', $author); + $tmpGit->commit($message, $author); $this->behavior->sendChange($tmpGit, $update, $this->git); } diff --git a/src/Services/Repository/RepositoryManager.php b/src/Services/Repository/RepositoryManager.php index cd192c68..e4856206 100644 --- a/src/Services/Repository/RepositoryManager.php +++ b/src/Services/Repository/RepositoryManager.php @@ -4,7 +4,6 @@ use App\Services\GitLab\GitLabService; use App\Services\GitLab\GitLabStatusService; -use App\Services\Repository\Behavior\GitLabBehavior; use Doctrine\ORM\EntityManager; use Doctrine\ORM\EntityManagerInterface; use App\Entity\RepositoryEntity; @@ -13,7 +12,7 @@ use App\Services\GitHub\GitHubService; use App\Services\GitHub\GitHubStatusService; use App\Services\Mail\MailService; -use App\Services\Repository\Behavior\GitHubBehavior; +use App\Services\Repository\Behavior\GitHostingProviderBehavior; use App\Services\Repository\Behavior\PlainBehavior; use App\Services\Repository\Behavior\RepositoryBehavior; use Psr\Log\LoggerInterface; @@ -125,13 +124,13 @@ private function getRepositoryBehavior(RepositoryEntity $repository): Repository { $url = $repository->getUrl(); if (preg_match('/^(git:\/\/|https:\/\/|git@)github\.com/i', $url)) { - return new GitHubBehavior($this->gitHubService, $this->gitHubStatus); + return new GitHostingProviderBehavior($this->gitHubService, $this->gitHubStatus); } if (preg_match('/^(git:\/\/|https:\/\/|git@)gitlab\.com/i', $url)) { //build manually as Repository is not yet available.. $repoFolder = $this->dataFolder . '/gitlab_projectids/' . $repository->getType() . '/' . $repository->getName() . '/'; $this->gitLabService->setProjectIdFolder($repoFolder); - return new GitLabBehavior($this->gitLabService, $this->gitLabStatus); + return new GitHostingProviderBehavior($this->gitLabService, $this->gitLabStatus); } return new PlainBehavior($this->mailService); }