From 46cc572bbd27973e243a1d5640da329983314695 Mon Sep 17 00:00:00 2001 From: Simon Vieille Date: Thu, 7 Jun 2018 14:52:18 +0200 Subject: [PATCH 1/4] Gogs weebhook helper added --- src/Languages/lang.da.php | 3 +++ src/Languages/lang.de.php | 2 ++ src/Languages/lang.el.php | 3 +++ src/Languages/lang.en.php | 3 +++ src/Languages/lang.es.php | 3 +++ src/Languages/lang.fr.php | 3 +++ src/Languages/lang.it.php | 4 ++++ src/Languages/lang.nl.php | 3 +++ src/Languages/lang.pl.php | 3 +++ src/Languages/lang.pt-br.php | 3 +++ src/Languages/lang.ru.php | 3 +++ src/Languages/lang.uk.php | 3 +++ src/Languages/lang.zh.php | 2 ++ src/View/Project/view.phtml | 4 ++++ 14 files changed, 42 insertions(+) diff --git a/src/Languages/lang.da.php b/src/Languages/lang.da.php index b12df021..3f996a52 100644 --- a/src/Languages/lang.da.php +++ b/src/Languages/lang.da.php @@ -138,6 +138,9 @@ and Services under dit GitHub-repository.', 'webhooks_help_gitlab' => 'For at køre dette build automatisk når nye commits bliver pushed kan du tilføje nedenstående URL som en "WebHook URL" i Web Hooks-sektionen i dit GitLab-repository.', + 'webhooks_help_gogs' => 'For at køre dette build automatisk når nye commits bliver pushed kan du tilføje nedenstående URL +som en "WebHook URL" i Web Hooks-sektionen i dit Gogs-repository.', + 'webhooks_help_bitbucket' => 'For at køre dette build automatisk når nye commits bliver pushed skal du tilføje nedenstående URL som "POST" service i diff --git a/src/Languages/lang.de.php b/src/Languages/lang.de.php index 834e385c..338a9aeb 100644 --- a/src/Languages/lang.de.php +++ b/src/Languages/lang.de.php @@ -140,6 +140,8 @@ generiert. Um es zu verwenden, fügen Sie einfach den folgenden Public Key im Ab 'webhooks_help_gitlab' => 'Um für dieses Projekt automatisch einen Build zu starten, wenn neue Commits gepushed werden, fügen Sie die untenstehende URL in der Web Hooks Sektion Ihres GitLab Repositories hinzu.', + 'webhooks_help_gogs' => 'Um für dieses Projekt automatisch einen Build zu starten, wenn neue Commits gepushed werden, fügen Sie die untenstehende URL in der Web Hooks Sektion Ihres Gogs Repositories hinzu.', + 'webhooks_help_bitbucket' => 'Um für dieses Projekt automatisch einen Build zu starten, wenn neue Commits gepushed werden, fügen Sie die untenstehende URL als "POST" Service in der Services-Sektion Ihres Bitbucket Repositories hinzu.', // View Build diff --git a/src/Languages/lang.el.php b/src/Languages/lang.el.php index 211117d5..5c39ea57 100644 --- a/src/Languages/lang.el.php +++ b/src/Languages/lang.el.php @@ -139,6 +139,9 @@ and Services του GitHub αποθετηρίου σας.', 'webhooks_help_gitlab' => 'Για την αυτόματη κατασκευή αυτού του έργου όταν υπάρχουν νέες συνεισφορές, προσθέστε την διεύθυνση URL παρακάτω σαν "WebHook URL" στο τμήμα Web Hooks του GitLab αποθετηρίου σας.', + 'webhooks_help_gogs' => 'Για την αυτόματη κατασκευή αυτού του έργου όταν υπάρχουν νέες συνεισφορές, προσθέστε την διεύθυνση URL παρακάτω +σαν "WebHook URL" στο τμήμα Web Hooks του Gogs αποθετηρίου σας.', + 'webhooks_help_bitbucket' => 'Για την αυτόματη κατασκευή αυτού του έργου όταν υπάρχουν νέες συνεισφορές, προσθέστε τη διεύθυνση URL παρακάτω ως μια υπηρεσία "POST" στο τμήμα Services του Bitbucket αποθετηρίου σας.', diff --git a/src/Languages/lang.en.php b/src/Languages/lang.en.php index 4a948e15..f1be2f24 100644 --- a/src/Languages/lang.en.php +++ b/src/Languages/lang.en.php @@ -165,6 +165,9 @@ PHP Censor', 'webhooks_help_gitlab' => 'To automatically build this project when new commits are pushed, add the URL below as a "WebHook URL" in the Web Hooks section of your GitLab repository.', + 'webhooks_help_gogs' => 'To automatically build this project when new commits are pushed, add the URL below + as a "WebHook URL" in the Web Hooks section of your Gogs repository.', + 'webhooks_help_bitbucket' => 'To automatically build this project when new commits are pushed, add the URL below as a "POST" service in the diff --git a/src/Languages/lang.es.php b/src/Languages/lang.es.php index e1b3537c..12180cf7 100644 --- a/src/Languages/lang.es.php +++ b/src/Languages/lang.es.php @@ -138,6 +138,9 @@ PHP Censor', 'webhooks_help_gitlab' => 'Para compilar automáticamente este proyecto, cada vez que se realiza un commit, agreagar la siguiente URL como una "WebHook URL" en la sección "web hooks" de tu repositorio en GitLab.', + 'webhooks_help_gogs' => 'Para compilar automáticamente este proyecto, cada vez que se realiza un commit, agreagar la siguiente URL + como una "WebHook URL" en la sección "web hooks" de tu repositorio en Gogs.', + 'webhooks_help_bitbucket' => 'Para compilar automáticamente este proyecto, cada vez que se realiza un commit, agreagar la siguiente URL como un servicio "POST" en la sección diff --git a/src/Languages/lang.fr.php b/src/Languages/lang.fr.php index 28121b93..e3525586 100644 --- a/src/Languages/lang.fr.php +++ b/src/Languages/lang.fr.php @@ -167,6 +167,9 @@ PHP Censor', 'webhooks_help_gitlab' => 'Pour générer un build quand de nouveaux commits sont poussés, ajouter l\'url suivante en tant que "WebHook URL" dans la section "Web Hooks" de votre dépôt GitLab.', + 'webhooks_help_gogs' => 'Pour générer un build quand de nouveaux commits sont poussés, ajouter l\'url suivante + en tant que "WebHook URL" dans la section "Web Hooks" de votre dépôt Gogs.', + 'webhooks_help_bitbucket' => 'Pour générer un build quand de nouveaux commits sont poussés, ajouter l\'url suivante en tant que service "POST" dans la section diff --git a/src/Languages/lang.it.php b/src/Languages/lang.it.php index 0a8bab7c..f5f9c61e 100644 --- a/src/Languages/lang.it.php +++ b/src/Languages/lang.it.php @@ -139,6 +139,10 @@ PHP Censor', aggiungi l\'URL seguente come "Webhook URL" nella sezione "WebHook URL" del tuo repository GitLab.', + 'webhooks_help_gogs' => 'Per effettuare la build automatica di questo progetto quando vengono inseriti nuovi commit, + aggiungi l\'URL seguente come "Webhook URL" nella sezione "WebHook URL" del tuo + repository Gogs.', + 'webhooks_help_bitbucket' => 'Per effettuare la build automatica di questo progetto quando vengono inseriti nuovi commit, aggiungi l\'URL seguente come serizio "POST" nella sezione Services del tuo repository su diff --git a/src/Languages/lang.nl.php b/src/Languages/lang.nl.php index 1e4e17a0..69129fcf 100644 --- a/src/Languages/lang.nl.php +++ b/src/Languages/lang.nl.php @@ -139,6 +139,9 @@ and Services sectie van je GitHub repository toegevoegd worden.', 'webhooks_help_gitlab' => 'Voor automatische builds wanneer nieuwe commits worden gepusht, dient onderstaande URL als nieuwe "Webhook URL" in de Web Hooks sectie van je GitLab repository toegevoegd worden.', + 'webhooks_help_gogs' => 'Voor automatische builds wanneer nieuwe commits worden gepusht, dient onderstaande URL +als nieuwe "Webhook URL" in de Web Hooks sectie van je Gogs repository toegevoegd worden.', + 'webhooks_help_bitbucket' => 'Voor automatische builds wanneer nieuwe commits worden gepusht, dient onderstaande URL als "POST" service in de in de diff --git a/src/Languages/lang.pl.php b/src/Languages/lang.pl.php index bbc0c9cc..0e995d36 100644 --- a/src/Languages/lang.pl.php +++ b/src/Languages/lang.pl.php @@ -140,6 +140,9 @@ od wybranego kodu źródłowego platformy hostingowej.', 'webhooks_help_gitlab' => 'Aby automatycznie uruchomić nową budowę po wysłaniu commitów dodaj poniższy adres URL jako "WebHook URL" w sekcji Web Hook Twojego repozytoria GitLab.', + 'webhooks_help_gogs' => 'Aby automatycznie uruchomić nową budowę po wysłaniu commitów dodaj poniższy adres URL + jako "WebHook URL" w sekcji Web Hook Twojego repozytoria Gogs.', + 'webhooks_help_bitbucket' => 'Aby automatycznie uruchomić nową budowę po wysłaniu commitów, dodaj poniższy adres URL jako usługę "POST" w sekcji diff --git a/src/Languages/lang.pt-br.php b/src/Languages/lang.pt-br.php index 8e65b892..1b7fe352 100644 --- a/src/Languages/lang.pt-br.php +++ b/src/Languages/lang.pt-br.php @@ -137,6 +137,9 @@ PHP Censor', 'webhooks_help_gitlab' => 'To automatically build this project when new commits are pushed, add the URL below as a "WebHook URL" in the Web Hooks section of your GitLab repository.', + 'webhooks_help_gogs' => 'To automatically build this project when new commits are pushed, add the URL below + as a "WebHook URL" in the Web Hooks section of your Gogs repository.', + 'webhooks_help_bitbucket' => 'To automatically build this project when new commits are pushed, add the URL below as a "POST" service in the diff --git a/src/Languages/lang.ru.php b/src/Languages/lang.ru.php index f4b07bd3..69e46380 100644 --- a/src/Languages/lang.ru.php +++ b/src/Languages/lang.ru.php @@ -160,6 +160,9 @@ PHP Censor', 'webhooks_help_gitlab' => 'Чтобы Автоматически собирать этот проект при публикации новых коммитов, добавьте URL ниже в качестве "WebHook URL" в разделе "Web Hooks" вашего GitLab репозитория.', + 'webhooks_help_gogs' => 'Чтобы Автоматически собирать этот проект при публикации новых коммитов, добавьте URL ниже в качестве "WebHook URL" + в разделе "Web Hooks" вашего Gogs репозитория.', + 'webhooks_help_bitbucket' => 'Чтобы Автоматически собирать этот проект при публикации новых коммитов, добавьте URL ниже как "POST" сервис в разделе Services вашего Bitbucket репозитория.', diff --git a/src/Languages/lang.uk.php b/src/Languages/lang.uk.php index 5a74eb04..205cac79 100644 --- a/src/Languages/lang.uk.php +++ b/src/Languages/lang.uk.php @@ -139,6 +139,9 @@ PHP Censor', 'webhooks_help_gitlab' => 'Для автоматичної збірки цього проекту, при надходженні нових комітів, додайте наступний URL у якості нового "WebHook URL" у розділі "Web Hooks" вашого GitLab репозиторію.', + 'webhooks_help_gogs' => 'Для автоматичної збірки цього проекту, при надходженні нових комітів, додайте наступний URL +у якості нового "WebHook URL" у розділі "Web Hooks" вашого Gogs репозиторію.', + 'webhooks_help_bitbucket' => 'Для автоматичної збірки цього проекту, при надходженні нових комітів, додайте наступний URL у якості нового "POST" сервісу у розділі Services diff --git a/src/Languages/lang.zh.php b/src/Languages/lang.zh.php index b569e2a2..5c934d4b 100644 --- a/src/Languages/lang.zh.php +++ b/src/Languages/lang.zh.php @@ -136,6 +136,8 @@ PHP Censor', 'webhooks_help_gitlab' => '要想当您的仓库由新的提交推送时自动构建,请在您的GitLab仓库的 "WebHook URL" 添加该URL。', + 'webhooks_help_gogs' => '要想当您的仓库由新的提交推送时自动构建,请在您的Gogs仓库的 "WebHook URL" 添加该URL。', + 'webhooks_help_bitbucket' => '要想当您的仓库由新的提交推送时自动构建,请在您的GitLab仓库的 Services 将该URL添加成 “POST服务”。', diff --git a/src/View/Project/view.phtml b/src/View/Project/view.phtml index e82d3bb1..c1641f58 100644 --- a/src/View/Project/view.phtml +++ b/src/View/Project/view.phtml @@ -193,6 +193,10 @@ use PHPCensor\Model\Project; $url = APP_URL . 'webhook/bitbucket/' . $project->getId(); echo Lang::get('webhooks_help_bitbucket', $project->getReference()); break; + case Project::TYPE_GOGS: + $url = APP_URL . 'webhook/gogs/' . $project->getId(); + echo Lang::get('webhooks_help_gogs', $project->getReference()); + break; } ?>

From 2e77a17bcd2fd69eaf83a020b63528f4b873a50b Mon Sep 17 00:00:00 2001 From: Simon Vieille Date: Thu, 7 Jun 2018 14:56:35 +0200 Subject: [PATCH 2/4] Gogs weebhook helper box --- src/View/Project/view.phtml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/View/Project/view.phtml b/src/View/Project/view.phtml index c1641f58..471202c3 100644 --- a/src/View/Project/view.phtml +++ b/src/View/Project/view.phtml @@ -164,7 +164,8 @@ use PHPCensor\Model\Project; Project::TYPE_GITHUB, Project::TYPE_GITLAB, Project::TYPE_BITBUCKET, - Project::TYPE_BITBUCKET_HG + Project::TYPE_BITBUCKET_HG, + Project::TYPE_GOGS, ])): ?>
From 0205400c77e8df6abbf47e681558fe0612add571 Mon Sep 17 00:00:00 2001 From: Simon Vieille Date: Thu, 7 Jun 2018 15:24:38 +0200 Subject: [PATCH 3/4] Gogs: remove '.git' from links to commits and files --- src/Model/Build/GogsBuild.php | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/Model/Build/GogsBuild.php b/src/Model/Build/GogsBuild.php index 9f5d95e6..236ce423 100644 --- a/src/Model/Build/GogsBuild.php +++ b/src/Model/Build/GogsBuild.php @@ -7,12 +7,20 @@ namespace PHPCensor\Model\Build; */ class GogsBuild extends GitBuild { + /** + * Get a cleaned reference to generate link + */ + protected function getCleanedReferenceForLink() + { + return preg_replace('/\.git$/i', '', $this->getProject()->getReference()); + } + /** * Get link to commit from Gogs repository */ public function getCommitLink() { - return $this->getProject()->getReference() . '/commit/' . $this->getCommitId(); + return $this->getCleanedReferenceForLink() . '/commit/' . $this->getCommitId(); } /** @@ -20,8 +28,9 @@ class GogsBuild extends GitBuild */ public function getBranchLink() { - return $this->getProject()->getReference() . '/src/' . $this->getBranch(); + return $this->getCleanedReferenceForLink() . '/src/' . $this->getBranch(); } + /** * Get link to specific file (and line) in a the repo's branch */ @@ -29,7 +38,7 @@ class GogsBuild extends GitBuild { return sprintf( '%s/src/%s/{FILE}#L{LINE}', - $this->getProject()->getReference(), + $this->getCleanedReferenceForLink(), $this->getCommitId() ); } From 9bc2f69712bbd4d74cab9c004abe8bfa3c6cc86b Mon Sep 17 00:00:00 2001 From: Simon Vieille Date: Thu, 7 Jun 2018 16:45:39 +0200 Subject: [PATCH 4/4] GogsBuild: unit tests for the links generations --- tests/src/Model/BuildTest.php | 37 +++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/tests/src/Model/BuildTest.php b/tests/src/Model/BuildTest.php index 56360d81..2bb039cf 100644 --- a/tests/src/Model/BuildTest.php +++ b/tests/src/Model/BuildTest.php @@ -4,6 +4,8 @@ namespace Tests\PHPCensor\Model; use PHPCensor\Exception\InvalidArgumentException; use PHPCensor\Model\Build; +use PHPCensor\Model\Project; +use PHPCensor\Model\Build\GogsBuild; /** * Unit tests for the Build model class. @@ -138,4 +140,39 @@ class BuildTest extends \PHPUnit\Framework\TestCase self::assertEquals('Item One', $build->getExtra('item1')); self::assertEquals('Item Three', $build->getExtra('item3')); } + + public function testGogsBuildLinks() + { + $project = new Project(); + $project->setType(Project::TYPE_GOGS); + $project->setReference('https://gogs.repository/the-vendor/the-project.git'); + + $stub = $this->getMockBuilder(GogsBuild::class) + ->setMethods(['getProject', 'getCommitId', 'getBranch']) + ->getMock(); + + $stub->method('getProject') + ->will($this->returnValue($project)); + + $stub->method('getCommitId') + ->will($this->returnValue('abcdef')); + + $stub->method('getBranch') + ->will($this->returnValue('master')); + + $this->assertEquals( + 'https://gogs.repository/the-vendor/the-project/commit/abcdef', + $stub->getCommitLink() + ); + + $this->assertEquals( + 'https://gogs.repository/the-vendor/the-project/src/master', + $stub->getBranchLink() + ); + + $this->assertEquals( + 'https://gogs.repository/the-vendor/the-project/src/abcdef/{FILE}#L{LINE}', + $stub->getFileLinkTemplate() + ); + } }