Skip to content

Instantly share code, notes, and snippets.

@nidup
Created March 11, 2014 13:18
Show Gist options
  • Save nidup/9485426 to your computer and use it in GitHub Desktop.
Save nidup/9485426 to your computer and use it in GitHub Desktop.
Download Crowdin translations + create PR
<?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 git@github.com:akeneo/pim-community-dev.git %s/update && ' .
'cd %s/update && ' .
'git remote add nono git@github.com: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