Skip to content

Commit

Permalink
Added htmlspecialchars() to commit messages as & might break confluen…
Browse files Browse the repository at this point in the history
…ce pushes
  • Loading branch information
alexander.heidrich committed Feb 21, 2020
1 parent 58e1687 commit ad33d7f
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 37 deletions.
80 changes: 44 additions & 36 deletions ReleaseNotesBundle/Command/ReleaseNotesPublisherCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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 .= '<li>' . $commit . '</li>';
foreach ($fileContents as $commitMessage) {
$content .= '<li>' . htmlspecialchars($commitMessage) . '</li>';
}
$body = '

return '
<ac:structured-macro ac:name="expand" ac:schema-version="1">
<ac:parameter ac:name= "title">Gesamtes Changelog einblenden</ac:parameter>
<ac:rich-text-body>
<ul>' . $content . '</ul>
</ac:rich-text-body>
</ac:structured-macro>';

return $body;
}


Expand All @@ -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;
}

/**
Expand All @@ -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'];
}

/**
Expand Down Expand Up @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "*",
Expand Down

0 comments on commit ad33d7f

Please sign in to comment.