Created
March 11, 2014 13:18
-
-
Save nidup/9485426 to your computer and use it in GitHub Desktop.
Download Crowdin translations + create PR
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$app | |
->get('/crowdin/pull', function (Request $request) use ($app) { | |
$responses = array(); | |
$config = $app['config']['crowdin']['download']; | |
$app['crowdin']->api('export')->execute(); | |
if (!is_dir($config['base_dir'])) { | |
mkdir($config['base_dir']); | |
} | |
$download = $app['crowdin']->api('download')->setCopyDestination($config['base_dir']); | |
foreach ($config['packages'] as $package) { | |
$download->setPackage(sprintf('%s.zip', $package))->execute(); | |
} | |
if (is_dir($config['base_dir'] . '/update/.git')) { | |
logged_system(sprintf( | |
'cd %s/update/ && git checkout master && git pull origin master', | |
$config['base_dir'] | |
), $app['monolog']); | |
} else { | |
logged_system(sprintf( | |
'git clone [email protected]:akeneo/pim-community-dev.git %s/update && ' . | |
'cd %s/update && ' . | |
'git remote add nono [email protected]:nono-akeneo/pim-community-dev.git', | |
$config['base_dir'], | |
$config['base_dir'] | |
), $app['monolog']); | |
} | |
$zip = new \ZipArchive(); | |
foreach ($config['packages'] as $package) { | |
$res = $zip->open(sprintf('%s/%s.zip', $config['base_dir'], $package)); | |
$zip->extractTo($config['base_dir']); | |
} | |
$zip->close(); | |
logged_system(sprintf( | |
'cp -rf %s/1.0.x/* %s/update/app/Resources/', | |
$config['base_dir'], | |
$config['base_dir'] | |
), $app['monolog']); | |
$branch = (new DateTime())->format('Y-m-d-H-i'); | |
logged_system( | |
sprintf( | |
'cd %s/update/ && ' . | |
'git checkout -b crowdin/%s && ' . | |
'git add .', | |
$config['base_dir'], | |
$branch | |
), | |
$app['monolog'] | |
); | |
logged_system( | |
sprintf( | |
'export HOME=/home/githook && ' . | |
'cd %s/update git && git commit -m "[CrowdIn] Updated translations" && git push nono crowdin/%s', | |
$config['base_dir'], | |
$branch | |
), | |
$app['monolog'] | |
); | |
$app['github']->api('pr')->create('akeneo', 'pim-community-dev', array( | |
'head' => sprintf('nono-akeneo:crowdin/%s', $branch), | |
'base' => 'master', | |
'title' => 'Update translations from CrowdIn', | |
'body' => 'Updated on ' . $branch, | |
)); | |
return $app->json(array( | |
'message' => 'Files have been updated.', | |
)); | |
}); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment