Skip to content

Instantly share code, notes, and snippets.

@Tuurlijk

Tuurlijk/importer

Created Nov 3, 2019
Embed
What would you like to do?
<?php
$basePath = '/home/Blah/tmp/TYPO3.CMS/typo3/sysext/core/Documentation/Changelog';
$dir = new DirectoryIterator($basePath);
foreach ($dir as $fileinfo) {
if (!$fileinfo->isDot()) {
$filename = $fileinfo->getFilename();
if (strpos($filename, '.htaccess') === 0 || strpos($filename, 'Howto') === 0) {
continue;
}
echo PHP_EOL . PHP_EOL . 'Minor : ' . $filename . PHP_EOL;
generate($filename, $basePath);
}
}
function generate($minor, $basePath)
{
$publicUrlBase = 'https://docs.typo3.org/c/typo3/cms-core/master/en-us/Changelog/';
$dir = new DirectoryIterator($basePath . $minor);
$minorParts = explode('.', $minor);
$major = array_shift($minorParts);
foreach ($dir as $fileinfo) {
if (!$fileinfo->isDot()) {
$filename = $fileinfo->getFilename();
$filename = substr($filename, 0, -4);
if (strpos($filename, 'Feature') === 0 || strpos($filename, 'Index') === 0) {
continue;
}
$nameParts = explode('-', $filename);
$type = array_shift($nameParts);
$issue = array_shift($nameParts);
echo PHP_EOL;
$contentArray = file($basePath . $minor . '/' . $fileinfo->getFilename());
$title = getTitle($contentArray);
$publicUrl = $publicUrlBase . $minor . '/' . $filename . '.html';
$labels = implode(',', [$major, $minor, $type]);
$message = $title . PHP_EOL. PHP_EOL . $publicUrl . PHP_EOL . implode(PHP_EOL, $contentArray);
echo 'Creating Issue : ' . $issue . PHP_EOL;
echo 'Title : ' . $title . PHP_EOL;
echo 'Labels : ' . $labels . PHP_EOL;
echo 'Public : ' . $publicUrl . PHP_EOL;
$tmpFile = tmpfile();
fwrite($tmpFile, $message);
$tmpFilePath = stream_get_meta_data($tmpFile)['uri'];
// echo 'hub issue create -l ' . $labels . ' -F ' . $tmpFilePath . PHP_EOL;
exec('hub issue create -l ' . $labels . ' -F ' . $tmpFilePath );
fclose($tmpFile);
}
}
}
function getTitle($contentArray) {
$nextLineIsTitle = false;
foreach ($contentArray as $line) {
if ($nextLineIsTitle) {
return trim($line);
}
if (strpos($line, '===============') === 0) {
$nextLineIsTitle = true;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.