From ad33d7fef4bd11c4598dc57d9f415148a3c0905e Mon Sep 17 00:00:00 2001 From: "alexander.heidrich" Date: Fri, 21 Feb 2020 08:22:58 +0100 Subject: [PATCH] Added htmlspecialchars() to commit messages as & might break confluence pushes --- .../Command/ReleaseNotesPublisherCommand.php | 80 ++++++++++--------- composer.json | 2 +- 2 files changed, 45 insertions(+), 37 deletions(-) diff --git a/ReleaseNotesBundle/Command/ReleaseNotesPublisherCommand.php b/ReleaseNotesBundle/Command/ReleaseNotesPublisherCommand.php index f960e94..932d108 100755 --- a/ReleaseNotesBundle/Command/ReleaseNotesPublisherCommand.php +++ b/ReleaseNotesBundle/Command/ReleaseNotesPublisherCommand.php @@ -45,17 +45,19 @@ public function __construct( string $pageId ) { parent::__construct(); - $this->client = new HttpClient([ - 'headers' => [ - 'Content-Type' => 'application/json', - ], - 'auth' => [ - $confluenceUser, - $confluencePassword, - ], - 'base_uri' => rtrim($confluenceUrl, '/') . '/rest/api/content/', - 'timeout' => 2, - ]); + $this->client = new HttpClient( + [ + 'headers' => [ + 'Content-Type' => 'application/json', + ], + 'auth' => [ + $confluenceUser, + $confluencePassword, + ], + 'base_uri' => rtrim($confluenceUrl, '/') . '/rest/api/content/', + 'timeout' => 2, + ] + ); $this->pageId = $pageId; } @@ -83,52 +85,54 @@ public function execute(InputInterface $input, OutputInterface $output) $this->updateDocumentContent($appVersion, $tickets, $completeChangelog); $this->preparePayloadAndSendToConfluence(); } else { - echo 'No new App_Version'; + echo 'The app version is already part of the changelog.'; } } /** - * @param $fileName - * * @return array * @throws Exception */ private function extractTickets(): array { - $onlyWebTickets = explode(PHP_EOL, - shell_exec('/bin/bash ' . dirname(__DIR__) . '/' . basename(__DIR__) . '/GitChangelog.sh | grep -Eo \'([A-Z]{3,}-)([0-9]+)\' | uniq')); - $onlyWebTickets = array_unique(array_filter($onlyWebTickets, function ($value) { - return stripos($value, 'web-0000') === false && !empty($value); - }) + $bashPath = dirname(__DIR__) . '/' . basename(__DIR__); + $onlyWebTickets = explode( + PHP_EOL, + shell_exec('/bin/bash ' . $bashPath . '/GitChangelog.sh | grep -Eo \'([A-Z]{3,}-)([0-9]+)\' | uniq') + ); + $onlyWebTickets = array_unique( + array_filter( + $onlyWebTickets, + function ($value) { + return stripos($value, 'web-0000') === false && !empty($value); + } + ) ); return $onlyWebTickets; } /** - * @param $fileName - * * @return string * @throws Exception */ private function extractAndPrepareWholeChangelog(): string { $content = ''; - $fileContents = explode(PHP_EOL, - shell_exec('/bin/bash ' . dirname(__DIR__) . '/' . basename(__DIR__) . '/GitChangelog.sh ')); + $bashPath = dirname(__DIR__) . '/' . basename(__DIR__); + $fileContents = explode(PHP_EOL, shell_exec('/bin/bash ' . $bashPath . '/GitChangelog.sh ')); - foreach ($fileContents as $commit) { - $content .= '
  • ' . $commit . '
  • '; + foreach ($fileContents as $commitMessage) { + $content .= '
  • ' . htmlspecialchars($commitMessage) . '
  • '; } - $body = ' + + return ' Gesamtes Changelog einblenden
      ' . $content . '
    '; - - return $body; } @@ -145,9 +149,9 @@ private function getNextDocumentVersion(): int throw new Exception('Could not get response'); } - $content = json_decode((string) $response->getBody(), true); + $content = json_decode((string)$response->getBody(), true); - return (int) $content['version']['number'] + 1; + return (int)$content['version']['number'] + 1; } /** @@ -162,10 +166,10 @@ private function retrieveDocumentInformation() throw new Exception('Could not get response'); } - $content = json_decode((string) $response->getBody(), true); + $content = json_decode((string)$response->getBody(), true); - $this->pageTitle = (string) $content['title']; - $this->body = (string) $content['body']['storage']['value']; + $this->pageTitle = (string)$content['title']; + $this->body = (string)$content['body']['storage']['value']; } /** @@ -212,9 +216,13 @@ private function preparePayloadAndSendToConfluence() ], ]; - $response = $this->client->request('PUT', $this->pageId, [ - 'body' => json_encode($payload), - ]); + $response = $this->client->request( + 'PUT', + $this->pageId, + [ + 'body' => json_encode($payload), + ] + ); if ($response->getStatusCode() !== self::HTTP_OK) { throw new Exception('Could not send new version'); diff --git a/composer.json b/composer.json index b0240cb..718b8a2 100644 --- a/composer.json +++ b/composer.json @@ -3,7 +3,7 @@ "description": "Functionality to send git log messages to confluence", "keywords": ["log","logging","git log"], "require": { - "php": ">=7.0.0", + "php": ">=7.3.0", "ext-json": "*", "phpunit/phpunit": "^8.5", "symfony/console": "*",